summaryrefslogtreecommitdiff
path: root/locale
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2012-01-31 03:30:29 +0100
committerMichael Tänzer <neo@nhng.de>2012-01-31 03:30:29 +0100
commitd30dd44c1a5eeac330a4281e58db9a0873b32271 (patch)
treee76c1bb4f0b8d64fa1d057ec6dfd7e4edc8f60a6 /locale
parent8a7611eb5e18a678f81721d6602b668c2e7bea52 (diff)
downloadcacert-devel-d30dd44c1a5eeac330a4281e58db9a0873b32271.tar.gz
cacert-devel-d30dd44c1a5eeac330a4281e58db9a0873b32271.tar.xz
cacert-devel-d30dd44c1a5eeac330a4281e58db9a0873b32271.zip
bug 1011: Escape all special characters, not only non-ASCII ones while
keeping the PO file intact Signed-off-by: Michael Tänzer <neo@nhng.de>
Diffstat (limited to 'locale')
-rw-r--r--locale/Makefile3
-rwxr-xr-xlocale/escape_special_chars.php65
2 files changed, 66 insertions, 2 deletions
diff --git a/locale/Makefile b/locale/Makefile
index b703fb2..1517066 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -112,8 +112,7 @@ $(LANGS:%=$(MO_FILE_TEMPLATE)): $(MO_FILE_TEMPLATE): $(PO_FILE_TEMPLATE)
$(LANGS:%=$(PO_FILE_TEMPLATE)):
mkdir -p $(@D)
wget --output-document - '$(@:$(PO_FILE_TEMPLATE)=$(PO_URL_TEMPLATE))' | \
- # convert UTF-8 characters to HTML entities \
- php -r 'while (!feof(STDIN)) echo mb_convert_encoding(fgets(STDIN), "HTML-ENTITIES", "UTF-8");' \
+ php -f escape_special_chars.php \
> $@
diff --git a/locale/escape_special_chars.php b/locale/escape_special_chars.php
new file mode 100755
index 0000000..4ec0d9a
--- /dev/null
+++ b/locale/escape_special_chars.php
@@ -0,0 +1,65 @@
+#!/usr/bin/php -q
+<?php
+/*
+LibreSSL - CAcert web application
+Copyright (C) 2004-2012 CAcert Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; version 2 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/* Convert special characters in UTF-8 encoded PO files to HTML entities */
+
+
+function is_msgstr($line) {
+ return substr_compare($line, 'msgstr', 0, strlen('msgstr')) === 0;
+}
+
+function is_msgid($line) {
+ return substr_compare($line, 'msgid', 0, strlen('msgid')) === 0;
+}
+
+// Skip the metadata (first msgid/msgstr pair)
+while (!feof(STDIN)) {
+ $line = fgets(STDIN);
+ if ($line === false) {
+ exit(0); //EOF after newline mostly
+ }
+
+ echo $line;
+
+ if (is_msgstr($line)) {
+ break;
+ }
+}
+
+// determines if the current line belongs to a msgid or a msgstr
+$msgstr = false;
+
+while (!feof(STDIN)) {
+ $line = fgets(STDIN);
+ if ($line === false) {
+ exit(0); //EOF after newline mostly
+ }
+
+ if (is_msgstr($line)) {
+ $msgstr = true;
+ } elseif (is_msgid($line)) {
+ $msgstr = false;
+ }
+
+ if ($msgstr) {
+ $line = htmlentities($line, ENT_NOQUOTES, "UTF-8");
+ }
+ echo $line;
+}