爱意满满的作品展示区。
KouShuiYu

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

  •  
  •   KouShuiYu ·
    ckvv · Mar 26, 2021 · 1777 views
    This topic created in 1942 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   ·   4601 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:01 · PVG 09:01 · LAX 18:01 · JFK 21:01
    ♥ Do have faith in what you're doing.