Commit Graph

68 Commits

Author SHA1 Message Date
Andrew Kolos
be724796aa
update generated localized message files in the stocks test app (#148741)
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).
2024-06-03 18:08:19 +00:00
goodmost
3236957f02
chore: fix some comments (#145397)
fix some comments
2024-03-19 17:00:24 +00:00
Christopher Fujino
0f5cd7855d
[flutter_tools] fix flutter create -t skeleton (#141233)
Fixes https://github.com/flutter/flutter/issues/139138

This had been broken since https://github.com/flutter/flutter/pull/130090 merged, however, the test happened run with flutter_tools/pubspec.yaml in the current working directory.
2024-01-10 18:50:07 +00:00
TabooSun
e8436970e6
Gen l10n add named argument option (#138663)
Add an option to use named argument for generated method.

Fix #116308
2024-01-05 21:28:08 +00:00
Andrew Kolos
1952a6c8a1
Add type validation to non-template .arb file parsing logic (#139035)
Resolves https://github.com/flutter/flutter/issues/138297. 

When reading from a .arb file (which contains localizations of strings in the form of a user-defined JSON string-string map), validate the type of values that we read.

See [this comment of mine on #138297](https://github.com/flutter/flutter/issues/138297#issuecomment-1827043260) to see how I arrived at this fix.
2023-11-27 20:50:24 +00:00
Tae Hyung Kim
c6b93b2db7
Relax syntax for gen-l10n (#130736)
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.
2023-07-18 13:59:48 -07:00
Tae Hyung Kim
d75735eea6
Use platform specific line separator in gen-l10n (#130090)
Currently files are not generated with `\r\n` in windows. This PR should
fix the issue.

Fixes https://github.com/flutter/flutter/issues/109761.
2023-07-12 12:50:53 -07:00
Tae Hyung Kim
ff838bca89
Add locale-specific DateTime formatting syntax (#129573)
Based on the [message format
syntax](https://unicode-org.github.io/icu/userguide/format_parse/messages/#examples)
for
[ICU4J](https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/text/MessageFormat.html).
This adds new syntax to the current Flutter messageFormat parser which
should allow developers to add locale-specific date formatting.

## Usage example
```
  "datetimeTest": "Today is {today, date, ::yMd}",
  "@datetimeTest": {
    "placeholders": {
      "today": {
        "description": "The date placeholder",
        "type": "DateTime"
      }
    }
  }
```
compiles to
```
  String datetimeTest(DateTime today) {
    String _temp0 = intl.DateFormat.yMd(localeName).format(today);
    return 'Today is $_temp0';
  }
```

Fixes https://github.com/flutter/flutter/issues/127304.
2023-06-29 09:23:34 -07:00
Tae Hyung Kim
48ba9c4193
Refactor generate_localizations_test.dart (#128974)
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.
2023-06-20 15:42:22 +00:00
Tae Hyung Kim
5596a0cdab
Fix gen-l10n format: true so that it applies to when it gets called via build target (#127886) 2023-05-31 15:25:54 -07:00
Tae Hyung Kim
5c44b1df0f
Refactor "gen-l10n" command to use same code path when "l10n.yaml" is present or not present (#125429)
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.
2023-04-26 11:49:25 -07:00
Tae Hyung Kim
8be335f24c
Handle dollar signs properly when generating localizations (#125514)
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.
2023-04-25 22:52:24 +00:00
Albert Wolszon
509c2ddef3
Add decimalPatternDigits to gen-l10n valid NumberFormats (#122682)
`intl` [0.18.0 added](https://pub.dev/packages/intl/changelog#0180) a
[`NumberFormat.decimalPatternDigits`](https://pub.dev/documentation/intl/latest/intl/NumberFormat/NumberFormat.decimalPatternDigits.html)
pattern that allows `decimalDigits` param.

Fixes #122785

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] ~I updated/added relevant documentation (doc comments with
`///`).~
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-04-06 11:13:47 -07:00
Lioness100
26b6c1bedd
Fix typos (#121171)
* Fix typos

* lowercase animated & opacity

* Undo typo fix

---------

Co-authored-by: Michael Goderbauer <goderbauer@google.com>
2023-02-23 19:43:21 +00:00
Tae Hyung Kim
becb6bd00a
Fix message type inconsistency between locales (#120129)
* init

* fix error handling

* fix issue

* lint?

* error handling tests

* lint
2023-02-13 23:05:57 +00:00
Tae Hyung Kim
3884381415
Make gen-l10n error handling independent of logger state (#119644)
* init

* lint

* lint again
2023-01-31 15:28:27 -08:00
Tae Hyung Kim
117a83a4a7
Throw error when plural case had undefined behavior (#116622)
* init

* add comment

* make error more actionable
2022-12-08 22:29:14 +00:00
Tae Hyung Kim
21f3ce8b69
[gen_l10n] Multiline descriptions (#116380)
* init

* empty commit to start google testing
2022-12-06 19:16:23 +00:00
Ahmed Ashour
f6224f368a
[gen_l10n] keys can contain dollar sign (#114808)
* [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>
2022-12-01 21:42:02 +00:00
Tae Hyung Kim
7802c7acd8
[gen_l10n] Improvements to gen_l10n (#116202)
* init

* fix tests

* fix lint

* extra changes

* oops missed some merge conflicts

* fix lexer add tests

* consistent warnings and errors

* throw error at the end

* improve efficiency, improve code generation

* fix

* nit

* fix test

* remove helper method class

* two d's

* oops

* empty commit as google testing won't pass :(
2022-11-30 15:07:06 -08:00
Tae Hyung Kim
215f6372c6
Refactor Message class to hold all translations (#115506)
* init

* more fixing

* finish

* fix lint

* address pr comments

* redo checks
2022-11-28 20:27:33 +00:00
Tae Hyung Kim
cef4c2aac8
ICU Message Syntax Parser (#112390)
* init

* code generation

* improve syntax error, add tests

* add tests and fix bugs

* code generation fix

* fix all tests :)

* fix bug

* init

* fix all code gen issues

* FIXED ALL TESTS :D

* add license

* remove trailing spaces

* remove print

* tests fix

* specify type annotation

* fix test

* lint

* fix todos

* fix subclass issues

* final fix; flutter gallery runs

* escaping for later pr

* fix comment

* address PR comments

* more

* more descriptive errors

* last fixes
2022-11-05 10:26:46 -07:00
Tae Hyung Kim
001c499f24
[gen_l10n] Warn users when placeholder types are converted to 'num' when using pluralization (#108036)
* init

* asdf

* fix tests

* change warning slightly

* fix test again

* fix spacing and comment

* fix lint
2022-07-26 14:13:06 -07:00
Christopher Fujino
94da724868
[flutter_tools] fix RangeError in gen-l10n by checking for empty string (#107604) 2022-07-15 18:56:09 +00:00
Tae Hyung Kim
2da228593f
[gen_l10n] Throw error when arb file does not exist (#107583) 2022-07-15 18:18:06 +00:00
Michael Goderbauer
3fa355c97d
Remove dead code in tools tests (#104567) 2022-05-25 12:48:17 -07:00
Alex Li
aa39fa5a88
[gen_l10n] Better blank lines in the header of generated files (#103414) 2022-05-12 16:04:18 -07:00
Alex Li
dca58a289b
[gen_l10n] Throw a specified exception when the language code is invalid (#102431) 2022-04-24 11:04:06 -07:00
Hans Muller
09d08510d0
Revert "allow full locale in .arb files (#93401)" (#93806)
This reverts commit 16f441188c.
2021-11-17 11:26:16 -08:00
Taha Tesser
16f441188c
allow full locale in .arb files (#93401) 2021-11-17 09:35:47 -08:00
Shueh Chou Lu
e8b3fe8aa6
Use num on plural (#93228) 2021-11-10 08:47:25 -08:00
J-P Nurmi
550281e581
[gen_l10n] retain full output file suffix (#88362) 2021-11-08 13:55:19 -08:00
Ian Hickson
61a0add286
Enable avoid_redundant_argument_values lint (#91409) (#91462) 2021-10-08 09:25:14 -07:00
Zachary Anderson
b9d2177da0
Revert "Enable avoid_redundant_argument_values lint (#91409)" (#91461)
This reverts commit 5fd259be24.
2021-10-07 21:11:07 -07:00
Ian Hickson
5fd259be24
Enable avoid_redundant_argument_values lint (#91409) 2021-10-07 20:13:02 -07:00
Ahmed Ashour
eb185d73ce
internationalization: fix select with incorrect message (#90096) 2021-09-16 09:23:22 -07:00
Ahmed Ashour
5848a1620d
[gen_l10n] to handle arbitrary DateFormat patterns (#86844) 2021-08-12 14:34:52 -07:00
Ahmed Ashour
bf132daef3
[gen_l10n] correct variable name when the placeholder requiresFormatting (#86842) 2021-07-22 13:55:18 -07:00
Ahmed Ashour
f568d929db
[gen_l10n] Support plurals and selects inside string (#86167) 2021-07-21 12:41:06 -07:00
Shi-Hao Hong
b0bd7cf1d8
make app localizations lookup a public method (#84732) 2021-07-01 15:01:03 -07:00
Alexandre Ardhuin
cfc08594d9
enable lint use_test_throws_matchers (#83943) 2021-06-03 22:14:03 -07:00
Michael Goderbauer
ee17ebe51f
Use type:int without format in gen_l10n (#83132) 2021-05-24 09:54:02 -07:00
Michael Goderbauer
485c409184
import pkg:intl when DateFormat or NumberFormat is used (#83122) 2021-05-21 19:04:04 -07:00
Hattomo (TomohiroHattori)
08a70e7ac8
Enable avoid_escaping_inner_quotes lint (#81153) 2021-05-19 09:54:02 -07:00
Jenn Magder
25c10d6a1c
Replace testUsingContext with testWithoutContext in a few places (#82498) 2021-05-13 23:09:03 -07:00
Shi-Hao Hong
633edb649f
[gen-l10n] Cleans up formatting of the generated file (#79517) 2021-05-11 17:19:05 -07:00
Phil Quitslund
61c30c41b2
fix sort_directives violations (#80817) 2021-04-21 13:49:03 -07:00
Jenn Magder
728a193383
Migrate gen_l10n to null safety (#80763) 2021-04-20 11:09:03 -07:00
Jenn Magder
b4175e9b86
Refactor LocalizationsGenerator initialize instance method into factory (#80605) 2021-04-19 20:24:04 -07:00
Shi-Hao Hong
9077a5c69b
[gen-l10n] Remove more ignores, conditionally generate some code (#78975) 2021-03-31 19:54:02 -07:00