# i18n.js
**Repository Path**: minus16/i18n.js
## Basic Information
- **Project Name**: i18n.js
- **Description**: JavaScript 国际化框架 i18n 不依赖其他框架
- **Primary Language**: JavaScript
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 11
- **Forks**: 0
- **Created**: 2018-07-03
- **Last Updated**: 2024-02-04
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# i18n.js
#### 项目介绍
原生JavaScript 国际化插件 i18n ,不依赖其他框架
#### 软件架构
软件架构说明
#### 安装教程
1. 引入框架
```javascript
```
2. 初始化框架
```javascript
// 文件路径 filePath + filePrefix + lang + fileSuffix + ".json"
i18n("[i18n]", {
defaultLang: 'cn', // 设置默认语言,
// lang:'cn', // 缺省时为 defaultLang 初始化时不建议设置
filePath: "./i18n/",// 路径
filePrefix: "i18n_",// 文件前缀
fileSuffix: "",
forever:true,// 默认为 true 保存当前语言,设置为 false 后,每次刷新都为cn
get: true,// 缺省为 false 。当需要在其他js文件中使用 i18n.get(key),获取语言时开启,参考 index.js
only: ['value', 'html', 'placeholder', 'title'], // 全局设置i18n-only,默认值:['value', 'html', 'placeholder', 'title']
callback: function() {
console.log("i18n is ready.");
}
});
```
3.
## 配置
#### defaultLang
```JS
defaultLang: defaultLang,
```
默认语言名称,插件会自动将 `filePrefix`+`defaultLang`+`fileSuffix` 拼接在一起作为语言文件文件名。
#### filePath
```JS
filePath: "/i18n/",
```
该参数指定了语言文件所在文件夹在项目中的位置。
#### filePrefix
```JS
filePrefix: "i18n_",
```
该参数指定了语言文件的命名的前缀。
#### fileSuffix
```JS
fileSuffix: "",
```
该参数指定了语言文件的命名的后缀。
#### callback
```javascript
callback:function(){
//do something
}
```
#### only (i18n-only)
默认会将HTML元素的'value', 'html', 'placeholder', 'title'一起进行翻译替换,如果您只需要替换其中一个,可以在HTML标签中声明 `i18nOnly` 属性。
```html
```
* i18n-only 支持html、value和其他非`i18n`开头的`attribute`
#### 参与贡献
1.
#### 码云特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
5. 码云官方提供的使用手册 [http://git.mydoc.io/](http://git.mydoc.io/)
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)