V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
KouShuiYu

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

  •  
  •   KouShuiYu ·
    ckvv · Mar 26, 2021 · 1613 views
    This topic created in 1865 days ago, the information mentioned may be changed or developed.

    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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   752 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:58 · PVG 04:58 · LAX 13:58 · JFK 16:58
    ♥ Do have faith in what you're doing.