summaryrefslogtreecommitdiff
path: root/locale/escape_special_chars.php
blob: 4ec0d9ae1aeabd529a54d2bcb7c7c18df28a75e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}