Exemplo n.º 1
0
        //public static event Action OnLanguageChanged;

        public static ITranslationUtilityInstance createNewInstance(string destinationLanguageCode = "", string group = "")
        {
            if (_LanguageList == null)
            {
                _LanguageList = ResourceLoadFacade.getLanguageList();
            }

            if (_LanguageList == null)
            {
                Debug.LogError("Could not load new language list");
                return(null);
            }
            bool enableCapture = false;

#if UNITY_EDITOR
            if (Application.isEditor)
            {
                enableCapture = getCaptureMode();
            }
#endif //UNTIY_EDITOR

            TransfluentLanguage dest = _LanguageList.getLangaugeByCode(destinationLanguageCode);
            if (dest == null)
            {
                TranslationConfigurationSO defaultConfigInfo = ResourceLoadFacade.LoadConfigGroup(group);
                string newDestinationLanguageCode            = defaultConfigInfo.sourceLanguage.code;

                /*
                 * if (string.IsNullOrEmpty(destinationLanguageCode))
                 * {
                 *      Debug.Log("Using default destination language code, as was given an empty language code");
                 * }
                 * else
                 *      Debug.Log("Could not load destination language code:" + destinationLanguageCode + " so falling back to source game language code:" + destinationLanguageCode);
                 */
                destinationLanguageCode = newDestinationLanguageCode;

                dest = _LanguageList.getLangaugeByCode(destinationLanguageCode);
                //dest = _LanguageList.getLangaugeByCode
            }
            GameTranslationSet          destLangDB = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(destinationLanguageCode);
            Dictionary <string, string> keysInLanguageForGroupSpecified = destLangDB != null
                                ? destLangDB.getGroup(group).getDictionaryCopy()
                                : new Dictionary <string, string>();

#if UNITY_EDITOR
            EditorUtility.SetDirty(destLangDB);
#endif

            var newTranslfuentUtilityInstance = new TranslationUtilityInstance
            {
                allKnownTranslations = keysInLanguageForGroupSpecified,
                destinationLanguage  = dest,
                groupBeingShown      = group,
            };
            if (enableCapture)
            {
                newTranslfuentUtilityInstance = new AutoCaptureTranslationUtiliityInstance()
                {
                    allKnownTranslations = keysInLanguageForGroupSpecified,
                    destinationLanguage  = dest,
                    groupBeingShown      = group,
                    doCapture            = enableCapture,
                    coreTransltionSet    = destLangDB,
                };
            }
            return(newTranslfuentUtilityInstance);
        }
        //public static event Action OnLanguageChanged;
        public static ITranslationUtilityInstance createNewInstance(string destinationLanguageCode = "", string group = "")
        {
            if(_LanguageList == null)
            {
                _LanguageList = ResourceLoadFacade.getLanguageList();
            }

            if(_LanguageList == null)
            {
                Debug.LogError("Could not load new language list");
                return null;
            }
            bool enableCapture = false;
            #if UNITY_EDITOR
            if(Application.isEditor)
            {
                enableCapture = getCaptureMode();
            }
            #endif //UNTIY_EDITOR

            TransfluentLanguage dest = _LanguageList.getLangaugeByCode(destinationLanguageCode);
            if(dest == null)
            {
                TranslationConfigurationSO defaultConfigInfo = ResourceLoadFacade.LoadConfigGroup(group);
                string newDestinationLanguageCode = defaultConfigInfo.sourceLanguage.code;
                /*
                if (string.IsNullOrEmpty(destinationLanguageCode))
                {
                    Debug.Log("Using default destination language code, as was given an empty language code");
                }
                else
                    Debug.Log("Could not load destination language code:" + destinationLanguageCode + " so falling back to source game language code:" + destinationLanguageCode);
                 */
                destinationLanguageCode = newDestinationLanguageCode;

                dest = _LanguageList.getLangaugeByCode(destinationLanguageCode);
                //dest = _LanguageList.getLangaugeByCode
            }
            GameTranslationSet destLangDB = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(destinationLanguageCode);
            Dictionary<string, string> keysInLanguageForGroupSpecified = destLangDB != null
                ? destLangDB.getGroup(group).getDictionaryCopy()
                : new Dictionary<string, string>();
            #if UNITY_EDITOR
            EditorUtility.SetDirty(destLangDB);
            #endif

            var newTranslfuentUtilityInstance = new TranslationUtilityInstance
            {
                allKnownTranslations = keysInLanguageForGroupSpecified,
                destinationLanguage = dest,
                groupBeingShown = group,
            };
            if(enableCapture)
            {
                newTranslfuentUtilityInstance = new AutoCaptureTranslationUtiliityInstance()
                {
                    allKnownTranslations = keysInLanguageForGroupSpecified,
                    destinationLanguage = dest,
                    groupBeingShown = group,
                    doCapture = enableCapture,
                    coreTransltionSet = destLangDB,
                };
            }
            return newTranslfuentUtilityInstance;
        }