7

I am using flutter_localizations to localize my app.

Since updating to Flutter 3.7 i am getting this error:

ICU Syntax Error: Expected "identifier" but found "}".

This =|(){}[] obviously

This =|\(){}[] obviously is the text that i have in my .arb file.

I understand that curly braces "{}" have a special meaning and should be escaped, but i can not find the way to correctly escape them, has anyone managed to do so?


One simple way to reproduce the issue is simply following the steps to add localization support here, and then instead of the hello world string, write anything that includes the character "{".


P.S.: There is a releted issue open on Github. Be sure to go and check there for updates!

deczaloth
  • 7,094
  • 4
  • 24
  • 59

1 Answers1

3

There is an escaping syntax that is implemented but not enabled by default as it is a new feature that wasn't completely backward compatible with existing ICU message strings.

First, add the following to your l10n.yaml file:

use-escaping: true

Then, this will allow you to wrap parts of your strings in single quotes to ignore any syntax within the single quotes; to use a single quote normally as a character and not an escape, use a double single quote. For example,

{
  message: "This '{isn''t}' obvious"
}

becomes

String get message => "This {isn't} obvious";

See here for information on the syntax. I'll add this to the documentation later.

  • I tried enabling this, but I now have hundreds of "unmatched single quotes" errors in my translated arb files. Any automated way of fixing them? :) – giorgio79 Aug 10 '23 at 04:56
  • I think finding and replacing all single quotes to a double single quote should do the trick. Your text editor should be able to do this. If not there was a PR I made that relaxes the syntax for the `gen-l10n` parser so that it doesn't treat curly braces as syntax in some scenarios. Check this out: https://github.com/flutter/flutter/pull/130736, but I can't recommend that using this is a good idea. – Tae Hyung Kim Aug 10 '23 at 18:10