arb_translate 0.1.2 arb_translate: ^0.1.2 copied to clipboard
A command-line tool for automatically generating missing translations to ARB files using Google Gemini API by LeanCode.
arb_translate #
A command-line tool for automatically generating missing translations to ARB files using Google Gemini API by LeanCode
Installation #
$ dart pub global activate arb_translate
Configuration #
arb_translate
has been designed to seamlessly integrate with Flutter apps
using flutter_localizations
for code generation from ARB files. Thanks to this
integration, the setup process for arb_translate can be completed in just a few
steps:
With l10n.yaml configuration file #
- Generate your Gemini API token by following https://ai.google.dev/tutorials/setup
- Save your API token in the environment variable
ARB_TRANSLATE_API_KEY
or addarb-translate-api-key: {your-api-key}
tol10n.yaml
in your project - (Optional) Add context of your application
arb-translate-context: {your-app-context}
eg. "sporting goods store app"
All other required parameters match flutter_localizations
parameters and will
be read from l10n.yaml
file. You can override them using command arguments if
necessary. See arb_translate --help
for more information.
Without l10n.yaml configuration file #
- Generate your Gemini API token by following https://ai.google.dev/tutorials/setup
- Save your API token in the environment variable
ARB_TRANSLATE_API_KEY
or specify as command argument--api-key {your-api-key}
- Specify other option as command arguments:
--arb-dir
The directory where the template and translated ARB files are located--template-arb-file
The template ARB file that will be used as the basis for translation- (Optional) Add context of your application
--context {your-app-context}
eg. "sporting goods store app"
See arb_translate --help
for more information.
Configuration in regions where Gemini API is unavailable #
Gemini API is not available in all regions such as EU. You can strill use
arb_translate
but you need to access Gemini via Vertex AI service from Google
Cloud Platform. Because of that configuration is a bit longer:
- Create your GCP project and enable Vertex AI by following https://cloud.google.com/vertex-ai/docs/generative-ai/start/quickstarts/api-quickstart
- Generate your API token using gcloud CLI
$ gcloud auth print-access-token
- Save your API token in the environment variable
ARB_TRANSLATE_API_KEY
or addarb-translate-api-key: {your-api-key}
tol10n.yaml
or specify as command argument--api-key {your-api-key}
- Add
arb-translate-vertex-ai-project-url: {your-project-url}
tol10n.yaml
or specify as command argument--vertex-ai-project-url {your-project-url}
. Project url should look like thishttps://{region}-aiplatform.googleapis.com/v1/projects/{your-project-id}/locations/{region}/publishers/google/models
- Add
arb-translate-model-provider: vertex-ai
tol10n.yaml
or specify as command argument--model-provider: vertex-ai
Usage #
To generate translations, simply call arb_translate. All messages included in the template ARB file but missing from other files will be translated. To add a new locale, simply add an empty ARB file.
$ arb_translate
Or without l10n.yaml
file
$ arb_translate --arb-dir...
Read more #
If you want to know how we made this tool and what challenges we had, read the story.
#
Built with ☕️ by LeanCode