使用import不能用
import i18n from "LanguageData";
使用import不能用
import i18n from "LanguageData";
i18n包括LabelLocalized的typescript改写版:
https://github.com/toddlxt/Creator-TypeScript-Boilerplate/tree/master/typescript/libs/i18n
注意如果要用LabelLocalized.ts,把里面的@CCComponent和@CCProperty换成现在1.5的@ccclass和@property的写法。另外TS中import最好写全路径,以便IDE找到对应文件,获得代码提示。
感谢,感谢
大神,如果不想改写js代码,只添加*.d.ts文件能支持吗?
在2.0新版本编辑器你的git工程会报错,无法使用
自问自答了,是可以通过新增 LanguageData.d.ts 来实现的
LanguageData.d.ts 文件
declare interface ITranslateOption { [key: string]: string|number;}
declare module LanguageData { function init(language : string): void; function t (key : string, opt? : ITranslateOption) : string; function updateSceneRenderers(): void;}
export = LanguageData;
调用文件 assets\script\component\ChangeLange.ts
import * as i18n from “…/…/…/packages/i18n/runtime-scripts/LanguageData”;
导入路径是相对的,所以目录深度可能不一样
开始就时弄错了相对目录深度导致一直找不到