ParallelRoadTool/Utils/LocalizationManager.cs
/// <summary>
/// Loads the provided resource as a language file and also loads additional files for other languages.
/// This allows us to load English as a shared base, and then to add custom languages on top of it.
/// The result is that we have all the localized strings in the provided language, while still using English as a fallback for non-localized ones.
/// </summary>
/// <param name="resourceName"></param>
Loads the provided resource as a language file and also loads additional files for other languages.
This allows us to load English as a shared base, and then to add custom languages on top of it.
The result is that we have all the localized strings in the provided language, while still using English as a fallback for non-localized ones.
Loads the provided resource as a language file and also loads additional files for other languages . This allows us to load English as a shared base and then to add custom languages on top of it . The result is that we have all the localized strings in the provided language while still using English as a fallback for non - localized ones .
private static bool ApplyLocaleResources(string resourceName, params string[] additionalResourcesNames)
        {
            var nameList = ReadNameList(resourceName);
            if (nameList == null)
            {
                Log._DebugOnlyError($"[{nameof(LocalizationManager)}.{nameof(ApplyLocaleResources)}] ApplyLocaleResource(${resourceName}) failed.");
                return false;
            }
            var localizedStringsDictionary = nameList.LocalizedStrings.ToDictionary(k => $"{k.Identifier}:{k.Key}", v => v);
            foreach (var additionalResourceName in additionalResourcesNames.Where(l => resourceName != l))
            {
                var additionalNameList = ReadNameList(additionalResourceName);
                if (additionalNameList == null)
                {
                    Log._Debug($"[{nameof(LocalizationManager)}.{nameof(ApplyLocaleResources)}] Failed loading additional resource {additionalResourceName}.");                    return false;
                }
                foreach (var additionalLocalizedString in additionalNameList.LocalizedStrings)
                {
                    localizedStringsDictionary[$"{additionalLocalizedString.Identifier}:{additionalLocalizedString.Key}"] = additionalLocalizedString;
                }
            }
            nameList.LocalizedStrings = localizedStringsDictionary.Values.ToArray();
            nameList.Apply();
            return true;
        }
private static bool ApplyLocaleResources ( string resourceName , params string [ ] additionalResourcesNames ) { var nameList = ReadNameList ( resourceName ) ; if ( nameList == null ) { Log . _DebugOnlyError ( $" [ { nameof ( LocalizationManager ) } . { nameof ( ApplyLocaleResources ) } ] ApplyLocaleResource($ { resourceName } ) failed. " ) ; return false ; } var localizedStringsDictionary = nameList . LocalizedStrings . ToDictionary ( k => $" { k . Identifier } : { k . Key } " , v => v ) ; foreach ( var additionalResourceName in additionalResourcesNames . Where ( l => resourceName != l ) ) { var additionalNameList = ReadNameList ( additionalResourceName ) ; if ( additionalNameList == null ) { Log . _Debug ( $" [ { nameof ( LocalizationManager ) } . { nameof ( ApplyLocaleResources ) } ] Failed loading additional resource  { additionalResourceName } . " ) ; return false ; } foreach ( var additionalLocalizedString in additionalNameList . LocalizedStrings ) { localizedStringsDictionary [ $" { additionalLocalizedString . Identifier } : { additionalLocalizedString . Key } " ] = additionalLocalizedString ; } } nameList . LocalizedStrings = localizedStringsDictionary . Values . ToArray ( ) ; nameList . Apply ( ) ; return true ; }
Loads the provided resource as a language file and also loads additional files for other languages.
Loads the provided resource as a language file and also loads additional files for other languages .
// Read base NameList // Replace LocalizedStrings using the ones provided in additionalResourcesNames. Skip default language in this list. // Load the additional resource // Replace strings that already exist // Reconvert to array and apply
resourceName
string
None