-
I have a bunch of units, defined as follows: units-unit-liter =
.symbol = L
.name = { $count ->
[one] liter
*[other] liters
}
.symbol-value = {$count} {units-unit-liter.symbol}
.name-value = {$count} {units-unit-liter.name} I find it tedious that I have to spell out Why might one want this? Each time I add a new unit, I have to remember to update not just the name of the translation , but also its attribute usages, if I accidentally forget one, I could end up with bad translations like units-unit-kilogram =
.symbol = kg
.name = { $count ->
[one] kilogram
*[other] kilograms
}
.symbol-value = {$count} {units-unit-kilogram.symbol}
.name-value = {$count} {units-unit-liter.name} and oops, suddenly it says "3 liters" when I translate using the Footnotes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
To answer the first question: No, there is no such shorthand. As for whether there should be, that rather depends on whether it's needed. Regarding your example, I have two questions:
|
Beta Was this translation helpful? Give feedback.
It does sound like you might be trying to put more logic into Fluent than most of us usually do. Maybe go with custom functions instead?
Accessing the data depends on the environment. I'd recommend looking for CLDR/ICU bindings.
If you're in the browser, some but not all of the CLDR is exposed via Intl. Unfortunately, you cannot get unit names without an amount from
Intl.DisplayNames
(though for other things, it is your friend), but you can grab them viaIntl.NumberFormat
(which is also what fluent.js uses).formatToParts
is your friend if you want to grab only part of the output.