/// <summary> /// Load localizations for this mod. /// </summary> private void LoadLocalization() { var path = Path.Combine(ModContext.ModPathData, "Localization"); var supportedLanguages = new HashSet <MyLanguagesEnum>(); MyTexts.LoadSupportedLanguages(path, supportedLanguages); var currentLanguage = supportedLanguages.Contains(MyAPIGateway.Session.Config.Language) ? MyAPIGateway.Session.Config.Language : MyLanguagesEnum.English; if (Language != null && Language == currentLanguage) { return; } Language = currentLanguage; var languageDescription = MyTexts.Languages.Where(x => x.Key == currentLanguage).Select(x => x.Value).FirstOrDefault(); if (languageDescription != null) { var cultureName = string.IsNullOrWhiteSpace(languageDescription.CultureName) ? null : languageDescription.CultureName; var subcultureName = string.IsNullOrWhiteSpace(languageDescription.SubcultureName) ? null : languageDescription.SubcultureName; MyTexts.LoadTexts(path, cultureName, subcultureName); } }
/// <summary> /// Load translations for this mod. /// </summary> private void LoadTranslation() { using (PROFILE ? Profiler.Measure(nameof(Mod), nameof(LoadTranslation)) : null) { using (Log.BeginMethod(nameof(LoadTranslation))) { var currentLanguage = MyAPIGateway.Session.Config.Language; var supportedLanguages = new HashSet <MyLanguagesEnum>(); MyTexts.LoadSupportedLanguages($"{ModContext.ModPathData}\\Localization", supportedLanguages); if (supportedLanguages.Contains(currentLanguage)) { MyTexts.LoadTexts($"{ModContext.ModPathData}\\Localization", MyTexts.Languages[currentLanguage].CultureName); Log.Info($"Loaded {MyTexts.Languages[currentLanguage].FullCultureName} translations."); } else if (supportedLanguages.Contains(MyLanguagesEnum.English)) { MyTexts.LoadTexts($"{ModContext.ModPathData}\\Localization", MyTexts.Languages[MyLanguagesEnum.English].CultureName); Log.Warning($"No {MyTexts.Languages[currentLanguage].FullCultureName} translations found. Fall back to {MyTexts.Languages[MyLanguagesEnum.English].FullCultureName} translations."); } } } }
public static void Init() { MyTexts.LoadSupportedLanguages(GetLocalizationPath(), m_supportedLanguages); LoadLanguage(MyLanguagesEnum.English); }