I18nLabel.ts 874 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Config from "../Config";
  2. import { gameMethod } from "../common/gameMethod";
  3. import { Lang } from "../data/const/TypeConst";
  4. import { I18n } from "./I18nUtil";
  5. import { uiCommon } from "./UICommon";
  6. const { ccclass, property, menu } = cc._decorator;
  7. @ccclass
  8. @menu("I18N/I18nLabel")
  9. export default class I18nLabel extends cc.Component {
  10. @property(cc.String)
  11. key: string = "";
  12. @property(cc.Boolean)//是否是表内文本
  13. isLang: boolean = false;
  14. @property(cc.Boolean)//是否修正字体布局
  15. fix:boolean = false
  16. @property([cc.String])
  17. args: string[] = [];
  18. setI18nLabel() {
  19. //优先key值
  20. let str = "";
  21. if (this.isLang) {
  22. str = I18n.getI18nLang(this.key, ...this.args);
  23. } else str = I18n.getI18nText(this.key, ...this.args);
  24. uiCommon.setLabel(this.node, this.fix ? uiCommon.fixName(str) : str);
  25. }
  26. onLoad() {
  27. this.setI18nLabel();
  28. }
  29. }