public void ProvideTranslationFromHighlyPrioritizedSource()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello from memory!");
            CreateFileWithTranslations(localizationsFilePath, new []
            {
                new LocalFileSource.StringTranslationRecord
                {
                    TextCode    = "greeting",
                    CultureId   = enCulture.LCID,
                    Translation = "Hello from file!"
                }
            });
            var localFileSource     = new LocalFileSource(localizationsFilePath);
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);
            localizationFactory.RegisterSource(localFileSource, 1);

            var code             = new LocalizationCode("greeting");
            var translatedString = localizationFactory.GetString(code);

            Assert.AreEqual("Hello from file!", translatedString);
        }
예제 #2
0
        public void LoadLanguage(LocalizationCode i_localization)
        {
            Localization localization = LoadLocalization(i_localization);

            m_currentLang         = i_localization;
            m_currentLocalization = localization;
            m_langChangedObservable.Notify(new LanguageChanged());
        }
예제 #3
0
        private static Localization LoadLocalization(LocalizationCode i_localization)
        {
            Localization localization = new Localization();

            TextData[] texts = Resources.LoadAll <TextData>("texts/");
            foreach (TextData text in texts)
            {
                localization.Set(text.id, text.get(i_localization));
            }

            return(localization);
        }
예제 #4
0
        public string get(LocalizationCode i_localization)
        {
            switch (i_localization)
            {
            case LocalizationCode.en_EN:
                return(m_english);

            case LocalizationCode.es_ES:
                return(m_spanish);
            }
            return("");
        }
        public void ProvideTranslationFromSpecificSource()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello world!");
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);

            var code             = new LocalizationCode("greeting", LocalizationSourceType.InMemory);
            var translatedString = localizationFactory.GetString(code, enCulture);

            Assert.AreEqual("Hello world!", translatedString);
        }
        public void ProvideCorrectTranslation_WhenSeveralTranslationsExist()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello world!");
            inMemorySource.SaveString("greeting", ruCulture, "Привет мир!");
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);

            var code             = new LocalizationCode("greeting", LocalizationSourceType.InMemory);
            var translatedString = localizationFactory.GetString(code, ruCulture);

            Assert.AreEqual("Привет мир!", translatedString);
        }
예제 #7
0
 public LocalizationManager(LocalizationCode i_code)
 {
     Debug.Assert(s_localizationManager == null);
     s_localizationManager = this;
     LoadLanguage(i_code);
 }
예제 #8
0
        //Deprecated
        //public void LoadLanguageFromExcel(string langCode)
        //{
        //    TextAsset textAsset = (TextAsset)Resources.Load("texts/texts.lang");
        //    Dictionary<string, Localization> localizations = LocalizationParser.Load(textAsset);
        //
        //    //Dictionary<string, texts.Localization> localizations = texts.LocalizationParser.Load(Path.Combine(Application.streamingAssetsPath, "texts/texts.lang.xls"));
        //    if (localizations.ContainsKey(langCode))
        //    {
        //        m_currentLang = langCode;
        //        m_currentLocalization = localizations[langCode];
        //        m_langChangedObservable.Notify(new LanguageChanged());
        //    }
        //    else
        //    {
        //        m_currentLang = "";
        //        m_currentLocalization = null;
        //    }
        //}

#if UNITY_EDITOR
        //static EditorAsset<TextAsset> s_textFile;
        //static Dictionary<LocalizationCode, Localization> s_localizations;

        public static Localization GetLocalization(LocalizationCode i_code)
        {
            return(LoadLocalization(i_code));
        }