Skip to content

Find Translations Command

The mm:find-translations command is used to scan module files for translation strings and update language files accordingly.

Usage

bash
php artisan mm:find-translations [module]

Arguments

ArgumentDescription
module(Optional) The specific module name to process

Description

This command scans the PHP and Blade files in your modules to find strings that need translation. It extracts these strings and updates the language files for easier localization of your modules.

When executed, this command performs the following actions:

  1. Scan Files: Searches through PHP and Blade files in the specified module(s) for strings that need translation.

  2. Update Language Files: Creates or updates the language files in the module's lang directory, adding new translation strings.

  3. Optional AI Translation: Offers to use AI translation services to automatically translate the found strings to other languages configured in your application.

Examples

Process All Modules

bash
$ php artisan mm:find-translations
Starting in "Blog Module"
Created language directory for Blog
Found 25 new strings, added to json file

Starting in "Shop Module"
Found 15 new strings, added to json file

Finish...
40 strings found, the following modules have language updates:
+-------+-------------+
| Module| New Strings |
+-------+-------------+
| Blog  | 25          |
| Shop  | 15          |
+-------+-------------+

Do you want to use AI to translate the strings? (y/n) [y]

Process a Specific Module

bash
$ php artisan mm:find-translations Blog
Starting in "Blog Module"
Found 25 new strings, added to json file

Finish...
25 strings found, the following modules have language updates:
+-------+-------------+
| Module| New Strings |
+-------+-------------+
| Blog  | 25          |
+-------+-------------+

Do you want to use AI to translate the strings? (y/n) [y]

AI Translation Integration

When new strings are found, the command offers to use AI services to translate them to the languages configured in your module-manager.translation configuration. This requires:

  1. A valid API key for the translation service
  2. Proper configuration of source and target languages

The command supports:

  • OpenAI's language models for translation
  • Multiple target languages in a single run
  • Batch processing to optimize API usage

Configuration

The translation functionality uses the configuration defined in config('module-manager.translation'):

php
'translation' => [
    'TRANSLATION_API_KEY'        => env('TRANSLATION_API_KEY', null),
    'TRANSLATION_MODEL_PROVIDER' => env('TRANSLATION_MODEL_PROVIDER', 'openai'),
    'TRANSLATION_MODEL'          => env('TRANSLATION_MODEL', 'gpt-3.5-turbo'),
    'from_language'              => 'en',
    'to_language'                => ['es', 'pt_BR'],
],

Notes

  • This command helps maintain multi-language support across your modules.
  • It only extracts strings that haven't been previously added to the language files.
  • Translation files are created in JSON format for easier management.
  • The AI translation feature is optional and can be skipped if not needed.