🚧 ICU-23424 Initial implementation of Builder::setFormattingLocale()#4021
🚧 ICU-23424 Initial implementation of Builder::setFormattingLocale()#4021srl295 wants to merge 1 commit into
Conversation
| if (errorCode.errIfFailureAndReset("formatToString")) { | ||
| return; | ||
| } | ||
| UnicodeString expectedResult(u"PASS 13 @ 7/4/76"); |
There was a problem hiding this comment.
This test will FAIL on the existing code if set to the "en" locale (because it won't get the Polish plural buckets).
And the date format will be wrong (will be in Polish) if the formatting locale wasn't set to "en". 4.07.1776
| // Ignored if `setPattern()` wasn't called | ||
| StaticErrors* errors; | ||
| Locale locale; | ||
| Locale formattingLocale; |
| /** | ||
| * Sets the locale used by formatter factories (:number, :date, | ||
| * etc.) for rendering output. Selector factories (plural rules) | ||
| * continue to use the locale set via setLocale(). |
There was a problem hiding this comment.
As of #3536 there are no factories anymore and formatters and selectors aren't distinguished, so I think this comment needs updating? Perhaps it just applies to built-in functions?
There was a problem hiding this comment.
I think you're right, this was from pre-3536
| // The locale set by setLocale() | ||
| Locale locale; | ||
| // The locale set by setformattinglocale() | ||
| Locale formattingLocale; |
| * @internal ICU 79 technology preview | ||
| * @deprecated This API is for technology preview only. | ||
| */ | ||
| U_I18N_API const Locale& getFormattingLocale() { return formattingLocale; } |
There was a problem hiding this comment.
I find it confusing to refer to the two locales as "locale" and "formatting locale" -- perhaps rename "locale" to indicate what it does in contrast with the formatting locale?
There was a problem hiding this comment.
OK. Will need to address Mihai's comment also.
There was a problem hiding this comment.
perhaps selectionLocale and formattingLocale ?
|
I've been thinking about this in the last few days. This works for the formatters and plural selectors in MF1, that we know relatively well. But in MF2 the placeholders are not necessary formatters, and the selectors can be anything. And for example the placeholders can be used for grammar agreement (we have a prototype). And the locale for that should be the language of the message, so TLDR: I think this instrument is too blunt. |
OK,
OK. Do you have suggestions on how to (shall we say) slice it up to be more precise? The best parallel to existing APIs i can think of is something like |
Yes, but I think that the best option is still a locale in the placeholder / selector itself, in the message. There is no ideal option, really. This should be discussed in a TC design proposal, all options, with pros and cons. For example if I say "yes, users want Also note that the current function overrides are not global. So you have to do that every time you format a message. So in the end you the end up with a wrapper instead using Changing messages is a lot easier. It can be done algorithmically, at build time, on the resource bundles (whatever that is). Changing messages to use Taking allowing a locale on all functions ( There was a reason why we had that as a proposal... I think we should list all the options, with pros and cons, and present to the TC. |
|
Hi, thanks @mihnita for the constructive feedback!
Actually, you can override the format for a specific placeholder. (In MF1)
Yes, as I noted I will get a design proposal to the TC. I'm collecting unofficial feedback to start.
Okay, but I wasn't asking to only override in some locales. But if I did, I could do the following in user code: And still only the single API is needed.
OK- are you saying that you support that overriding?I had thought that was exactly what you disagreed with in MFWG. Maybe I am misunderstanding and you are just saying the above for the sake of argument.
But to what, though? Not to
Are the builders cloneable? If so then a builder that's all set except for the message, could be used. It does requiring knowing which :x needs to change to :custom_x just as knowing which :y needs to change to :y :locale=en
There's the rub.. And I know it was because of ICU4X's optimization angle that it was removed. Here's an idea:
Sure. Would you be able to help expand on the use cases you have beyond this 'blunt instrument'? One of the pros of this PR as written is that it is simple for the client in this use case.
Hm - no rush here, this is a draft PR that doesn't even have an API proposal out. This PR does, however, represent just how we solved the issue, which is time honored way to start a request. I have confidence that the TC is not overly swayed by the presence of an implementation. To @catamorphism point the present implementation doesn't explicitly list what the new function applies to. |
Draft… API proposal, etc forthcoming.
plus tests
Adds
Builder& Builder::setFormattingLocale(const Locale& locale);as tech previewPropagate the formatting locale (equal to the regular locale normally)
Checklist