V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
KouShuiYu
V2EX  ›  分享创造

最近在学 typescript,试着写了个非常迷你的 i18n 工具,百分百覆盖的单元测试,压缩后不到 1kb,

  •  
  •   KouShuiYu ·
    ckvv · 2021-03-26 19:01:38 +08:00 · 1242 次点击
    这是一个创建于 1187 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Example

    const i18n = new I18n({
      locale: 'zh',
      fallbackLocale: 'zh',
      messages: {
        zh: {
          hello: "你好 世界",
          say: {
            thanks: "{name} 谢谢"
          }
        },
        en: {
          hello: "hello world",
          say: {
            thanks: "thanks {name}"
          }
        }
      }
    });
    
    i18n.t('hello') // 你好 世界
    i18n.t('say.thanks', {name: 'xiaohong'}) // xiaohong 谢谢
    

    Demo

    Documentation

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5327 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:38 · PVG 14:38 · LAX 23:38 · JFK 02:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.