Translating Flutter Apps Just Got Better

New improvements in auto_translator 2.3.0

Lee Phillips
Level Up Coding

--

Introduction

I previously introduced the Dart package auto_translator in a Medium article here. If you are not familiar with the package, you may want to check out the article, or just head over to the Readme on pub.dev. For those whom are familiar, this article will cover the improvements and features added since release. You can also check out the Changelog and Readme, and be sure to update the package version to ^2.3.0 in your pubspec.yaml.

DeepL Translation

One of the biggest new features in auto_translator is the addition of support for DeepL Translation. Users have found that this service performs better than Google Cloud Translate for certain phrases in some languages. Just like with Google Cloud Translate, all you need is an API key for the DeepL Translate service.

New Configuration Params

The translator configuration in l10n.yaml now accepts 3 new parameters to help you achieve the best machine translations possible for your app.

Primary Translator Service

The service parameter allows you to define the primary service to use when translating your ARB files. This value defaults to Google but can be set to DeepL as well (capitalization does not matter). This will be the service used for any language that is not otherwise specified.

Preferred Translator Services

You can use the prefer-service parameter to define an alternative translation service for any given language. To do so, provide a list of language codes to the service name.

translator:
# all other languages will use Google Cloud Translate
prefer-service:
DeepL:
- tr
- uk

Preferred Language Templates

The prefer-lang-templates parameter allows you to specify a different language to use as a source template for a given target language. This can be very beneficial, especially when translating idiomatic expressions between closely related languages. Provide a map of target languages to source languages.

translator:
# use es template for fr translation & ja for ko
# all other translations will use [template-arb-file]
prefer-lang-templates:
fr: es
ko: ja

ARB Improvements

New Format

Since auto_translator was released, the format specs for ARB files changed slightly, making outdated ARB files incompatible with current flutter_localizations and intl packages. Version 2.0.0 was released to account for these changes.

Comments

As your ARB files grow, you may wish to use comments to help keep them organized. This can be done with the following approach.

"@_ARB_COMMENT": {},
"arbString": "blah blah blah"

If you use @@locale in the template ARB file, an entry will be added to the top of all generated ARB files as well.

Placeholder Examples

ARB files allow us to provide an example value in the string’s metadata.

"arbString": "Hello, {name}!",
"@arbString": {
"placeholders": {
"name": {
"type": "String",
"example": "world"
}
}
}

auto_translator now uses the example if one is provided, which can improve translation accuracy in certain situations, for example, when proper nouns are handled uniquely in a language.

Conclusion

auto_translator is a great tool for quickly translating your app for internationalization. With these added features, along with other performance improvements, the process is now better and easier than ever. Upgrade your version or start using auto_translator today, and check out pub.dev for all the information you need to get the most out of it.

If you find the the package useful, please give it a like on pub.dev and maybe even a start on GitHub. A round of applause on this article would be appreciated as well 😊. If you have an issue or wish to see a new feature, such as additional translation services, please leave a comment below and/or submit an issue on GitHub. Contributions are welcome as well!

Thank you for reading!

--

--

Software engineer. Flutter fanatic. I am here to share knowledge & inspire others to create great experiences.