public void testInstance()
    {
        var destinationLanguage = new TransfluentLanguage { code = "fo-o", id = 501, name = "foo" };

        var instance = new TranslationUtilityInstance
        {
            destinationLanguage = destinationLanguage,
            allKnownTranslations = new Dictionary<string, string>
            {
                {"hello world", "world hello"},
                {"formatted {0} text", "formatted text"}
            },
        };

        string toTranslateDoesNotExist = "THIS DOES NOT EXIST";
        Assert.AreEqual(instance.getTranslation(toTranslateDoesNotExist), toTranslateDoesNotExist);

        string toTranslateDoesNotExist2 = "THIS DOES NOT EXIST formattted {0}";
        Assert.AreEqual(instance.getFormattedTranslation(toTranslateDoesNotExist2, "nope"),
            string.Format(toTranslateDoesNotExist2, "nope"));

        string formattedStringThatExists = "formatted {0} text blah blah blah";
        Assert.AreEqual(instance.getFormattedTranslation(formattedStringThatExists, "success"),
                        string.Format(formattedStringThatExists, "success"));

        string toTranslateAndExists = "hello world";
        string translationResult = "world hello";
        Assert.AreEqual(translationResult, instance.getTranslation(toTranslateAndExists));
    }
Beispiel #2
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;
        }