import { resources } from "cc";
const win = window as any;
export class LanguageManager {
	// 当前语言
	public static currentLanguage: string = 'en';

	// 存储语言资源
	private static languageData: any = {};

	// 加载语言文件
	public static loadLanguage(language: string): void {
		this.currentLanguage = language;
		this.languageData = win.languages[language]
	}

	// 获取文本内容
	public static getText(key: string): string {
		const win: any = window;

		if (!win.languages) {
			return key;
		}
		const searcher = key.split('.');

		let data = this.languageData;
		for (let i = 0; i < searcher.length; i++) {
			data = data[searcher[i]];
			if (!data) {
				return '';
			}
		}
		return data || '';
	}

	// 切换语言
	public static switchLanguage(language: string): void {
		this.loadLanguage(language);
	}
}
