-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Handling DateTime, Currency and Numbers in gen_l10n tool #47008
Comments
I updated the original proposal to have currencies be specified with the type "Number", since currencies are also formatted using the |
I believe that this issue can be closed, since all functionality in this proposal has been merged. |
Sanity check: is this most excellent functionality ready for use? Running the tool from the current master branch and looking at the generated
This means that the fallback message (see #48822) is always shown. An example would be: messages_en.arb: {
"responseDueBy": "The response is due by {time} on {day}.",
"@responseDueBy": {
"description": "Response due time",
"placeholders": {
"time": {
"description": "Time that the response is due",
"type": "DateTime",
"format": "Hm"
},
"day": {
"description": "Day that the response is due",
"type": "DateTime",
"format": "yMMMMEEEEd"
}
}
}
} messages_de.arb: {
"responseDueBy": "Die Antwort wird bis {time} am {day} erstellt.",
} The generated content in both ...
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function>{};
} |
@garry-jeromson - could you open a new issue and include a test case that demonstrates how the generated localizations class fails? |
@HansMuller Will do. :-) |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
It would be great to provide some support/convenience for handling DateTime, numbers and currencies in the gen_l10n tool. I've been working with @HansMuller on some of ideas:
DateTime handling
Pull requests:
Simple, non-plural messages - #47006
Plural messages - #47483
Description
Essentially handles DateTime through reading the "type" and "format" resource attributes for each placeholder. By defining the "type" as "DateTime" and providing a "format" string that corresponds to an existing DateFormat constructor, the tool will automatically generate code that formats the date or time for the developer.
It generates the following result:
Message in .arb file:
Resulting method:
This takes away complexity from the app developer from having to format dates for each locale themselves.
Currency
Pull requests
Fix positional vs named params, introduce Currency formatting - #48445
Description
Essentially handles currencies through intl.NumberFormat through reading the "type, "format", and optional attributes such as "decimalDigits" for resource attributes for each placeholder. The tool will automatically generate code that formats the date or time for the developer.
Message in .arb file:
Resulting method:
Numbers
Pull requests
Handles number formats for simple and plural messages - #47706
Description
Essentially handles numbers through intl.NumberFormat through reading the "type, "format", and optional attributes such as "decimalDigits" for resource attributes for each placeholder. The tool will automatically generate code that formats the date or time for the developer.
Message in .arb file:
Resulting method:
The text was updated successfully, but these errors were encountered: