File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 88// Load the libraries
99require '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 ' );
1223foreach ($ files as $ file ) {
1324 $ read = fopen ($ file , "r " );
1425 if (!$ read ) {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments