コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
ファイル: Mod.cs プロジェクト: AutoMcDonough/Smart_Rotors
        /// <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.");
                    }
                }
            }
        }
コード例 #3
0
 public static void Init()
 {
     MyTexts.LoadSupportedLanguages(GetLocalizationPath(), m_supportedLanguages);
     LoadLanguage(MyLanguagesEnum.English);
 }