Skip to content

Commit

Permalink
docs: update documentation of i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtrovich committed Dec 2, 2024
1 parent c8dce0e commit a0845f6
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a0845f6

Please sign in to comment.