skip to Main Content

After Updating to Flutter 3.7.0 i get this error message when i build my App:

[app_en.arb:scanCode_fieldNotMatched] ICU Syntax Error: Expected
"identifier" but found "0".
field to match is "{0}"

It seems as if something had changed in how the variables are written in the .arb localization files.

2

Answers


  1. Chosen as BEST ANSWER

    UPDATE 1: Escape syntax characters!

    If what you are trying is to use the characters {, }, ' (or any other syntax character for that matter) in your strings, then you will have to escape them. To do that enable the use-escaping flag by adding the following to l10n.yaml

    use-escaping: true
    
    

    Now use pairs of single quotes to escape syntax characters, like "{". To escape single quotes you just have to write it as a double-single quote as follows:

    {
      "some_text": "Using the '{' character '{isn''t}' trivial?"
    }
    

    More details on this in the flutter docu.


    Update 2: If you are using a Chinese Mirror for Flutter

    Follow details in this issue.


    Original answer to my punctual problem

    I found out that the reason for this error is that in Flutter 3.7

    Internationalization support has been completely revamped! [they]’ve completely rewritten the gen-l10n tool...

    as stated in a release post.


    Previously i was declaring strings in my .arb file as follows

    "scanCode_fieldNotMatched": "field to match is "{0}"",
    

    where afterwards i was replacing {0} by some other value.

    Well, it seems that now the gen-l10n tool takes what is between brackets as special parameters, and the name "0" is not accepted so i had to change my string to

    "scanCode_fieldNotMatched": "field to match is "{value0}"",
    

    and AppLocalizations can be now called as:

    AppLocalizations.of(context)!.scanCode_fieldNotMatched("something here to replace value0!")
    

    Further details on this can be found here: Placeholders, plurals, and selects in Flutter.


  2. In my case, it was due to a translation string in my arb file for intl package. I had:

    "{x, plural, =1{item}, other{items}}" (worked fine in previous versions)

    This broke in Flutter 3.7. The solution for me was removing a comma:

    "{x, plural, =1{item} other{items}}" (works in Flutter 3.7)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search