-
Notifications
You must be signed in to change notification settings - Fork 29.1k
ICU Message Syntax Parser #112390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICU Message Syntax Parser #112390
Conversation
auto label is removed for flutter/flutter, pr: 112390, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
auto label is removed for flutter/flutter, pr: 112390, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
* cef4c2a ICU Message Syntax Parser (flutter/flutter#112390) * 07d3a64 0886c7d0b Narrow the scope of the Windows Android arm hack (flutter/engine#37125) (flutter/flutter#114751) * cf0cd06 Mark new_gallery__transition_perf as non-flaky (flutter/flutter#114694) * 5bc50c1 Fix macOS migration nothing-to-upgrade test (flutter/flutter#114703) * b1509ed 36cfa9e68 Apply the Windows friendly path solution in remaining spots (flutter/engine#37344) (flutter/flutter#114759) * b45e628 b8218eacc Roll Fuchsia Mac SDK from Ua8Jtf8Zka9uxIVdl... to sNXsQVxntMX8f42LE... (flutter/engine#37352) (flutter/flutter#114760) * 5ea5a53 6f3018a72 Roll Skia from a34882309d04 to c3c31be8729b (1 revision) (flutter/engine#37358) (flutter/flutter#114765)
* cef4c2a ICU Message Syntax Parser (flutter/flutter#112390) * 07d3a64 0886c7d0b Narrow the scope of the Windows Android arm hack (flutter/engine#37125) (flutter/flutter#114751) * cf0cd06 Mark new_gallery__transition_perf as non-flaky (flutter/flutter#114694) * 5bc50c1 Fix macOS migration nothing-to-upgrade test (flutter/flutter#114703) * b1509ed 36cfa9e68 Apply the Windows friendly path solution in remaining spots (flutter/engine#37344) (flutter/flutter#114759) * b45e628 b8218eacc Roll Fuchsia Mac SDK from Ua8Jtf8Zka9uxIVdl... to sNXsQVxntMX8f42LE... (flutter/engine#37352) (flutter/flutter#114760) * 5ea5a53 6f3018a72 Roll Skia from a34882309d04 to c3c31be8729b (1 revision) (flutter/engine#37358) (flutter/flutter#114765)
dependentPlaceholders.addAll(pluralPartHelper.dependentPlaceholders); | ||
} else { | ||
logger.printWarning(''' | ||
The plural part specified below is overrided by a later plural part. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "overrided" is a typo? Shouldn't it be "overridden"?
* cef4c2a ICU Message Syntax Parser (flutter/flutter#112390) * 07d3a64 0886c7d0b Narrow the scope of the Windows Android arm hack (flutter/engine#37125) (flutter/flutter#114751) * cf0cd06 Mark new_gallery__transition_perf as non-flaky (flutter/flutter#114694) * 5bc50c1 Fix macOS migration nothing-to-upgrade test (flutter/flutter#114703) * b1509ed 36cfa9e68 Apply the Windows friendly path solution in remaining spots (flutter/engine#37344) (flutter/flutter#114759) * b45e628 b8218eacc Roll Fuchsia Mac SDK from Ua8Jtf8Zka9uxIVdl... to sNXsQVxntMX8f42LE... (flutter/engine#37352) (flutter/flutter#114760) * 5ea5a53 6f3018a72 Roll Skia from a34882309d04 to c3c31be8729b (1 revision) (flutter/engine#37358) (flutter/flutter#114765)
* cef4c2a ICU Message Syntax Parser (flutter/flutter#112390) * 07d3a64 0886c7d0b Narrow the scope of the Windows Android arm hack (flutter/engine#37125) (flutter/flutter#114751) * cf0cd06 Mark new_gallery__transition_perf as non-flaky (flutter/flutter#114694) * 5bc50c1 Fix macOS migration nothing-to-upgrade test (flutter/flutter#114703) * b1509ed 36cfa9e68 Apply the Windows friendly path solution in remaining spots (flutter/engine#37344) (flutter/flutter#114759) * b45e628 b8218eacc Roll Fuchsia Mac SDK from Ua8Jtf8Zka9uxIVdl... to sNXsQVxntMX8f42LE... (flutter/engine#37352) (flutter/flutter#114760) * 5ea5a53 6f3018a72 Roll Skia from a34882309d04 to c3c31be8729b (1 revision) (flutter/engine#37358) (flutter/flutter#114765)
Any idea when this will be brought to stable or beta? We are currently running into some issues that this pull fixes for us. |
I believe it's already in beta: https://github.com/flutter/flutter/tree/beta/packages/flutter_tools/lib/src/localizations |
This reverts commit cef4c2a.
* 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
* 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
* cef4c2a ICU Message Syntax Parser (flutter/flutter#112390) * 07d3a64 0886c7d0b Narrow the scope of the Windows Android arm hack (flutter/engine#37125) (flutter/flutter#114751) * cf0cd06 Mark new_gallery__transition_perf as non-flaky (flutter/flutter#114694) * 5bc50c1 Fix macOS migration nothing-to-upgrade test (flutter/flutter#114703) * b1509ed 36cfa9e68 Apply the Windows friendly path solution in remaining spots (flutter/engine#37344) (flutter/flutter#114759) * b45e628 b8218eacc Roll Fuchsia Mac SDK from Ua8Jtf8Zka9uxIVdl... to sNXsQVxntMX8f42LE... (flutter/engine#37352) (flutter/flutter#114760) * 5ea5a53 6f3018a72 Roll Skia from a34882309d04 to c3c31be8729b (1 revision) (flutter/engine#37358) (flutter/flutter#114765)
Description
This PR implements the new parser for ICU message format. The current implementation involves doing a lot of hacky RegEx string replacements (i.e. replace placeholders to use a different syntax, RegEx match plurals and selects) and making assumptions about the messages (e.g. the original implementation assumes that messages may have at most one plural). This has a lot of limitations which include
We provide a new approach. The high level idea is to divide up the whole process into three steps:
message_parser.dart:Parser.lexIntoTokens
.message_parser.dart:Parser.parseIntoTree
.gen_l10n_templates.dart
and implemented ingen_l10n.dart:LocalizationsGenerator._generateMethod
.Another feature of separating the parsing and code generation process is better error messages. For example, if there is an unexpected token, then we should see the error message
Design Doc
Link to design doc.
Testing
message_parser_test.dart
file which includes tests for up to parsing.generate_localizations_test.dart
succeed.gen_l10n_test.dart
.Follow up work
There's a little more work left, which is a bit outside the scope of this PR. Essentially, the placeholder type inference for placeholders for plurals and selects were done by assuming that there is a unique count placeholder per message. Since we no longer make this assumption, we need to refactor the
Message
class to include all messages, parse all of these messages at the same time, then attempt to infer the correct type for each placeholder. This PR doesn't modify the old placeholder type inference logic, so it may not work properly if there are multiple plurals.We're also setting aside escaping for a separate PR but that's lower priority than above.
Related Issue
Fixes #86906. Fixes #113495.
Future Work