Fixes https://github.com/flutter/flutter/issues/149386. Fixes https://github.com/flutter/flutter/issues/106150.
The stocks test app includes Dart files containing localized messages generated by `package:flutter_localizations`. However, these files appear to have become out of date. Running `pub get` in the project will regenerate these files and generate a diff, which can be annoying when working on the repo.
This PR generates the files. ~~It also updates the templates for these files to be compliant with flutter/flutter repo lint rules, including `noop_primitive_operations` and `use_super_parameters`.~~ It also adds `// ignore_for_file: type=lint` to these files to disable linting for these files. This avoids issues like https://github.com/flutter/flutter/issues/106150 and [this](https://github.com/flutter/flutter/pull/148741#issuecomment-2141161753).
To preserve backward compatibility with the old parser which would
ignore syntax errors, this PR introduces a way to treat the special
characters `{` and `}` in the following way:
1. If we encounter a `{` which searching for a string token and this `{`
is not followed by a valid placeholder, then we treat the `{` as a
string and continue lexing for strings.
2. If we encounter a `}` while not within some expression (i.e.
placeholders, arguments, plurals, or selects), then we treat the `}` as
a string and continue lexing for strings.
This makes it so that
```
"helloWorld": "{ } { placeholder }",
"@@helloWorld": {
"placeholders": {
"placeholder" {}
}
}
```
treats the `{ }` as a string while `{ placeholder } ` is treated as a
placeholder.
Fixes https://github.com/flutter/flutter/issues/122404.
The file was becoming harder to deal with as it manually sets up a /lib/l10n directory with a `MemoryFileSystem` in every single test. This PR wraps this process in a helper function `setupLocalizations` and also provides a helper function `getGeneratedFileContent` which helps fetch the respective output file given the locale string.
I think this is a long needed change to the `gen-l10n` command.
Essentially, the arguments to `flutter gen-l10n` can be provided by two
different methods: via command line arguments or via the `l10n.yaml`
file. The existence of a `l10n.yaml` file causes the latter approach to
take precedence.
However, currently, there's several differences in how the two
approaches are handled, and most of the default arguments are all over
the place, causing unexpected issues such as #120457 or #120023.
This PR refactors the command so that
* `LocalizationOptions` are more consistent with the actual argument
names/yaml options.
* All default values are determined in `LocalizationOptions`'s
constructor (or in `argParser.addOption(...)` in the case a boolean
value needs to be explicitly true).
* New `parseLocalizationsOptionsFromCommand` function to parse
arguments.
* Parse `LocalizationOptions` at the beginning of `runCommand()` and
pass it to `generateLocalizations`.
Fixes#120023.
Currently, the code doesn't properly handle strings which contain dollar signs. The return expression for the generated localization function is computed by `generateReturnExpr` which concatenates several strings, which are either interpolated placeholders, interpolated function calls, or normal strings, but we didn't properly escape dollar signs before sending normal strings to `generateReturnExpr`.
Fixes#125461.
* [gen_l10n] keys can contain dollar sign
Fixes#112250
* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart
Co-authored-by: Christopher Fujino <fujino@google.com>