Skip to content

Commit b8e089f

Browse files
committed
docs: documentation for i18n support
1 parent 733285e commit b8e089f

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,39 @@ Whenever an exception is caught by `Application::handle()`, it will show a beaut
820820

821821
![Exception Preview](https://user-images.githubusercontent.com/2908547/44401057-8b350880-a577-11e8-8ca6-20508d593d98.png "Exception trace")
822822

823-
### Autocompletion
823+
## I18n Support
824+
825+
**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.
826+
827+
By default, all texts generated by our system are in English. But you can easily change them at any time
828+
829+
```php
830+
\Ahc\Translations\Translator::$locale = 'fr';
831+
```
832+
833+
The system currently supports 5 fully translated languages:
834+
835+
* English: `en`
836+
* French: `fr`
837+
* Spanish: `es`
838+
* German: `de`
839+
* Russian: `ru`
840+
841+
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.
842+
843+
After that, you will need to enter the path to the folder where your translation files are stored.
844+
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
845+
846+
```php
847+
\Ahc\Translations\Translator::$translations_dir = APP_PATH . '/translations';
848+
\Ahc\Translations\Translator::$locale = 'ch'; // or 'ar'
849+
```
850+
851+
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
852+
853+
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).
854+
855+
## Autocompletion
824856

825857
Any console applications that are built on top of **adhocore/cli** can entertain autocomplete of commands and options in zsh shell with oh-my-zsh.
826858

0 commit comments

Comments
 (0)