forked from wordpress-mobile/WordPress-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-translation.php
30 lines (27 loc) · 935 Bytes
/
fix-translation.php
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
<?php
if ( count( $argv ) < 2 ) {
die("Usage: php fix-translation.php Localizable.strings\n");
}
array_shift( $argv );
foreach ( $argv as $file ) {
$f = fopen( $file, 'r+' );
$out = '';
while ( $line = fgets( $f ) ) {
$utf8Line = mb_convert_encoding( $line, 'UTF-8', 'UTF-16BE' );
if ( preg_match( '/^"(.*)" = "";$/', $utf8Line, $matches ) ) {
$fixedLine = preg_replace( '/^"(.*)" = "";$/', '"$1" = "$1";', $utf8Line );
$fixedLine = mb_convert_encoding( $fixedLine, 'UTF-16BE' );
$out .= $fixedLine;
} else if ( preg_match('/^(.* = ".*)(?<!\\\\)\"(.*)(?<!\\\\)\"(.*\";)$/uim', $utf8Line, $matches ) ) {
$fixedLine = preg_replace('/^(.* = ".*)(?<!\\\\)\"(.*)(?<!\\\\)\"(.*\";)$/uim', '$1\\"$2\\"$3', $utf8Line);
$fixedLine = mb_convert_encoding( $fixedLine, 'UTF-16BE', 'UTF-8' );
$out .= $fixedLine;
} else {
$out .= $line;
}
}
fseek( $f, 0, SEEK_SET );
fwrite( $f, $out );
fclose( $f );
}
?>