mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
19080933b6
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started. For more information on customizing the code style applied by Shift, [watch this short video][4]. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://github.com/squizlabs/PHP_CodeSniffer [3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 [4]: https://laravelshift.com/videos/shift-code-style
119 lines
2.9 KiB
PHP
119 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\User;
|
|
use App\Utils\CurlUtils;
|
|
use Illuminate\Console\Command;
|
|
|
|
class MobileLocalization extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'ninja:mobile-localization {--type=}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Generate mobile localization resources';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$type = strtolower($this->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;
|
|
}
|
|
|
|
$text = str_replace(['<b>', '</b>'], '', $text);
|
|
$text = str_replace(['<i>', '</i>'], '', $text);
|
|
$text = str_replace(['<strong>', '</strong>'], '', $text);
|
|
|
|
echo "'$key': '$text',\n";
|
|
}
|
|
|
|
echo "},\n";
|
|
}
|
|
}
|
|
|
|
private function getResources()
|
|
{
|
|
$url = 'https://raw.githubusercontent.com/invoiceninja/flutter-client/develop/lib/utils/i18n.dart';
|
|
$data = CurlUtils::get($url);
|
|
|
|
$start = strpos($data, 'do not remove comment') + 25;
|
|
$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],
|
|
];
|
|
}
|
|
}
|