Open jamesking opened 5 years ago
This is one of the complex cases that we're only now slowly starting to play with (French has so many of them!).
One idea I can suggest is a builtin function that you can pass some string to and it computes a category for you.
Example:
on-weekday =
{ WEEKDAY_GENDER(DATETIME($date, weekday: "long")) ->
[masculine] no
[feminine] na
*[other] ne
} {DATETIME($date, weekday: "long")}
Would that solve your case?
I'm pretty sure that you'll hit a declension problem, too. That is, the dateformat function will produce "Wednesday" in a grammatical form that's OK for standalone, but not in the relative clause you're expecting. Think "at Wednesdiya"
I'd suggest to do 7 strings to localize.
Only if we had dynamic term references and you did a lot of stuff around weekdays, it'd make sense to create terms for weekdays, and have them have gender and grammatical forms for languages in need. That's #80, but not triaged or scheduled.
Thank you for the quick response!
@zbraniecki That function would certainly work for the particular instance we are trying to implement in Portuguese right now. Whether it scales to other use-cases is difficult to say.
@Pike #80 sounds really promising, and your suggestion to simply use 7 strings is appreciated. We might do that.
If we attempted this with a single string, however, this is the only that I can get working right now:
on-day =
{ $weekday-number ->
*[1] na {DATETIME($date, weekday: "long")}
[6] no {DATETIME($date, weekday: "long")}
[7] no {DATETIME($date, weekday: "long")}
}
Where $weekday-number
is a helper variable passed into Fluent. It is the weekday of $date
represented as an integer between 1 and 7. Monday = 1, Tuesday = 2 etc.
Its a bit hacky, but it seems to work.
I tried to derive a weekday-number from $date
directly, but Intl.DateTimeFormat
does not seem to have an option for that, so we would have to calculate that outside of Fluent and pass it in.
I also tried:
on-day =
{ DATETIME($date, weekday: "long") ->
*[segunda-feira] na {DATETIME($date, weekday: "long")}
[sábado] no {DATETIME($date, weekday: "long")}
[domingo] no {DATETIME($date, weekday: "long")}
}
This does not seem to work when I try it in the Playground:
á
in [sábado]
seems not to be valid syntax, according to the Playground.[mandag]
, [tirsdag]
etc), I still can't get that approach to work.I would not recommend the last approach. Intl data is not meant to be stable or consistent across implementations. Writing such code indicates an expectation that the string returned from Intl.DateTimeFormat will remain the same in all implementations and over time which may not be the case.
@zbraniecki Thank you for the heads-up
There's also the point that you can't enforce a localization to actually implement 7 weekdays in one string.
That's one of the corner stones of Fluent. Localizations are allowed to choose how complex their implementation of a string is. Like, one localization might choose to use "on Wednesdiya", the other might choose "soon".
You're applications intent OTH is to have a string per week day.
We wrote this down in https://github.com/projectfluent/fluent/wiki/Good-Practices-for-Developers#prefer-wet-over-dry, WET over DRY. Write Everything Twice (or seven times) over Don't Repeat Yourself.
@Pike thanks for the link. Always good to be reminded of those best practices.
… the other might choose "soon".
This is actually what we have decided for now. Keep things simple and remove the reference to the specific weekday in Portuguese.
In English we want to say something like
on Wednesday
(as in "See you on Wednesday!"), wherewednesday
is a generated by a datetime variable,$date
. This is easy to do in Fluent:In Portuguese, the preposition
on
is eitherno
orna
depending on the gender of the weekday. We are struggling to come up with a way of formatting this in Fluent. We were hoping something like this is possible.Is something like this possible in Fluent?
Is there a way of doing this?