LoadLanguageFile() public static method

Loads the language file and returns the RAW values
public static LoadLanguageFile ( string languageCode ) : string>.Dictionary
languageCode string
return string>.Dictionary
示例#1
0
    /// <summary>
    /// Creates a new language file with the keys from the root file.
    /// </summary>
    /// <param name='languageName'>
    /// The name of the language
    /// </param>
    public static void CreateNewLanguage(string languageName)
    {
        Dictionary <string, string> rootValues = LocFileUtility.LoadLanguageFile(null);

        //Copy the keys over to the new language
        Dictionary <string, string> baseDictionary = new Dictionary <string, string>();

        foreach (KeyValuePair <string, string> keyPair in rootValues)
        {
            baseDictionary.Add(keyPair.Key, "");
        }

        //Save the new language file
        LocFileUtility.SaveLanguageFile(baseDictionary, LocFileUtility.rootLanguageFilePath + "." + languageName + LocFileUtility.resXFileEnding);
    }
示例#2
0
    /// <summary>
    /// Saves the root language file and updates all the available languages.
    /// </summary>
    public static void SaveRootLanguageFile(Dictionary <string, string> changedRootKeys, Dictionary <string, string> changedRootValues)
    {
        //The dictionary with all the final changes
        Dictionary <string, string> changedDictionary = new Dictionary <string, string>();

        foreach (KeyValuePair <string, string> changedKey in changedRootKeys)
        {
            if (changedKey.Key == changedKey.Value)
            {
                //The key is not changed, just add the key and the changed value to the new dictionary
                AddNewKeyPersistent(changedDictionary, changedKey.Key, changedRootValues[changedKey.Key]);
            }
            else
            {
                //Add the new key along with the new changed value
                AddNewKeyPersistent(changedDictionary, changedKey.Value, changedRootValues[changedKey.Key]);
            }
        }

        //Look if any keys were deleted,(so that we can delete the created files)
        //(Somewhat costly operation)
        List <string>        deletedKeys  = new List <string>();
        IEnumerable <string> originalKeys = LoadLanguageFile(null).Keys;

        foreach (string originalKey in originalKeys)
        {
            bool foundMatch = false;
            foreach (KeyValuePair <string, string> changedKey in changedRootKeys)
            {
                if (originalKey == changedKey.Key)
                {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch)
            {
                deletedKeys.Add(originalKey);
            }
        }

        //Save the language file
        SaveLanguageFile(changedDictionary, LocFileUtility.rootLanguageFilePath + LocFileUtility.resXFileEnding);

        //Change all the key values for all the translated languages
        Dictionary <string, string> changedCultureValues = new Dictionary <string, string>();
        List <CultureInfo>          availableLanguages   = GetAvailableLanguages();

        foreach (CultureInfo cultureInfo in availableLanguages)
        {
            Dictionary <string, string> currentCultureValues = LocFileUtility.LoadLanguageFile(cultureInfo.Name);
            foreach (KeyValuePair <string, string> changedKey in changedRootKeys)
            {
                string thisValue;
                currentCultureValues.TryGetValue(changedKey.Key, out thisValue);
                if (thisValue == null)
                {
                    thisValue = "";
                }

                //If the key is changed, we need to change the asset names as well
                if (changedKey.Key != changedKey.Value && thisValue != "")
                {
                    LocalizedObjectType originalType = LocalizedObject.GetLocalizedObjectType(changedKey.Key);
                    LocalizedObjectType changedType  = LocalizedObject.GetLocalizedObjectType(changedKey.Value);

                    if (originalType != changedType)
                    {
                        //If the type is changed, then delete the asset and reset the value
                        DeleteFileFromResources(changedKey.Key, cultureInfo);
                        thisValue = "";
                    }
                    else
                    {
                        //just rename it otherwise
                        RenameFileFromResources(changedKey.Key, changedKey.Value, cultureInfo);
                    }
                }

                AddNewKeyPersistent(changedCultureValues, changedKey.Value, thisValue);
            }

            //Save the language file
            SaveLanguageFile(changedCultureValues, LocFileUtility.rootLanguageFilePath + "." + cultureInfo.Name + LocFileUtility.resXFileEnding);
            changedCultureValues.Clear();

            //Remove all the deleted files associated with the deleted keys
            foreach (string deletedKey in deletedKeys)
            {
                DeleteFileFromResources(deletedKey, cultureInfo);
            }
        }
    }