-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat(intl): ignore script subtags when canonicalizing locale strings #948
feat(intl): ignore script subtags when canonicalizing locale strings #948
Conversation
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.
A bit of a hacky solution, but the existing code is also quite hacky, so that's fine :)
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. Coverage ✔️
This check for test coverage is informational (issues shown here will not fail the PR).
API leaks
|
Package | Leaked API symbols |
---|---|
intl | StringStack DateBuilder |
This check can be disabled by tagging the PR with skip-leaking-check
.
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files |
---|
no missing headers |
All source files should start with a license header.
45d5ff8
to
6ea1b12
Compare
This fails internal Google testing, which looks like this:
Which made me think about what It doesn't help that i18n/pkgs/intl/lib/src/intl_helpers.dart Line 188 in c6b911b
canonicalizedLocale but before shortLocale (which should be renamed to something like languageOnly ), which returns what you implemented. This way, we would first try zh_Hant_CN , then zh_CN , then zh , etc. when running NumberFormat.currency .
What do you think? |
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.
As detailed in comment
I would also add something like test('Use script', () {
expect(
NumberFormat.currency(locale: 'zh_Hant_TW').format(12),
'TWD12.00',
);
expect(
NumberFormat.currency(locale: 'zh_Hant_CN').format(12),
'CNY12.00',
);
}); to the tests. |
Locale strings with a script such as `zh-Hans-CN` are incorrectly canonicalized as `zh` instead of `zh-CN`. Update the `verifiedLocale` function to look for a script subtag and ignore it if found.
6ea1b12
to
88ab7a8
Compare
Thank you for your patience, I couldn't get back to this sooner.
Sounds good to me, even though there is no script specific data for numbers nor dates as far as I know, we should still try looking them up in case they appear in the future. Implemented your suggestions and modified tests, let me know if I should change anything else. |
Locale strings with a script such as
zh-Hans-CN
are incorrectly canonicalized aszh
instead ofzh-CN
. Update thecanonicalizedLocale
function to look for a script subtag and ignore it if found.Closes: #945
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.