540fe8707c3487a9e7d67cbac8436ed8bbbd2bfa.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. System.register(["__unresolved_0", "cc", "cc/env", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Label, error, EDITOR, i18n, Logger, _dec, _class, _class2, _descriptor, _class3, _crd, ccclass, property, LocalizedLabel;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfi18n(extras) {
  8. _reporterNs.report("i18n", "./LanguageData", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfLogger(extras) {
  11. _reporterNs.report("Logger", "../../../extend/Logger", _context.meta, extras);
  12. }
  13. return {
  14. setters: [function (_unresolved_) {
  15. _reporterNs = _unresolved_;
  16. }, function (_cc) {
  17. _cclegacy = _cc.cclegacy;
  18. __checkObsolete__ = _cc.__checkObsolete__;
  19. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  20. _decorator = _cc._decorator;
  21. Component = _cc.Component;
  22. Label = _cc.Label;
  23. error = _cc.error;
  24. }, function (_ccEnv) {
  25. EDITOR = _ccEnv.EDITOR;
  26. }, function (_unresolved_2) {
  27. i18n = _unresolved_2.default;
  28. }, function (_unresolved_3) {
  29. Logger = _unresolved_3.Logger;
  30. }],
  31. execute: function () {
  32. _crd = true;
  33. _cclegacy._RF.push({}, "c4c1axXN+NL4oYQEr2M4qn2", "LocalizedLabel", undefined);
  34. __checkObsolete__(['_decorator', 'Component', 'Label', 'log', 'error']);
  35. ({
  36. ccclass,
  37. property
  38. } = _decorator);
  39. /**
  40. * 1、lable多语言 直接挂载LocalizedLabel类 到lable节点上 然后填入id,
  41. 这个id是多语言中i18n.languages.en 例如
  42. "lottery": {
  43. "title": "Wheel of fortune",
  44. "free": "Free"
  45. },就是 填入“lottery.title”
  46. 2、打当lable文本是动态的时候,比如”你完成了多少个个订单“ 这儿就需要你在当前所在的类的,
  47. 就是这个空间的所在的页面调用 this.lbTakeCount.string = i18n("balance.你完成了%{value}个订单", { value: take});
  48. 传入动态的实际参数,然后在这个lable上就不需要在去挂载 LocalizedLabel类
  49. 以上总结:就是静态的多语言文本需要挂载 LocalizedLabel类
  50. 而动态的不需要挂载,直接在当前的文本类里设置动态的多语言
  51. */
  52. _export("default", LocalizedLabel = (_dec = ccclass("LocalizedLabel"), _dec(_class = (_class2 = (_class3 = class LocalizedLabel extends Component {
  53. constructor() {
  54. super(...arguments);
  55. this._debouncedUpdateLabel = null;
  56. this.label = null;
  57. _initializerDefineProperty(this, "_dataID", _descriptor, this);
  58. }
  59. set dataID(val) {
  60. if (this._dataID !== val) {
  61. this._dataID = val;
  62. if (EDITOR) {
  63. this._debouncedUpdateLabel && this._debouncedUpdateLabel();
  64. } else {
  65. this.updateLabel();
  66. }
  67. }
  68. }
  69. get dataID() {
  70. return this._dataID;
  71. }
  72. onLoad() {
  73. if (EDITOR) {
  74. this._debouncedUpdateLabel = this.debounce(this.updateLabel, 200);
  75. }
  76. if (!(_crd && i18n === void 0 ? (_reportPossibleCrUseOfi18n({
  77. error: Error()
  78. }), i18n) : i18n).inst) {
  79. (_crd && i18n === void 0 ? (_reportPossibleCrUseOfi18n({
  80. error: Error()
  81. }), i18n) : i18n).init();
  82. }
  83. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  84. error: Error()
  85. }), Logger) : Logger).log('dataID: ' + this.dataID + ' value: ' + (_crd && i18n === void 0 ? (_reportPossibleCrUseOfi18n({
  86. error: Error()
  87. }), i18n) : i18n)(this.dataID));
  88. this.fetchRender();
  89. }
  90. fetchRender() {
  91. var label = this.getComponent(Label);
  92. if (label) {
  93. this.label = label;
  94. this.updateLabel();
  95. return;
  96. }
  97. }
  98. updateLabel() {
  99. if (!this.label) {
  100. error('Failed to update localized label, label component is invalid!');
  101. return;
  102. }
  103. var localizedString = (_crd && i18n === void 0 ? (_reportPossibleCrUseOfi18n({
  104. error: Error()
  105. }), i18n) : i18n)(this.dataID, {});
  106. if (localizedString) {
  107. this.label.string = (_crd && i18n === void 0 ? (_reportPossibleCrUseOfi18n({
  108. error: Error()
  109. }), i18n) : i18n)(this.dataID, {});
  110. }
  111. }
  112. debounce(func, wait, immediate) {
  113. var timeout = -1;
  114. return (() => {
  115. var args = arguments;
  116. var later = (() => {
  117. timeout = -1;
  118. if (!immediate) func.apply(this, args);
  119. }).bind(this);
  120. var callNow = immediate && !timeout;
  121. clearTimeout(timeout);
  122. timeout = setTimeout(later, wait);
  123. if (callNow) func.apply(this, args);
  124. }).bind(this);
  125. }
  126. }, _class3.editor = {
  127. executeInEditMode: true,
  128. menu: 'i18n/LocalizedLabel'
  129. }, _class3), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "_dataID", [property], {
  130. configurable: true,
  131. enumerable: true,
  132. writable: true,
  133. initializer: function initializer() {
  134. return "";
  135. }
  136. }), _applyDecoratedDescriptor(_class2.prototype, "dataID", [property], Object.getOwnPropertyDescriptor(_class2.prototype, "dataID"), _class2.prototype)), _class2)) || _class));
  137. _cclegacy._RF.pop();
  138. _crd = false;
  139. }
  140. };
  141. });
  142. //# sourceMappingURL=540fe8707c3487a9e7d67cbac8436ed8bbbd2bfa.js.map