-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Extracts translation strings from the Friendica project's files to be exported\r
- * to Transifex for translation.\r
- *\r
- * Outputs a PHP file with language strings used by Friendica\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Extract extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console extract - Generate translation string file for the Friendica project (deprecated)\r
-Usage\r
- bin/console extract [-h|--help|-?] [-v]\r
-\r
-Description\r
- This script was used to generate the translation string file to be exported to Transifex,\r
- please use bin/run_xgettext.sh instead\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) > 0) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $s = '<?php' . PHP_EOL;\r
- $s .= '\r
- function string_plural_select($n){\r
- return ($n != 1);\r
- }\r
-\r
- ';\r
-\r
- $arr = [];\r
-\r
- $files = array_merge(\r
- ['index.php', 'boot.php'],\r
- glob('mod/*'),\r
- glob('include/*'),\r
- glob('addon/*/*'),\r
- $this->globRecursive('src')\r
- );\r
-\r
- foreach ($files as $file) {\r
- $str = file_get_contents($file);\r
-\r
- $pat = '|L10n::t\(([^\)]*+)[\)]|';\r
- $patt = '|L10n::tt\(([^\)]*+)[\)]|';\r
-\r
- $matches = [];\r
- $matchestt = [];\r
-\r
- preg_match_all($pat, $str, $matches);\r
- preg_match_all($patt, $str, $matchestt);\r
-\r
- if (count($matches) || count($matchestt)) {\r
- $s .= '// ' . $file . PHP_EOL;\r
- }\r
-\r
- if (!empty($matches[1])) {\r
- foreach ($matches[1] as $long_match) {\r
- $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);\r
- $match = $match_arr[0];\r
- if (!in_array($match, $arr)) {\r
- if (substr($match, 0, 1) == '$') {\r
- continue;\r
- }\r
-\r
- $arr[] = $match;\r
-\r
- $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";\r
- }\r
- }\r
- }\r
- if (!empty($matchestt[1])) {\r
- foreach ($matchestt[1] as $match) {\r
- $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);\r
- if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {\r
- if (substr($matchtkns[1], 0, 1) == '$') {\r
- continue;\r
- }\r
-\r
- $arr[] = $matchtkns[0];\r
-\r
- $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";\r
- $s .= "\t0 => " . $matchtkns[0] . ",\n";\r
- $s .= "\t1 => " . $matchtkns[1] . ",\n";\r
- $s .= ");\n";\r
- }\r
- }\r
- }\r
- }\r
-\r
- $s .= '// Timezones' . PHP_EOL;\r
-\r
- $zones = timezone_identifiers_list();\r
- foreach ($zones as $zone) {\r
- $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";\r
- }\r
-\r
- $this->out($s);\r
-\r
- return 0;\r
- }\r
-\r
- private function globRecursive($path) {\r
- $dir_iterator = new \RecursiveDirectoryIterator($path);\r
- $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);\r
-\r
- $return = [];\r
- foreach ($iterator as $file) {\r
- if ($file->getBasename() != '.' && $file->getBasename() != '..') {\r
- $return[] = $file->getPathname();\r
- }\r
- }\r
-\r
- return $return;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * 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
+ *
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+class Extract extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console extract - Generate translation string file for the Friendica project (deprecated)
+Usage
+ bin/console extract [-h|--help|-?] [-v]
+
+Description
+ This script was used to generate the translation string file to be exported to Transifex,
+ please use bin/run_xgettext.sh instead
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) > 0) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $s = '<?php' . PHP_EOL;
+ $s .= '
+ function string_plural_select($n){
+ return ($n != 1);
+ }
+
+ ';
+
+ $arr = [];
+
+ $files = array_merge(
+ ['index.php', 'boot.php'],
+ glob('mod/*'),
+ glob('include/*'),
+ glob('addon/*/*'),
+ $this->globRecursive('src')
+ );
+
+ foreach ($files as $file) {
+ $str = file_get_contents($file);
+
+ $pat = '|L10n::t\(([^\)]*+)[\)]|';
+ $patt = '|L10n::tt\(([^\)]*+)[\)]|';
+
+ $matches = [];
+ $matchestt = [];
+
+ preg_match_all($pat, $str, $matches);
+ preg_match_all($patt, $str, $matchestt);
+
+ if (count($matches) || count($matchestt)) {
+ $s .= '// ' . $file . PHP_EOL;
+ }
+
+ if (!empty($matches[1])) {
+ 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";
+ }
+ }
+ }
+ if (!empty($matchestt[1])) {
+ 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;
+ }
+
+ $arr[] = $matchtkns[0];
+
+ $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";
+ $s .= "\t0 => " . $matchtkns[0] . ",\n";
+ $s .= "\t1 => " . $matchtkns[1] . ",\n";
+ $s .= ");\n";
+ }
+ }
+ }
+ }
+
+ $s .= '// Timezones' . PHP_EOL;
+
+ $zones = timezone_identifiers_list();
+ foreach ($zones as $zone) {
+ $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
+ }
+
+ $this->out($s);
+
+ return 0;
+ }
+
+ private function globRecursive($path) {
+ $dir_iterator = new \RecursiveDirectoryIterator($path);
+ $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
+
+ $return = [];
+ foreach ($iterator as $file) {
+ if ($file->getBasename() != '.' && $file->getBasename() != '..') {
+ $return[] = $file->getPathname();
+ }
+ }
+
+ return $return;
+ }
+}