Skip to content

Commit fb3805f

Browse files
committed
getopts
1 parent 0a57a0a commit fb3805f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

i18n_convert.php renamed to i18n_compile.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
// Load the libraries
99
require 'vendor/autoload.php';
1010

11-
$files = glob('i18n/*.po');
11+
$options = getopt('hp:');
12+
if (isset($options['h'])) {
13+
echo "Usage: php i18n_compile.php [-d default]\n";
14+
exit(0);
15+
}
16+
if (isset($options['d'])) {
17+
$domain = $options['d'];
18+
} else {
19+
$domain = 'default';
20+
}
21+
22+
$files = glob('i18n/' . $domain . '_*.po');
1223
foreach ($files as $file) {
1324
$read = fopen($file, "r");
1425
if (!$read) {

i18n_extract.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function leaveNode(Node $node)
5454
if ($node->args[0] instanceof PhpParser\Node\Arg) {
5555
if ($node->args[0]->value instanceof PhpParser\Node\Scalar\String_) {
5656
$string = $node->args[0]->value->value;
57-
$string = preg_replace("/\s+/", " ", $string);
5857
if (!isset($this->strings[$string])) {
5958
$this->strings[$string] = [];
6059
}
@@ -71,7 +70,7 @@ public function getStrings(): array
7170
}
7271
}
7372

74-
function str_split_word_aware(string $string, int $maxLengthOfLine): array
73+
function wordAwareStringSplit(string $string, int $maxLengthOfLine): array
7574
{
7675
if (strlen($string) < $maxLengthOfLine - 6) {
7776
return [$string];
@@ -148,7 +147,11 @@ function str_split_word_aware(string $string, int $maxLengthOfLine): array
148147
foreach ($locations as $location) {
149148
$body .= '#: ' . $location . "\n";
150149
}
151-
$body .= 'msgid "' . $string . '"' . "\n";
150+
$msgid = wordAwareStringSplit($string, 80);
151+
$body .= 'msgid ';
152+
foreach ($msgid as $s) {
153+
$body .= json_encode($s, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n";
154+
}
152155
$body .= 'msgstr ""' . "\n";
153156
}
154157

0 commit comments

Comments
 (0)