1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Console/Commands/MobileLocalization.php

138 lines
3.4 KiB
PHP
Raw Normal View History

2021-05-04 06:47:37 +02:00
<?php
2023-01-28 22:37:34 +01:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2023-01-28 22:37:34 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
2021-05-04 06:47:37 +02:00
namespace App\Console\Commands;
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);
2021-05-04 06:47:37 +02:00
2023-04-28 06:45:35 +02:00
//replace the three lines above with this
// if($language->locale == 'ar') {
// $text = str_replace('\n', " ", $text);
// }
// $text = str_replace(['<strong>', '</strong>','<i>', '</i>','<b>', '</b>'], '', $text);
// $text = str_replace('"', "'", $text);
2021-05-04 06:47:37 +02:00
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);
2022-11-07 21:04:00 +01:00
$data = str_replace("\'", "\#", $data);
$data = str_replace("'", '"', $data);
2022-11-07 21:04:00 +01:00
$data = str_replace("\#", "'", $data);
2021-05-04 06:47:37 +02:00
return json_decode('{'.rtrim($data, ',').'}');
2021-05-04 06:47:37 +02:00
}
protected function getOptions()
{
return [
['type', null, InputOption::VALUE_OPTIONAL, 'Type', null],
];
}
}