Skip to content
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

Is there a way to control capitalization when using `DATETIME`? #299

Open
elisehein opened this issue Sep 30, 2019 · 2 comments
Open

Is there a way to control capitalization when using `DATETIME`? #299

elisehein opened this issue Sep 30, 2019 · 2 comments
Labels

Comments

@elisehein
Copy link

@elisehein elisehein commented Sep 30, 2019

We use the DATETIME filter in one of our Fluent strings to format an ISO date string to just output the weekday name (Monday): {DATETIME($isoString, weekday: "long")}

Is there a way to specify whether the weekday name should be capitalized or not, regardless of the locale's capitalization rules?

In the English case, the weekday occurs in the middle of the sentence, and anyway it's not of any consequence because weekdays are capitalized in English. In Hungarian, however, the weekday ends up being the first word in the string. Because weekdays are not capitalized in Hungarian, we end up with a sentence that isn't capitalized.

Is this something we can address using Fluent alone, or should we be fixing it somewhere else in the stack?

@Pike Pike added the resolver label Sep 30, 2019
@Pike
Copy link
Contributor

@Pike Pike commented Sep 30, 2019

@zbraniecki, any idea?

I've done a tad of research, and found http://cldr.unicode.org/translation/capitalization and http://cldr.unicode.org/development/development-process/design-proposals/grammar-and-capitalization-for-date-time-elements. Which implies that anything on the CLDR/ICU front would return lower-case strings for Hungarian, even in standalone.

Now, I don't know if contextTransforms are exposed in any way. And in Fluent, I think it's hard to do so out of the box.

I wonder if the least horrible solution would be to expose a CAPITALIZE function, and have languages that need it wrap the DATETIME call like so: `{CAPITALIZE(DATETIME($isoString, weekday: "long"))}

@zbraniecki
Copy link
Contributor

@zbraniecki zbraniecki commented Oct 2, 2019

So, in ECMA402 we're introducing Intl.DisplayNames which is an API better suited for cases like retrieving a weekday.

With that in mind, we're talking about adding displayContext to it - tc39/ecma402#355

This will take some time to standardize and in the meantime, we do not provide a good intl coverage for capitalization rules.
You can write your own, as Pike suggested, but it may require a bit more trickery, since by default we just return data from CLDR for context standalone which may or may not be capitalized, so you need to adapt for both:

{ CAPITALIZATION(DATETIME($isoString, weekday: "long"), "lower") }
{ CAPITALIZATION(DATETIME($isoString, weekday: "long"), "title") }

etc.

@stasm stasm added this to To do in Resolver 1.0 Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Resolver 1.0
  
To do
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.