コード例 #1
0
        private TranslatedDictionary <T> AddLanguageFallback <T>(
            string[] importLanguages, TranslatedDictionary <T> availableValues
            )
        {
            if (importLanguages == null || importLanguages.Length == 0)
            {
                return(availableValues);
            }

            if (availableValues == null || availableValues.Count == 0)
            {
                return(null);
            }

            bool needEnglishFallback = !importLanguages.Contains("en");

            // copy over all languages to import
            TranslatedDictionary <T> result = new TranslatedDictionary <T>();

            foreach (var importLanguage in importLanguages)
            {
                if (availableValues.ContainsKey(importLanguage))
                {
                    result.Add(importLanguage, availableValues[importLanguage]);
                }
                else if (needEnglishFallback && availableValues.ContainsKey("en"))
                {
                    // Add English as fallback for all languages not available

                    result.Add(importLanguage, availableValues["en"]);
                }
            }
            return(result);
        }
コード例 #2
0
        public static string MinutesToText(this int minutes, TranslatedDictionary labels)
        {
            var timespan = TimeSpan.FromMinutes(minutes);

            var result = string.Empty;

            if (timespan.Days > 0)
            {
                result += timespan.Days + " ";
                result += timespan.Days > 1 ? labels["General:Dashboard:Days"] : labels["General:Dashboard:Day"];
                result += " " + timespan.Hours + " ";
                result += timespan.Hours > 1 ? labels["General:Dashboard:Hours"] : labels["General:Dashboard:Hour"];
                result += " " + timespan.Minutes + " ";
                result += timespan.Minutes > 1 ? labels["General:Dashboard:Minutes"] : labels["General:Dashboard:Minute"];
            }
            else if (timespan.Hours > 0)
            {
                result += timespan.Hours + " ";
                result += timespan.Hours > 1 ? labels["General:Dashboard:Hours"] : labels["General:Dashboard:Hour"];
                result += " " + timespan.Minutes + " ";
                result += timespan.Minutes > 1 ? labels["General:Dashboard:Minutes"] : labels["General:Dashboard:Minute"];
            }
            else if (timespan.Minutes > 0)
            {
                result += timespan.Minutes + " ";
                result += timespan.Minutes > 1 ? labels["General:Dashboard:Minutes"] : labels["General:Dashboard:Minute"];
            }
            else
            {
                result += labels["General:Dashboard:Started"];
            }

            return(result);
        }
コード例 #3
0
        protected TranslatedDictionary GetLabels()
        {
            var settings = TranslationSettings;

            settings.AddSettings("General", "Dashboard");
            settings.AddSettings("Dashboard", "MainMenu");

            var dictionary           = translationManager.GetTranslationLabels(LanguageId, settings.ModuleTypes);
            var translatedDictionary = new TranslatedDictionary();

            translatedDictionary.AddRange(dictionary);

            return(translatedDictionary);
        }
コード例 #4
0
        public static string Translate(string key)
        {
            string _result = string.Empty;

            if (LanguageDictionary == null || CurrentLanguage != DefaultLanguage)
            {
                CurrentLanguage = DefaultLanguage;

                if (Resources.Load(DefaultFileName + CurrentLanguage) != null)//
                {
                    LanguageDictionary = JsonUtility.FromJson <TranslatedDictionary>("{\"Dictionary\":" + Resources.Load(DefaultFileName + CurrentLanguage).ToString() + "}");
                }
                else
                {
                    LanguageDictionary = null;
                }
            }

            if (LanguageDictionary != null)
            {
                foreach (TranslatedWords item in LanguageDictionary.Dictionary)
                {
                    if (item.key == key)
                    {
                        _result = item.words;
                        break;
                    }
                }
            }

            if (_result == string.Empty)
            {
                _result = "[<color=red>" + key + "</color>][<color=red>" + CurrentLanguage + "</color>]";
#if UNITY_EDITOR
                Debug.LogError("[DBG] [Localization] [<color=red>Not Found</color>][" + key + "][" + CurrentLanguage + "]");
#endif
            }

            return(_result);
        }
コード例 #5
0
        protected TranslatedDictionary GetLabels()
        {
            var settings = TranslationSettings;

            settings.AddSettings("General", "Dashboard");
            settings.AddSettings("Dashboard", "MainMenu");

            var languageCookie = httpContextAccessor.HttpContext.Request.Cookies
                                 .FirstOrDefault(x => x.Key == "language");

            var languageId = 1;

            if (!languageCookie.IsNullOrDefault())
            {
                languageId = languageCookie.Value.ToInt();
            }

            var labels     = translationManager.GetTranslationLabels(languageId, settings.ModuleTypes);
            var dictionary = new TranslatedDictionary();

            dictionary.AddRange(labels);

            return(dictionary);
        }