Git Product home page Git Product logo

hx-i18n-helper's Introduction

hx-i18n-helper

HBuilderX开发国际化辅助工具,解放无聊的手动操作

  • 快速初始化
  • 快速同步

使用

const {i18nHelper} = require("../dist/index.js")

const helper = i18nHelper()
// 初始化所需要的nls文件,默认nls文件将自动检测处理(创建)
helper.initLocales(["ja", "fr"])
// 此过程会从package.json里提取部分可能存在i18n应用的key进行拍平处理,生成默认的nls文件
// 如果后续package.json有变动的i18n相关的键,重新调用此函数以更新nls文件内容
helper.generateNls()

// 从默认nls文件向其他nls文件同步,同步会跳过已经配置过的内容
// (比如package.nls.en.js中的description字段翻译过了,那么在同步时会跳过该字段)
helper.syncLocales()

// 生成一个简单的键值对辅助文件,对于js代码内需要使用i18n的地方进行智能推断辅助
helper.generateJsHelper()
// 支持自定义输出文件名
// 如果觉得在js代码里使用key太长了可以传第二个参数启用简化
// helper.generateJsHelper("helper.js", true)

// 自动判断locale并从i18n文件中获取内容,主要是在js代码中辅助使用
helper.i18nGet("key", "这是默认值123")
// 批量获取i18n内容,返回Object
helper.i18nGets(["key1", "key2"])
// 也可以配置默认值
helper.i18nGets(["key1", ["key2", "这是默认值123"]])

使用实例

hx-i18n-helper's People

Contributors

noah227 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.