thienson98 / tftranslator
A simple package help you automatically translate all text on your site to other languages.
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-19 19:12:38 UTC
README
A simple Laravel package help you automatically translate all text on your site to other languages. Writed by Trieu Tai Niem.
Requirement
- PHP: >= 7.0
- Laravel: >= 5.5
Features
-
Automatically find translate string in parameter of translation functions ( _() or lang() ) and generate into json translation files
-
Automatically translates text found into other languages using google translator
-
Automatically updates and translates newly added text
Installation
Open terminal and change directory to your project folder, now using composer command bellow to install package:
composer require thienson98/tftranslator
Finally, open laravel config file config/app.php and add the following line to end of $provider array:
ThienSon98\TFTranslator\TFTranslatorServiceProvider::class
That's all!
How to use?
If you want to automatically generate keys from translation functions (__ or lang) into json language files, use the following command:
php artisan 3F:translator
Of course, you can also use the above command to update the changes in your files
Auto find and insert translation function
You do not want to take the effort to insert text as parameter of translation function?
Do not worry! You just execute the command bellow:
php artisan 3F:translator --auto
Translation functions will be added to the view files and automatically generated json language files.
Specify other languages
The default languages of the translator are Vietnamese (vi) and English (en). You can translate into other languages with the --lang=<language code>
option.
For example, use the following command to translate to Japanese:
php artisan 3F:translator --lang=ja
Or translate to Vietnamese, Japanese and Chinese:
php artisan 3F:translator --lang=ja,vi,zh
It supports all languages and works with all of the options.
Remove unused keys
To clean unused translation keys, you can use the following command:
php artisan 3F:translator --clear
It will remove all the keys that are not using in views.
Just write the translation keys
Of course, if you do not want to use Google translator to translate your texts. You can use the option below:
php artisan 3F:translator --justwrite
It will ignore auto-translations and only give you translation keys into json files.
This option works with all of the options above.