0 Star 1 Fork 0

Eyelly Wu/i18n-pro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 5.80 KB
一键复制 编辑 原始数据 按行查看 历史
Eyelly Wu 提交于 2023-06-07 22:56 . chore: release 2.0.0

logo

English | 简体中文

Lightweight, simple, flexible, automatic translation internationalization tool for JavaScript

npm-version npm-download

github-stars last-commit github-issues codecov

demo

Table of Contents

Vision
Features
Live Demo
Principle
Help Document
License

Vision

To make internationalization easy and enjoyable 😄💪🏻

Features

  • lightweightbundlesize
  • simple:Low learning cost and easy to use
  • flexible:Support Variable Interpolation , as well as unique type tag and formatting callbacks (numbers, currency, dates, times, plurals)
  • automatic-translation:One command can automatically extract text and translate it to generate language packs
    • Support incremental translation mode:Only translate new text and intelligently remove unused text
    • Support multi -translation platform:Google x、OpenAI、Google、Microsoft、Tencent、Alibaba Cloud、Youdao、Baidu(In addition to Google x, other platforms need to register an account by themselves)
    • Support multiple translation logs:The output of a variety of types of translation logs, which is convenient for tracking and positioning translation issues
  • keyless:No need to manually define key, Translation Text is key

Live Demo

Principle

Taking Translation Text as key is the key to all the functions of the library. If you have any questions about this, Please see

The library is mainly composed of two parts

  • Command Line Tool
  • Function API

Command Line Tool:Parse the text that needs to be translated based on specified rules (regular expressions), translate the text to the specified target language through a translation platform, and finally generate language pack files

An example of parsing text using Matching Rules is as follows:

/** Normal string */

t('hello world')
t("hello world")
t(`hello world`)


/** Support Variable Interpolation */

t('hello {0}', 'developer friends'),
t('This is {0}, welcome to {1}. If you think {2}, please give {3} your support', ' `i18n-pro` ', 'use', `it's helpful for you`, ' ⭐️ ')


/** Interpolation Variable type tag need to be used with corresponding formatting callbacks */

// Number Type
t('The number of users has reached {n0}', 100000000)

// Currency Type
t('The selling price is {c0}', 14999)

// Date Type
t(`Today's date is {d0}`, new Date())

// Time Type
t('Current time: {t0}', new Date())

// Plural Type
t('I have {p0 apple}, {p1 banana} and {p2 pear}', 5, 4, 3) 

Function API:Connect the international language package into the project, consisting of initI18n , t , setI18n and withI18n

  • initI18n:Used to initialize the fixed configuration, and finally return the objects containing the following 3 APIs
  • t:It is used for wrapping Translation Text to achieve internationalization, and it is also used as a logo of the command line to match Translation Text rules
  • setI18n:Set language and language package
  • withI18n:It is applicable to the server. Each interface response needs to be internationalized

Therefore, Command Line Tool and Function API work better together. It is precisely because of this structural design that i18n-pro library can be easily integrated into any JavaScript project

Help Document

License

MIT

Copyright (c) 2022-present Eyelly Wu

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/eyelly/i18n-pro.git
git@gitee.com:eyelly/i18n-pro.git
eyelly
i18n-pro
i18n-pro
main

搜索帮助

Cb406eda 1850385 E526c682 1850385