i18n
Hint
3.0.0-alpha.41 and later versions available
All xgplayer plugins provide four languages, namely Simplified Chinese
, Traditional Chinese
, English
and Japanese
, and provide users with the expansion ability to add new language packs and default languages. Chinese and English are packaged by default, and Japanese and traditional Chinese need to be imported and added from the es directory
Capabilities:
- Custom language pack
- Extend/Modify existing language pack
- Switch all the builtin plugin languages of the initialized instance with one button
- One-button switch, and provide static interface
I18N.use(Object)
Add a new language pack
The data structure of the language pack is as follows. For detailed definitions, refer to Preset language list
{
LANG: 'custom', // Lang to be defined
TEXT: {...} // Lang list
}
demo
/**
* UMD package:
* const I18N = window.Player.I18N
*/
import Player, { I18N } from 'xgplayer'
const CUSTOM_LANG = {
LANG: 'custom', // Lang to be defined
// Lang list
TEXT: {
HAVE_NOTHING:'没有关于音频/视频是否就绪的信息',
...
}
}
// use custom lang package
I18N.use(CUSTOM_LANG)
// Initialize default custom lang
player = new Player({
lang: 'custom'
...
})
// Switch lang after created a player instance
player.lang = 'custom'
/**
* Get the list of currently integrated lang packs
* {
* en: {...},
* zh: {...}
* }
*/
I18N.lang
/**
* Get the list of languages currently integrated
* ["en", "zh-cn"]
*/
I18N.langKeys
I18N.extend(Object)
Extend the configuration item for language package
import Player, {I18N} from 'xgplayer'
const CUSTOM_LANG = [{
LANG: 'zh',
TEXT: '这是扩展语言项目'
}, {
LANG: 'en',
TEXT: 'this is an language item'
}]
// Extended Language Pack
I18N.extend(CUSTOM_LANG)
player.lang
import Player from 'xgplayer'
const player1 = new Player({
lang: 'zh',
...
})
// Switch lang after created a player instance
player1.lang = 'en'
Predefined language packs
At present, only Simplified Chinese and English are predefined language packs by default. If you want to use the predefined language packs Japanese and Traditional Chinese, you can reference them from the es/lang directory, us as the following:
import Player, {I18N} from 'xgplayer'
// jp
import JP from 'xgplayer/es/lang/jp'
// zh-hk
import ZH_HK from 'xgplayer/es/lang/zh-hk'
// use custom lang pack
I18N.use(JP)
I18N.use(ZH_HK)
Lang Defined[Chinese/English]
key | zh | en |
---|---|---|
HAVE_NOTHING | 没有关于音频/视频是否就绪的信息 | There is no information on whether audio/video is ready |
HAVE_METADATA | 音频/视频的元数据已就绪 | Audio/video metadata is ready |
HAVE_CURRENT_DATA | 关于当前播放位置的数据是可用的,但没有足够的数据来播放下一帧/毫秒 | Data about the current play location is available, but there is not enough data to play the next frame/millisecond |
HAVE_FUTURE_DATA | 当前及至少下一帧的数据是可用的 | Current and at least one frame of data is available |
HAVE_ENOUGH_DATA | 可用数据足以开始播放 | The available data is sufficient to start playing |
NETWORK_EMPTY | 音频/视频尚未初始化 | Audio/video has not been initialized |
NETWORK_IDLE | 音频/视频是活动的且已选取资源,但并未使用网络 | Audio/video is active and has been selected for resources, but no network is used |
NETWORK_LOADING | 浏览器正在下载数据 | The browser is downloading the data |
NETWORK_NO_SOURCE | 未找到音频/视频来源 | No audio/video source was found |
MEDIA_ERR_ABORTED | 取回过程被用户中止 | The fetch process is aborted by the user |
MEDIA_ERR_NETWORK | 当下载时发生错误 | An error occurred while downloading |
MEDIA_ERR_DECODE | 当解码时发生错误 | An error occurred while decoding |
MEDIA_ERR_SRC_NOT_SUPPORTED | 不支持的音频/视频格式 | Audio/video is not supported |
REPLAY | 重播 | Replay |
ERROR | 网络连接似乎出现了问题 | Network is offline |
PLAY_TIPS | 播放 | Play |
PAUSE_TIPS | 暂停 | Pause |
PLAYNEXT_TIPS | 下一集 | Play next |
DOWNLOAD_TIPS | 下载 | Download |
ROTATE_TIPS | 旋转 | Rotate |
RELOAD_TIPS | 重新载入 | Reload |
FULLSCREEN_TIPS | 进入全屏 | Fullscreen |
EXITFULLSCREEN_TIPS | 退出全屏 | Exit fullscreen |
CSSFULLSCREEN_TIPS | 进入样式全屏 | Cssfullscreen |
EXITCSSFULLSCREEN_TIPS | 退出样式全屏 | Exit cssfullscreen |
TEXTTRACK | 字幕 | Caption |
PIP | 画中画 | PIP |
SCREENSHOT | 截图 | Screenshot |
LIVE | 正在直播 | LIVE |
OFF | 关闭 | Off |
OPEN | 开启 | Open |
MINI_DRAG | 点击按住可拖动视频 | Click and hold to drag |
MINISCREEN | 小屏幕 | Miniscreen |
REFRESH_TIPS | 请试试 | Please Try |
REFRESH | 刷新 | Refresh |