Skip to content

Provide an option to verify translation key integrity in translation files #88

Open
@navaronbracke

Description

@navaronbracke

I have a question about the usage of intl_utils.

I recently had a bug where I thought that my translations were not being generated correctly.
Turns out that I had mismatching keys between translation files.
I.e.

intl_en.arb (128 entries)

"FirstKey": "foo",
"SecondKey": "bar"
"ThirdKey": "qux"
intl_fr.arb (128 entries)

"FirstKey": "foo",
"SecondWoopsKey": "bar"
"ThirdKey": "qux"

It took me a while to figure that out (especially with large translation files).
Would there be an option to have a validation check that is run before the translations are generated?
We could turn it on in the pubspec.yaml configuration.
All that the check would do is the following:

  1. Take the keys from the main translation file (the main_locale option)
  2. For each other translation file, verify that it has exactly the same set of keys
  3. If one or more files do not match the main translation file, exit with an error and perhaps show which files have conflicts and where

This would make it easier to spot the following errors:

  • missing keys in any translation file (works both ways I think)
  • the same amount of keys but different names (the issue I had earlier)

The errors could look like:

// missing translation in child translation file
File 'intl_fr.arb' does not have a translation for 'foo'. Either the key does not exist, or its name does not exactly match the one in main translation file 'intl_en.arb'

// translation in child translation file that does not yet exist in the main translation file
File 'intl_fr.arb' has a translation named 'bar' that does not yet exist in the main translation file 'intl_en.arb'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions