3 namespace Friendica\Console;
6 * Extracts translation strings from the Friendica project's files to be exported
7 * to Transifex for translation.
9 * Outputs a PHP file with language strings used by Friendica
11 * @author Hypolite Petovan <hypolite@mrpetovan.com>
13 class Extract extends \Asika\SimpleConsole\Console
15 protected $helpOptions = ['h', 'help', '?'];
17 protected function getHelp()
20 console extract - Generate translation string file for the Friendica project (deprecated)
22 bin/console extract [-h|--help|-?] [-v]
25 This script was used to generate the translation string file to be exported to Transifex,
26 please use bin/run_xgettext.sh instead
29 -h|--help|-? Show help information
30 -v Show more debug information.
35 protected function doExecute()
37 if ($this->getOption('v')) {
38 $this->out('Class: ' . __CLASS__);
39 $this->out('Arguments: ' . var_export($this->args, true));
40 $this->out('Options: ' . var_export($this->options, true));
43 if (count($this->args) > 0) {
44 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
47 $s = '<?php' . PHP_EOL;
49 function string_plural_select($n){
58 ['index.php', 'boot.php'],
62 $this->globRecursive('src')
65 foreach ($files as $file) {
66 $str = file_get_contents($file);
68 $pat = '|L10n::t\(([^\)]*+)[\)]|';
69 $patt = '|L10n::tt\(([^\)]*+)[\)]|';
74 preg_match_all($pat, $str, $matches);
75 preg_match_all($patt, $str, $matchestt);
77 if (count($matches) || count($matchestt)) {
78 $s .= '// ' . $file . PHP_EOL;
81 if (!empty($matches[1])) {
82 foreach ($matches[1] as $long_match) {
83 $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);
84 $match = $match_arr[0];
85 if (!in_array($match, $arr)) {
86 if (substr($match, 0, 1) == '$') {
92 $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";
96 if (!empty($matchestt[1])) {
97 foreach ($matchestt[1] as $match) {
98 $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);
99 if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {
100 if (substr($matchtkns[1], 0, 1) == '$') {
104 $arr[] = $matchtkns[0];
106 $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";
107 $s .= "\t0 => " . $matchtkns[0] . ",\n";
108 $s .= "\t1 => " . $matchtkns[1] . ",\n";
115 $s .= '// Timezones' . PHP_EOL;
117 $zones = timezone_identifiers_list();
118 foreach ($zones as $zone) {
119 $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
127 private function globRecursive($path) {
128 $dir_iterator = new \RecursiveDirectoryIterator($path);
129 $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
132 foreach ($iterator as $file) {
133 if ($file->getBasename() != '.' && $file->getBasename() != '..') {
134 $return[] = $file->getPathname();