Download the PHP package lehadnk/translation-merge-tool without Composer
On this page you can find all versions of the php package lehadnk/translation-merge-tool. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package translation-merge-tool
Introduction
i18n_mrg is the helper tool that scans your project's codebase for translated strings and synchronizes translations with a popular translation tool named Weblate and back.
Installation
The software you need to install the translation merge tool:
- PHP >= 7.0
- Composer package manager
- GNU Gettext package (already installed on macOS and most Linux distributions)
- NodeJS >= 6.0 (for JS projects)
- i18next converter (if you use i18next for your js project)
You require php>=8.1 to run the software. Also, you require to have a PHP packet manager (composer), which you may get here.
Run the following command to install the tool:
Running the tool
Run the following command under your project root:
Project setup
First, you need to prepare your codebase to work with i18n_mrg:
-
Configure your project to work with translation files. We'd suggest you use GNU gettext format, but i18n_mrg could also compile JSON files as well if you prefer, which works better for web applications. You need to set up a directory in your project and store your translation files in it, naming each subfolder with the language code you're planning to use. Example file tree structure:
-
Use the wrapper function named
__()
to mark your translation strings. Implement the function to return the corresponding string from your storage, e.g.: -
Add
.translate-config.json
to your project root. The example contents of the file: - Next, define the translation branch in your repository. Usually, you want it to be managed by translation tools (i18n_mrg and Weblate) only, and never touch it:
git checkout -b translations && git push --set-upstream origin translations
- Set up the Weblate platform and define the component for your project.
- Now run
i18n_mrg
to scan your project for translation strings and initially upload them to Weblate. i18n_mrg will parse your codebase for every string wrapped in __() decorator and add it to translation files, the pull updates from Weblate automatically.
Developer workflow
For developers working with i18n_mrg
on your project, I'd suggest the following workflow:
- When you're about to be done with your working branch, which contains translation strings, run
i18n_mrg
and push new translation strings to Weblate. - Notify the person in your team responsible for handling translation that new strings are added to Weblate.
- Once translations are done, run
i18n_mrg
again to pull translated strings from Weblate and add updated translated files to your branch.
In big teams, you may also want translations files compilation to be a part of your CI cycle.
Updating the tool
Handling authorization tokens
To use the tool with various VCS providers, you must set up authorization.
Gitlab
- Create the key using your profile settings > Access Tokens.
- Your key must have the next scopes: api, read_repository, write_repository
- Export your token to I18N_MRG_GITLAB_AUTH_TOKEN env variable:
export I18N_MRG_GITLAB_AUTH_TOKEN=<token>
Github
- Goto Settings > Developer Settings > Personal access tokens
- Create a token with scope: repo
- Export your token to I18N_MRG_GITHUB_AUTH_TOKEN env variable:
export I18N_MRG_GITHUB_AUTH_TOKEN=<token>
BitBucket
- Go to repository settings
- Issue the repository access token with read/write permissions in the "Access Tokens" section
- Place your token in I18N_MRG_BITBUCKET_AUTH_TOKEN env variable:
export I18N_MRG_BITBUCKET_AUTH_TOKEN=<token>
How to add it to the project
First, you need to create a.translate-config.json
configuration file under the project's root. Example contents of the config file:
Troubleshooting
Some Mac users reported that they had issues with the gettext tool installed through Brew. Unlinking and linking it again resolves the issue: