System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6"], function (_export, _context) {
  "use strict";

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, director, Polyglot, Singleton, LocalizedLabel, LocalizedSprite, Logger, GameConst, i18nCls, _crd, ccclass, property, curLang, langCacheKey, instance, i18nFn, i18n;

  function _reportPossibleCrUseOfPolyglot(extras) {
    _reporterNs.report("Polyglot", "./polyglot.min", _context.meta, extras);
  }

  function _reportPossibleCrUseOfSingleton(extras) {
    _reporterNs.report("Singleton", "../../manager/Singleton", _context.meta, extras);
  }

  function _reportPossibleCrUseOfLocalizedLabel(extras) {
    _reporterNs.report("LocalizedLabel", "./LocalizedLabel", _context.meta, extras);
  }

  function _reportPossibleCrUseOfLocalizedSprite(extras) {
    _reporterNs.report("LocalizedSprite", "./LocalizedSprite", _context.meta, extras);
  }

  function _reportPossibleCrUseOfLogger(extras) {
    _reporterNs.report("Logger", "../../extend/Logger", _context.meta, extras);
  }

  function _reportPossibleCrUseOfGameConst(extras) {
    _reporterNs.report("GameConst", "../../common/GameConst", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      _decorator = _cc._decorator;
      director = _cc.director;
    }, function (_unresolved_2) {
      Polyglot = _unresolved_2.Polyglot;
    }, function (_unresolved_3) {
      Singleton = _unresolved_3.Singleton;
    }, function (_unresolved_4) {
      LocalizedLabel = _unresolved_4.default;
    }, function (_unresolved_5) {
      LocalizedSprite = _unresolved_5.default;
    }, function (_unresolved_6) {
      Logger = _unresolved_6.Logger;
    }, function (_unresolved_7) {
      GameConst = _unresolved_7.GameConst;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "d6597NeRz5OuZ6kceJkHWc3", "LanguageData", undefined);

      __checkObsolete__(['_decorator']);

      __checkObsolete__(['director']);

      ({
        ccclass,
        property
      } = _decorator); //默认的多语言 必须是存在于数组i18n.languages中的

      curLang = 'zh'; //缓存选择的多语言的key

      langCacheKey = `${(_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
        error: Error()
      }), GameConst) : GameConst).gameName}CurLang`;
      /**事例
       * 1、切换语言调用:
       * let languages = Object.keys(i18n.languages);
         let count: number = (languages.indexOf(i18n.curLang) + 1) % languages.length;
         i18n.init(languages[count]);
      
         2、切换了语言整个页面刷新语言 调用:
         i18n.updateSceneRenderers();
      
         3、lable多语言 直接挂载LocalizedLabel类 到lable节点上 然后填入id，
         这个id是多语言中i18n.languages.en 例如
         "lottery": {
              "title": "Wheel of fortune",
              "free": "Free"
          },就是 填入“lottery.title”
      
          4、打当lable文本是动态的时候，比如”你完成了多少个个订单“ 这儿就需要你在当前所在的类的，
          就是这个空间的所在的页面调用 this.lbTakeCount.string = i18n.t("balance.你完成了%{value}个订单", { value: take});
          传入动态的实际参数，然后在这个lable上就不需要在去挂载 LocalizedLabel类
      
          5、图片多语言 直接挂载LocalizedSprite类 到对应的sprite节点上去
          然后根据languages.length的列表填入如 “en” 然后拖入英文的图片，然后“zh” 拖入中文的图片
       */

      i18nCls = class i18nCls extends (_crd && Singleton === void 0 ? (_reportPossibleCrUseOfSingleton({
        error: Error()
      }), Singleton) : Singleton) {
        //当前语言 默认语言中文
        get curLang() {
          var _localStorage$getItem;

          return (_localStorage$getItem = localStorage.getItem(langCacheKey)) != null ? _localStorage$getItem : curLang;
        } //设置当前语言并更新到 localStorage


        set curLang(language) {
          let cur = this.curLang;

          if (cur !== language) {
            //将语言存储到localStorage
            localStorage.setItem(langCacheKey, language); //初始化语言

            this.init(language);
          }
        }

        constructor() {
          super();
          this.inst = null;
          //多语言数组
          this.languages = {
            en: {},
            zh: {}
          };
          this.init();
        }

        initPolyglot(data) {
          if (data) {
            if (this.inst) {
              this.inst.replace(data);
            } else {
              this.inst = new (_crd && Polyglot === void 0 ? (_reportPossibleCrUseOfPolyglot({
                error: Error()
              }), Polyglot) : Polyglot)({
                phrases: data,
                allowMissing: true
              });
            }
          }
        }
        /**
         * This method allow you to switch language during runtime, language argument should be the same as your data file name
         * such as when language is 'zh', it will load your 'zh.js' data source.
         * @method init
         * @param language - the language specific data file name, such as 'zh' to load 'zh.js'
         */


        init(language) {
          if (!language || language === this.curLang) {
            return;
          }

          let data = this.languages[language] || {};
          this.curLang = language;
          this.initPolyglot(data);
        }
        /**
         * this method takes a text key as input, and return the localized string
         * Please read https://github.com/airbnb/polyglot.js for details
         * @method t
         * @return {String} localized string
         * @example
         *
         * var myText = i18n.t('MY_TEXT_KEY');
         *
         * // if your data source is defined as
         * // {"hello_name": "Hello, %{name}"}
         * // you can use the following to interpolate the text
         * var greetingText = i18n.t('hello_name', {name: 'nantas'}); // Hello, nantas
         */


        t(key, opt) {
          var _this$inst;

          //检查数据是否加载
          if (!this.inst || Object.keys(this.inst.phrases).length === 0) {
            const data = this.languages[this.curLang] || {};
            this.initPolyglot(data);
            (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
              error: Error()
            }), Logger) : Logger).warn('数据未加载，重新初始化');
          } //调用 Polyglot 的翻译方法


          return ((_this$inst = this.inst) == null ? void 0 : _this$inst.t(key, opt)) || key;
        }
        /**
         * inst: polyInst
         * 是遍历场景中所有的 LocalizedLabel 和 LocalizedSprite 组件，并更新它们的显示内容
        */


        updateSceneRenderers() {
          // very costly iterations
          let rootNodes = director.getScene().children; // walk all nodes with localize label and update

          let allLocalizedLabels = [];

          for (let i = 0; i < rootNodes.length; ++i) {
            let labels = rootNodes[i].getComponentsInChildren(_crd && LocalizedLabel === void 0 ? (_reportPossibleCrUseOfLocalizedLabel({
              error: Error()
            }), LocalizedLabel) : LocalizedLabel);
            Array.prototype.push.apply(allLocalizedLabels, labels);
          }

          for (let i = 0; i < allLocalizedLabels.length; ++i) {
            let label = allLocalizedLabels[i];
            if (!label.node.active) continue;
            label.updateLabel();
          } //walk all nodes with localize sprite and update


          let allLocalizedSprites = [];

          for (let i = 0; i < rootNodes.length; ++i) {
            let sprites = rootNodes[i].getComponentsInChildren(_crd && LocalizedSprite === void 0 ? (_reportPossibleCrUseOfLocalizedSprite({
              error: Error()
            }), LocalizedSprite) : LocalizedSprite);
            Array.prototype.push.apply(allLocalizedSprites, sprites);
          }

          for (let i = 0; i < allLocalizedSprites.length; ++i) {
            let sprite = allLocalizedSprites[i];
            if (!sprite.node.active) continue;
            sprite.updateSprite(this.curLang);
          }
        }

      };
      ;
      instance = i18nCls.ins(); //使用函数保持this 绑定

      i18nFn = (key, opt) => instance.t(key, opt); //拷贝所有方法到函数对象


      i18n = Object.setPrototypeOf(i18nFn, instance); //导出类型声明保持不变

      _export("default", i18n);

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=b7172603187c74def01ed93147d98a4a5af14d64.js.map