mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 05:11:20 -08:00
- Created a new documentation file for the danmuku plugin with code examples. - Added comprehensive i18n setup instructions, including default language settings, language imports, and examples for adding and modifying languages. - Updated the structure and content of the i18n documentation to enhance clarity and usability.
102 lines
2.1 KiB
Markdown
102 lines
2.1 KiB
Markdown
# 语言设置
|
|
|
|
::: danger
|
|
|
|
鉴于捆绑的多国语言越来越多, 从 `5.1.0` 版本开始, `artplayer.js` 核心代码除了包含 `简体中文` 和 `英文` 外, 不再捆绑其它多国语言, 需要自行导入需要的语言。
|
|
|
|
:::
|
|
|
|
:::warning
|
|
|
|
当无法匹配到语言时, 会默认显示英文, i18n 写法参考: [artplayer/types/i18n.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/i18n.d.ts)
|
|
|
|
:::
|
|
|
|
## 默认语言
|
|
|
|
默认语言有: `en`, `zh-cn`, 无需手动导入
|
|
|
|
```js{4}
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
lang: 'zh-cn', // or 'en'
|
|
});
|
|
```
|
|
|
|
## 导入语言
|
|
|
|
打包前的语言文件存放于: `artplayer/src/i18n/*.js`, 欢迎来添加你的语言
|
|
|
|
打包后的语言文件存放于: `artplayer/dist/i18n/*.js`
|
|
|
|
::: code-group
|
|
|
|
```js [import]
|
|
import id from 'artplayer/i18n/id';
|
|
import zhTw from 'artplayer/i18n/zh-tw';
|
|
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
i18n: {
|
|
id: id,
|
|
'zh-tw': zhTw,
|
|
},
|
|
lang: 'zh-tw',
|
|
});
|
|
```
|
|
|
|
```js [script]
|
|
<script src="artplayer/dist/i18n/id.js"></script>
|
|
<script src="artplayer/dist/i18n/zh-tw.js"></script>
|
|
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
i18n: {
|
|
id: window['artplayer-i18n-id'],
|
|
'zh-tw': window['artplayer-i18n-zh-tw'],
|
|
},
|
|
lang: 'zh-tw',
|
|
});
|
|
```
|
|
|
|
:::
|
|
|
|
## 新增语言
|
|
|
|
```js{4-9}
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
lang: 'your-lang',
|
|
i18n: {
|
|
'your-lang': {
|
|
Play: 'Your Play'
|
|
},
|
|
},
|
|
});
|
|
```
|
|
|
|
## 修改语言
|
|
|
|
```js
|
|
import zhTw from 'artplayer/i18n/zh-tw';
|
|
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
i18n: {
|
|
// Change the default language
|
|
'zh-cn': {
|
|
Play: 'Your Play'
|
|
},
|
|
// Change the imported language
|
|
'zh-tw': {
|
|
...zhTw,
|
|
Play: 'Your Play'
|
|
},
|
|
},
|
|
});
|
|
``` |