@bluecateng/l10n.macro
L10n宏报.
从旧版本升级? 见 移徙指南。 。 。 .
安装
npm i -D @bluecateng/l10n.macro babel-plugin-macros
使用量
Babel 配置
为了启用宏插件, 它应该添加到 Babel 配置中 .
plugins: [
"macros"
]
宏使用量
页:1
标记本地化的模板。 其他l10n宏可以在模板中被浅入巢.
import {t} from '@bluecateng/l10n.macro';
console.log(t`Hello world`);
const salute = (name) => t`Hello ${name}`;
选择
在指定的选项中根据值选择字符串 key。 。 。 .
键可以是字符串,数字,也可以是布尔.
选择列表必须包括"其他",如果其他选择没有匹配,则选择该列表.
import {select} from '@bluecateng/l10n.macro';
const statusText = (active) => select(active, {true: 'Active', other: 'Inactive'});
复数
在指定的选项中选择一个字符串,其基础是主文形式 key。 。 。 .
关键必须是数字.
选择列表必须包括"其他",如果其他选择没有匹配,则选择该列表.
选择键可以是数字,也可以是目标语言的复数关键词.
页:1.
import {plural} from '@bluecateng/l10n.macro';
const peopleCount = (count) =>
plural(count, {offset: 1, 0: 'nobody', 1: 'you', one: 'you and one other', other: 'you and # other'});
选择正文
在指定的选项中选择一个字符串,该字符串基于 key。 。 。 .
这个宏的论据必须遵循与下列规则相同的规则: plural 宏 .
import {selectOrdinal} from '@bluecateng/l10n.macro';
const place = (number) => selectOrdinal(number, {one: '#st', two: '#nd', few: '#rd', other: '#th'});
编号
使用当前区域规则格式化指定的编号.
第一个论点必须是数字.
第二个参数是可选的,如果指定必须是其中之一 'decimal' 或者说 'percent',默认值为 'decimal'。 。 。 .
import {t, number} from '@bluecateng/l10n.macro';
const interest = (value) => t`The interest is ${number(value, 'percent')}`;