Пример #1
0
        public KeyLanguageTextMap RepopulateAllTranslations()
        {
            // Setup or clear the dictionary
            if (allTranslations == null)
            {
                allTranslations = new KeyLanguageTextMap(this);
            }
            allTranslations.Clear();

            // Populate the dictionary
            LanguageTextMap toAdd = null;

            foreach (TranslationCollection collection in translations)
            {
                // Create a new dictionary
                toAdd = allTranslations.Add(collection.Key);
                if (toAdd != null)
                {
                    // Add all the pairs
                    foreach (LanguageTextPair pair in collection.AllTranslations)
                    {
                        // Make sure the language is supported before adding to the map
                        if (SupportedLanguages.Contains(pair.LanguageIndex) == true)
                        {
                            toAdd[pair.LanguageIndex] = pair.Text;
                        }
                    }
                }
            }

            // Indicate the dictionary matches the serialization
            IsAllTranslationsSerialized = true;
            return(allTranslations);
        }
        void SetupDefaults(List <Dictionary <string, string> > data)
        {
            // Populate the supported languages so the defaults are correct
            SupportedLanguages.Clear();
            foreach (string key in data[0].Keys)
            {
                if ((string.IsNullOrEmpty(key) == false) && (key != keyHeader))
                {
                    SupportedLanguages.Add(key);
                }
            }

            // Make sure the list is populated
            if (SupportedLanguages.Count > 0)
            {
                SetupDefaultLanguage();
                SetupCurrentLanguage();

                // Setup the default translation dictionary, taking in both default language and left-most column as backup
                SetupTranslationDictionary(DefaultTranslationDictionary, data, keyHeader, DefaultLanguage, SupportedLanguages[0]);
            }
            else
            {
                // Setup the default translation dictionary, taking in only the default language
                SetupTranslationDictionary(DefaultTranslationDictionary, data, keyHeader, DefaultLanguage);
            }
        }
Пример #3
0
            public string this[string languageName]
            {
                get
                {
                    // Check if the language index is valid
                    if (SupportedLanguages.Contains(languageName) == false)
                    {
                        // Indicate if it isn't
                        throw new ArgumentOutOfRangeException("languageName");
                    }

                    // Use the above getter
                    return(this[SupportedLanguages[languageName]]);
                }
                set
                {
                    // Check if the language index is valid
                    if (SupportedLanguages.Contains(languageName) == false)
                    {
                        // Indicate if it isn't
                        throw new ArgumentOutOfRangeException("languageName");
                    }

                    // Use the above setter
                    this[SupportedLanguages[languageName]] = value;
                }
            }
        void SetupCurrentLanguage()
        {
            // Retrieve the current language settings from GameSettings
            currentLanguage = Singleton.Get <GameSettings>().Language;

            // Check if the current langauge is set
            if ((string.IsNullOrEmpty(currentLanguage) == true) || (SupportedLanguages.Contains(currentLanguage) == false))
            {
                // If not, use the default language instead
                currentLanguage = DefaultLanguage;

                // Update the settings
                Singleton.Get <GameSettings>().Language = currentLanguage;
            }
        }
Пример #5
0
            public string this[int languageIndex]
            {
                get
                {
                    // Check if the language index is valid
                    if (SupportedLanguages.Contains(languageIndex) == false)
                    {
                        // Indicate if it isn't
                        throw new ArgumentOutOfRangeException("languageIndex");
                    }

                    // Grab a text based off of the index
                    string returnText = null;
                    if (dictionary.TryGetValue(languageIndex, out returnText) == false)
                    {
                        // If none found, return null
                        returnText = null;
                    }
                    return(returnText);
                }
                set
                {
                    // Check if the language index is valid
                    if (SupportedLanguages.Contains(languageIndex) == false)
                    {
                        // Indicate if it isn't
                        throw new ArgumentOutOfRangeException("languageIndex");
                    }

                    // Check if the dictionary already contains a text
                    if (dictionary.ContainsKey(languageIndex) == false)
                    {
                        // Add this text
                        dictionary.Add(languageIndex, value);

                        // Indicate the serialization no longer matches what's contained in the dictionary
                        IsSerialized = false;
                    }
                    else if (dictionary[languageIndex] != value)
                    {
                        // Overwrite this text
                        dictionary[languageIndex] = value;

                        // Indicate the serialization no longer matches what's contained in the dictionary
                        IsSerialized = false;
                    }
                }
            }
        void SetupDefaultLanguage()
        {
            // Check to see if default language isn't set yet
            if (HeaderDictionary.ContainsKey(Application.systemLanguage) == true)
            {
                // Grab the default language from the system settings
                DefaultLanguage = HeaderDictionary[Application.systemLanguage];
            }

            // Check if the default language is set
            if ((string.IsNullOrEmpty(DefaultLanguage) == true) || (SupportedLanguages.Contains(DefaultLanguage) == false))
            {
                // If not, grab the first language in the headers
                DefaultLanguage = SupportedLanguages[0];
            }
        }
Пример #7
0
 public bool HasTranslation(string key, int languageIndex)
 {
     return((HasKey(key) == true) && (SupportedLanguages.Contains(languageIndex) == true) && (AllTranslations[key][languageIndex] != null));
 }