Intl.NumberFormat() 的单位参数无效(伏特、焦耳...)
Invalid unit argument for Intl.NumberFormat() with electric units (volt, joule...)
我正在尝试本地化我的 Web 应用程序,但我无法使 Intl.NumberFormat 使用电气单位(安培、欧姆、伏特、焦耳...)。
在documentation, they provide some examples and the list of units available.
虽然我无法让它与电动装置一起工作:
// Working
console.log(new Intl.NumberFormat('fr', { style: 'unit', unit: 'second' }).format(1000));
// Failing with Invalid unit argument for Intl.NumberFormat() 'volt'
console.log(new Intl.NumberFormat('fr', { style: 'unit', unit: 'volt' }).format(1000));
有人知道为什么吗?
A subset of units from the full list was selected for use in ECMAScript.
Simple Unit
-----------
acre
bit
byte
celsius
centimeter
day
degree
fahrenheit
fluid-ounce
foot
gallon
gigabit
gigabyte
gram
hectare
hour
inch
kilobit
kilobyte
kilogram
kilometer
liter
megabit
megabyte
meter
mile
mile-scandinavian
milliliter
millimeter
millisecond
minute
month
ounce
percent
petabyte
pound
second
stone
terabit
terabyte
week
yard
year
Pairs of simple units can be concatenated with "-per-" to make a compound unit. There is no default value; if the style is "unit", the unit property must be provided.
很酷:兆字节每秒 变成法语 mégaoctets par seconde
console.log(
new Intl.NumberFormat('fr',
{ style: 'unit', unit: 'megabyte-per-second', 'unitDisplay': 'long' }
).format(1000)
);
我正在尝试本地化我的 Web 应用程序,但我无法使 Intl.NumberFormat 使用电气单位(安培、欧姆、伏特、焦耳...)。
在documentation, they provide some examples and the list of units available.
虽然我无法让它与电动装置一起工作:
// Working
console.log(new Intl.NumberFormat('fr', { style: 'unit', unit: 'second' }).format(1000));
// Failing with Invalid unit argument for Intl.NumberFormat() 'volt'
console.log(new Intl.NumberFormat('fr', { style: 'unit', unit: 'volt' }).format(1000));
有人知道为什么吗?
A subset of units from the full list was selected for use in ECMAScript.
Simple Unit
-----------
acre
bit
byte
celsius
centimeter
day
degree
fahrenheit
fluid-ounce
foot
gallon
gigabit
gigabyte
gram
hectare
hour
inch
kilobit
kilobyte
kilogram
kilometer
liter
megabit
megabyte
meter
mile
mile-scandinavian
milliliter
millimeter
millisecond
minute
month
ounce
percent
petabyte
pound
second
stone
terabit
terabyte
week
yard
year
Pairs of simple units can be concatenated with "-per-" to make a compound unit. There is no default value; if the style is "unit", the unit property must be provided.
很酷:兆字节每秒 变成法语 mégaoctets par seconde
console.log(
new Intl.NumberFormat('fr',
{ style: 'unit', unit: 'megabyte-per-second', 'unitDisplay': 'long' }
).format(1000)
);