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