2018-01-24 16:53:57 -05:00
|
|
|
#!/usr/bin/env php
|
2010-09-29 21:11:23 -04:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
/**
|
|
|
|
* @file util/extract.php
|
|
|
|
*
|
|
|
|
* Extracts translation strings from the Friendica project's files to be exported
|
|
|
|
* to Transifex for translation.
|
|
|
|
*
|
|
|
|
* Outputs a PHP file with language strings used by Friendica
|
|
|
|
*/
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
$s = '<?php' . PHP_EOL;
|
|
|
|
$s .= '
|
|
|
|
function string_plural_select($n){
|
|
|
|
return ($n != 1);
|
|
|
|
}
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
';
|
|
|
|
|
|
|
|
$arr = [];
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
$files = ['index.php', 'boot.php'];
|
|
|
|
$files = array_merge(
|
|
|
|
$files,
|
|
|
|
glob('mod/*'),
|
|
|
|
glob('include/*'),
|
|
|
|
glob('addon/*/*'),
|
|
|
|
glob_recursive('src')
|
|
|
|
);
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
foreach ($files as $file) {
|
|
|
|
$str = file_get_contents($file);
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
$pat = '|L10n::t\(([^\)]*+)[\)]|';
|
|
|
|
$patt = '|L10n::tt\(([^\)]*+)[\)]|';
|
2018-01-15 08:05:12 -05:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
preg_match_all($pat, $str, $matches);
|
|
|
|
preg_match_all($patt, $str, $matchestt);
|
2011-03-13 08:51:59 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
if (count($matches) || count($matchestt)) {
|
|
|
|
$s .= '// ' . $file . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($matches)) {
|
|
|
|
foreach ($matches[1] as $long_match) {
|
|
|
|
$match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);
|
|
|
|
$match = $match_arr[0];
|
|
|
|
if (!in_array($match, $arr)) {
|
|
|
|
if (substr($match, 0, 1) == '$') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr[] = $match;
|
|
|
|
|
|
|
|
$s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";
|
2011-03-13 08:51:59 -04:00
|
|
|
}
|
|
|
|
}
|
2018-01-24 16:53:57 -05:00
|
|
|
}
|
|
|
|
if (count($matchestt)) {
|
|
|
|
foreach ($matchestt[1] as $match) {
|
|
|
|
$matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);
|
|
|
|
if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {
|
|
|
|
if (substr($matchtkns[1], 0, 1) == '$') {
|
|
|
|
continue;
|
2011-03-13 08:51:59 -04:00
|
|
|
}
|
2018-01-24 16:53:57 -05:00
|
|
|
|
|
|
|
$arr[] = $matchtkns[0];
|
|
|
|
|
|
|
|
$s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";
|
|
|
|
$s .= "\t0 => " . $matchtkns[0] . ",\n";
|
|
|
|
$s .= "\t1 => " . $matchtkns[1] . ",\n";
|
|
|
|
$s .= ");\n";
|
2011-03-13 08:51:59 -04:00
|
|
|
}
|
2010-09-29 21:11:23 -04:00
|
|
|
}
|
|
|
|
}
|
2018-01-24 16:53:57 -05:00
|
|
|
}
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
$s .= '// Timezones' . PHP_EOL;
|
|
|
|
|
|
|
|
$zones = timezone_identifiers_list();
|
|
|
|
foreach ($zones as $zone) {
|
|
|
|
$s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
|
2011-03-13 08:51:59 -04:00
|
|
|
}
|
2010-09-29 21:11:23 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
echo $s;
|
|
|
|
|
|
|
|
function glob_recursive($path) {
|
|
|
|
$dir_iterator = new RecursiveDirectoryIterator($path);
|
|
|
|
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
|
2011-03-13 08:51:59 -04:00
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
$return = [];
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
if ($file->getBasename() != '.' && $file->getBasename() != '..') {
|
|
|
|
$return[] = $file->getPathname();
|
2011-03-13 08:51:59 -04:00
|
|
|
}
|
2010-09-29 21:11:23 -04:00
|
|
|
}
|
|
|
|
|
2018-01-24 16:53:57 -05:00
|
|
|
return $return;
|
|
|
|
}
|