5 * @file util/extract.php
7 * Extracts translation strings from the Friendica project's files to be exported
8 * to Transifex for translation.
10 * Outputs a PHP file with language strings used by Friendica
13 $s = '<?php' . PHP_EOL;
15 function string_plural_select($n){
23 $files = ['index.php', 'boot.php'];
32 foreach ($files as $file) {
33 $str = file_get_contents($file);
35 $pat = '|L10n::t\(([^\)]*+)[\)]|';
36 $patt = '|L10n::tt\(([^\)]*+)[\)]|';
38 preg_match_all($pat, $str, $matches);
39 preg_match_all($patt, $str, $matchestt);
41 if (count($matches) || count($matchestt)) {
42 $s .= '// ' . $file . PHP_EOL;
45 if (count($matches)) {
46 foreach ($matches[1] as $long_match) {
47 $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);
48 $match = $match_arr[0];
49 if (!in_array($match, $arr)) {
50 if (substr($match, 0, 1) == '$') {
56 $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";
60 if (count($matchestt)) {
61 foreach ($matchestt[1] as $match) {
62 $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);
63 if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {
64 if (substr($matchtkns[1], 0, 1) == '$') {
68 $arr[] = $matchtkns[0];
70 $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";
71 $s .= "\t0 => " . $matchtkns[0] . ",\n";
72 $s .= "\t1 => " . $matchtkns[1] . ",\n";
79 $s .= '// Timezones' . PHP_EOL;
81 $zones = timezone_identifiers_list();
82 foreach ($zones as $zone) {
83 $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
88 function glob_recursive($path) {
89 $dir_iterator = new RecursiveDirectoryIterator($path);
90 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
93 foreach ($iterator as $file) {
94 if ($file->getBasename() != '.' && $file->getBasename() != '..') {
95 $return[] = $file->getPathname();