diff --git a/app/Console/Commands/MobileLocalization.php b/app/Console/Commands/MobileLocalization.php new file mode 100644 index 000000000000..a738b453567a --- /dev/null +++ b/app/Console/Commands/MobileLocalization.php @@ -0,0 +1,116 @@ +option('type')); + + switch ($type) { + case 'laravel': + $this->laravelResources(); + break; + default: + $this->flutterResources(); + break; + } + } + + private function laravelResources() + { + $resources = $this->getResources(); + + foreach ($resources as $key => $val) { + $transKey = "texts.{$key}"; + if (trans($transKey) == $transKey) { + echo "'$key' => '$val',\n"; + } + } + } + + private function flutterResources() + { + $languages = cache('languages'); + $resources = $this->getResources(); + + foreach ($languages as $language) { + if ($language->locale == 'en') { + continue; + } + + echo "'{$language->locale}': {\n"; + + foreach ($resources as $key => $val) { + $text = trim(addslashes(trans("texts.{$key}", [], $language->locale))); + if (substr($text, 0, 6) == 'texts.') { + $text = $resources->$key; + } + echo "'$key': '$text',\n"; + } + + echo "},\n"; + } + } + + private function getResources() + { + $url = 'https://raw.githubusercontent.com/invoiceninja/flutter-mobile/develop/lib/utils/i18n.dart'; + $data = CurlUtils::get($url); + + $start = strpos($data, '\'en\': {') + 8; + $end = strpos($data, '},', $start); + $data = substr($data, $start, $end - $start - 5); + + $data = str_replace("\n", "", $data); + $data = str_replace("\"", "\'", $data); + $data = str_replace("'", "\"", $data); + + return json_decode('{' . rtrim($data, ',') . '}'); + } + + protected function getOptions() + { + return [ + ['type', null, InputOption::VALUE_OPTIONAL, 'Type', null], + ]; + } + +}