How to disable "untranslated message" warnings from Flutter gen-l10n for country files

1.7k Views Asked by At

The specific case I'm looking at is two .arb language files: en and en_AU. en includes all the translation tokens and en_AU includes only a few that are actually different. This works as expected: with en_AU locale en tokens are used when no alternate translation provided.

However, when running flutter gen-l10n it gives the untranslated message(s) warning for en_AU. Is there a way to turn this off, while preserving the warning for different languages?

3

There are 3 best solutions below

0
On

Below answer is based on the usage of flutter_localizations

pubspec.yaml

  flutter_localizations:
    sdk: flutter

Create a file named l10n.yaml in your root location.

arb-dir: lib/l10n/translations. // where all translation exists
template-arb-file: app_en.arb. // default file to consider as template
output-localization-file: app_localizations.dart //generated output file which contains getters for all the translation keys
untranslated-messages-file: untranslated_keys // this line of code will removing the warnings, but it will generate the file named untranslated_keys with details on which files missing what keys

Please follow the comments on each line to understand the purpose.

Example snippet of untranslated_keys

{
  "de": [
    "homePage_title",
    "homePage_header",
    "login_button_title",
  ],

  "es": [
    "homePage_title",
    "homePage_header",
  ],

  "fr": [
     "homePage_title",
    "homePage_header",
  ],
}

This will help you understand what translations are missing which could potentially break behaviour on specific locales.

Refer https://pub.dev/packages/flutter_localization

0
On

Create l10n.yaml file in the project root and add below code

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
nullable-getter: false
untranslated-messages-file: l10n_errors.txt

run flutter gen-l10n it will general l10n_errors.txt file and you can see untranslated items.

0
On

How about you just provide translartions ffor these different languages. The linter is clearly notifying you that you didn't provide some translations. All you have to do is translate it. If you're finding difficulty figuring out which one you didn't translate, you could just use Chat GPT