diff --git a/Dockerfile b/Dockerfile index a7cae38502..f993079ce0 100755 --- a/Dockerfile +++ b/Dockerfile @@ -343,6 +343,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/ssl && \ chmod +x /usr/local/bin/test && \ chmod +x /usr/local/bin/vars && \ + chmod +x /usr/local/bin/locales && \ chmod +x /usr/local/bin/worker-audits && \ chmod +x /usr/local/bin/worker-certificates && \ chmod +x /usr/local/bin/worker-databases && \ diff --git a/app/cli.php b/app/cli.php index 09b3dc9413..28674767f1 100644 --- a/app/cli.php +++ b/app/cli.php @@ -12,16 +12,20 @@ Authorization::disable(); $cli = new CLI(); +// Administartive commands include 'tasks/doctor.php'; include 'tasks/maintenance.php'; include 'tasks/install.php'; include 'tasks/migrate.php'; -include 'tasks/sdks.php'; -include 'tasks/specs.php'; include 'tasks/ssl.php'; include 'tasks/vars.php'; include 'tasks/usage.php'; +// Tooling commands +include 'tasks/sdks.php'; +include 'tasks/specs.php'; +include 'tasks/locales.php'; + $cli ->task('version') ->desc('Get the server version') diff --git a/app/tasks/locales.php b/app/tasks/locales.php new file mode 100644 index 0000000000..d93136b403 --- /dev/null +++ b/app/tasks/locales.php @@ -0,0 +1,63 @@ +task('locales') + ->desc('Find missing locales configuration') + ->param('type', 'verbose', new WhiteList(['verbose', 'debug', 'json']), 'Style of result logging.', true) + ->action(function ($type) { + $languages = Locale::getLanguages(); + + $mainLanguage = 'en'; + $mainTranslations = []; + + $mainLocale = new Locale($mainLanguage); + foreach ($mainLocale->getTranslations() as $key => $value) { + if(!empty($value)) { + $mainTranslations[] = $key; + } + } + + $results = []; + + foreach ($languages as $language) { + $locale = new Locale($language); + $translations = $locale->getTranslations(); + $missing = []; + foreach ($mainTranslations as $translation) { + if(empty($translations[$translation])) { + $missing[] = $translation; + } + } + + if(\count($missing) <= 0) { + $type !== 'json' && Console::success('Locale "' . $language . '" is fully translated.'); + } else { + $type !== 'json' && Console::error('Locale "' . $language . '" is missing ' . \count($missing) . ' translations.'); + + if($type === 'debug') { + foreach ($missing as $key) { + Console::log('"' . $key . '" missing in "' . $language . '".'); + } + } else if ($type === 'json') { + if(!(\array_key_exists($language, $results))) { + $results[$language] = []; + } + + $results[$language] = $key; + } + } + } + + $type !== 'json' && Console::info('To get detailed information about missing translations, run the command with --type=debug parameter. Use --type=json to get JSON formatted results.'); + + if($type === 'json') { + Console::log(\json_encode($results)); + } + + }); diff --git a/bin/locales b/bin/locales new file mode 100755 index 0000000000..92b12b9b33 --- /dev/null +++ b/bin/locales @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php locales $@ \ No newline at end of file diff --git a/composer.json b/composer.json index 973aec8539..f52b6dbf71 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", "utopia-php/database": "0.25.*", - "utopia-php/locale": "0.4.*", + "utopia-php/locale": "dev-feat-get-languages as 0.4.0", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", "utopia-php/domains": "1.1.*", diff --git a/composer.lock b/composer.lock index cd2040eb1a..1a9cd6b30c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "568151395a8877f87d9bdce048adc2dc", + "content-hash": "ed42f5767ed3c24ad5bddccb4c164270", "packages": [ { "name": "adhocore/jwt", @@ -2279,16 +2279,16 @@ }, { "name": "utopia-php/locale", - "version": "0.4.0", + "version": "dev-feat-get-languages", "source": { "type": "git", "url": "https://github.com/utopia-php/locale.git", - "reference": "c2d9358d0fe2f6b6ed5448369f9d1e430c615447" + "reference": "88f855c56445452a916f60282529f8c3d96a66b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/locale/zipball/c2d9358d0fe2f6b6ed5448369f9d1e430c615447", - "reference": "c2d9358d0fe2f6b6ed5448369f9d1e430c615447", + "url": "https://api.github.com/repos/utopia-php/locale/zipball/88f855c56445452a916f60282529f8c3d96a66b8", + "reference": "88f855c56445452a916f60282529f8c3d96a66b8", "shasum": "" }, "require": { @@ -2324,9 +2324,9 @@ ], "support": { "issues": "https://github.com/utopia-php/locale/issues", - "source": "https://github.com/utopia-php/locale/tree/0.4.0" + "source": "https://github.com/utopia-php/locale/tree/feat-get-languages" }, - "time": "2021-07-24T11:35:55+00:00" + "time": "2022-10-07T07:22:14+00:00" }, { "name": "utopia-php/logger", @@ -5358,9 +5358,18 @@ "time": "2022-09-28T08:42:51+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/locale", + "version": "dev-feat-get-languages", + "alias": "0.4.0", + "alias_normalized": "0.4.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/locale": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -5384,5 +5393,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" }