From a0845f6f0ea20778f94be1c75e634e14290eaa10 Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Mon, 2 Dec 2024 19:42:51 +0100 Subject: [PATCH] docs: update documentation of i18n support --- README.md | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7bcf735..4c3dd1c 100644 --- a/README.md +++ b/README.md @@ -824,33 +824,23 @@ Whenever an exception is caught by `Application::handle()`, it will show a beaut **adhocore/cli** also supports internationalisation. This is particularly useful if you are not very comfortable with English or if you are creating a framework or CLI application that could be used by people from a variety of backgrounds. -By default, all texts generated by our system are in English. But you can easily change them at any time +By default, all the texts generated by our system are in English. But you can easily modify them by defining your translations as follows ```php -\Ahc\Translations\Translator::$locale = 'fr'; +\Ahc\Application::addLocale('fr', [ + 'Only last argument can be variadic' => 'Seul le dernier argument peut être variadique', +], true); ``` -The system currently supports 5 fully translated languages: - -* English: `en` -* French: `fr` -* Spanish: `es` -* German: `de` -* Russian: `ru` - -If the language you want to use is not supported natively, you can create your own translation file from the main translation file. Simply copy the entire contents of the file `vendor/adhocore/cli/src/Translations/en.php` and translate all the translation values into the desired language. - -After that, you will need to enter the path to the folder where your translation files are stored. -For example, if you have made Chinese (`ch`) and Arabic (`ar`) translations, and they are respectively in the `APP_PATH/translations/ch.php` and `APP_PATH/translations/ar.php` files, you can configure the translator as follows +You can also change the default English text to make the description more explicit if you wish. ```php -\Ahc\Translations\Translator::$translations_dir = APP_PATH . '/translations'; -\Ahc\Translations\Translator::$locale = 'ch'; // or 'ar' +\Ahc\Application::addLocale('en', [ + 'Show help' => 'Shows helpful information about a command', +]); ``` -In the same way, you can override the built-in translations, just create your own file `en.php` or `fr.php`, etc... and indicate the folder in which it is located - -You don't have to translate all the translation keys. If a translation key does not exist in your implementation, the default value will be used. This allows you to translate only the elements you consider important (for example, exception messages do not necessarily need to be translated). +vous pouvez trouver toutes les clés de traduction supportées par le paquet dans cette gist : https://gist.github.com/dimtrovich/1597c16d5c74334e68eef15a4e7ba3fd ## Autocompletion