You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.3 KiB
80 lines
2.3 KiB
import { sys, resources, TTFFont, BitmapFont, Font, assetManager } from "cc";
|
|
import { Global } from "./Global";
|
|
import { EBundleName } from "./const/GameEnum";
|
|
|
|
export default class Language {
|
|
private constructor() { };
|
|
private static _ins: Language = null;
|
|
static get Ins(): Language {
|
|
if (!this._ins) { this._ins = new Language(); }
|
|
return this._ins;
|
|
}
|
|
|
|
static getValue(key, org: string = "", to: string = ""): string {
|
|
return this.Ins.LangugeValue(key, org, to);
|
|
}
|
|
|
|
static getValueSound(key) {
|
|
return this.Ins.LangugeValueSound(key);
|
|
}
|
|
|
|
private language: string = '';
|
|
private mFont: Font = null;
|
|
InitLanguage(callBack?: Function) {
|
|
this.language = Global.LocalStorage.getItem("game_language");
|
|
this.language = this.language ? this.language : sys.language;
|
|
this.loadFont(callBack);
|
|
}
|
|
|
|
/** 加载字体 */
|
|
private loadFont(callBack?: Function) {
|
|
callBack && callBack();
|
|
// assetManager.loadBundle(EBundleName.Presets, () => {
|
|
// assetManager.getBundle(EBundleName.Presets).load(this.getFontName(), Font, (err, font: Font) => {
|
|
// if (!err) {
|
|
// this.mFont = font;
|
|
// }
|
|
// callBack && callBack();
|
|
// })
|
|
// })
|
|
}
|
|
|
|
/** 获取当前的语言 */
|
|
private getLanguge(): string {
|
|
//sys.language;
|
|
return this.language;
|
|
}
|
|
|
|
/** 获取多语言配置文件 */
|
|
private getLangugeFile() {
|
|
|
|
return 'language/' + this.getLanguge() + '.json';
|
|
}
|
|
|
|
/** 获取当前的font字体 */
|
|
private getFontName() {
|
|
//'Font/mimi'//
|
|
return 'Font/zh';
|
|
}
|
|
|
|
private getFont() {
|
|
return this.mFont;
|
|
}
|
|
/** 获取多语言 */
|
|
private LangugeValue(key, org: string = "", to: string = ""): string {
|
|
if (!Global.CsvMgr.language_csv[key]) {
|
|
return key;
|
|
}
|
|
const value: string = Global.CsvMgr.language_csv[key][this.getLanguge()];
|
|
if (!value || !value.length) { return key };
|
|
return value.replace(org, to);
|
|
}
|
|
private LangugeValueSound(key) {
|
|
if (Global.CsvMgr.language_csv[key]) {
|
|
return Global.CsvMgr.language_csv[key]["audioName"];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
window["Language"] = Language;
|