fluent
fluent copied to clipboard
Is there a way to control capitalization when using `DATETIME`?
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?
@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"))}
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 - https://github.com/tc39/ecma402/issues/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.