@@ -5,19 +5,27 @@ namespace MultiBloxy
55{
66 public class Localization
77 {
8- private readonly Dictionary < string , Dictionary < string , string > > _translations ;
9- private string _currentLocale ;
8+ public readonly Dictionary < string , Dictionary < string , string > > Locales ;
9+ public string CurrentLocale ;
1010
11+ // Constructor to initialize the Localization class
1112 public Localization ( )
1213 {
13- _translations = new Dictionary < string , Dictionary < string , string > > ( ) ;
14- _currentLocale = CultureInfo . CurrentCulture . Name ;
15- LoadTranslations ( ) ;
14+ Locales = new Dictionary < string , Dictionary < string , string > > ( ) ;
15+ AutoCurrentLocale ( ) ;
16+ LoadLocales ( ) ;
1617 }
1718
18- private void LoadTranslations ( )
19+ // Automatically sets the current locale based on the system's culture settings
20+ public void AutoCurrentLocale ( )
1921 {
20- _translations [ "en" ] = new Dictionary < string , string >
22+ CurrentLocale = CultureInfo . CurrentCulture . TwoLetterISOLanguageName ;
23+ }
24+
25+ // Loads predefined locales into the Locales dictionary
26+ private void LoadLocales ( )
27+ {
28+ Locales [ "en" ] = new Dictionary < string , string >
2129 {
2230 { "ContextMenu.StatusMenuItem.Running" , "Status: Running" } ,
2331 { "ContextMenu.StatusMenuItem.Paused" , "Status: Paused" } ,
@@ -31,6 +39,8 @@ private void LoadTranslations()
3139 { "ContextMenu.SettingsMenuItem.Settings" , "Settings" } ,
3240 { "ContextMenu.SettingsMenuItem.PauseOnLaunchMenuItem.PauseOnLaunch" , "Pause on Launch" } ,
3341 { "ContextMenu.SettingsMenuItem.ResetRememberedMenuItem.ResetRemembered" , "Reset Remembered Options" } ,
42+ { "ContextMenu.SettingsMenuItem.LanguageMenuItem.Language" , "Language" } ,
43+ { "ContextMenu.SettingsMenuItem.LanguageMenuItem.AutoDetectMenuItem.AutoDetect" , "Auto Detect" } ,
3444 { "ContextMenu.ExitMenuItem.Exit" , "Exit" } ,
3545 { "Error.Mutex.Caption" , "Failed to Create Mutex" } ,
3646 { "Error.Mutex.Message" , "An error occurred while creating the Mutex. This likely happened because when {0} was launched, Roblox was already running and had registered its handle. You can do the following:" } ,
@@ -44,7 +54,7 @@ private void LoadTranslations()
4454 { "Error.Singleton.Message" , "{0} is already running. Try looking in the system tray." }
4555 } ;
4656
47- _translations [ "ru" ] = new Dictionary < string , string >
57+ Locales [ "ru" ] = new Dictionary < string , string >
4858 {
4959 { "ContextMenu.StatusMenuItem.Running" , "Статус: Работает" } ,
5060 { "ContextMenu.StatusMenuItem.Paused" , "Статус: Приостановлено" } ,
@@ -58,6 +68,8 @@ private void LoadTranslations()
5868 { "ContextMenu.SettingsMenuItem.Settings" , "Настройки" } ,
5969 { "ContextMenu.SettingsMenuItem.PauseOnLaunchMenuItem.PauseOnLaunch" , "Приостановить при запуске" } ,
6070 { "ContextMenu.SettingsMenuItem.ResetRememberedMenuItem.ResetRemembered" , "Сбросить запомненные параметры" } ,
71+ { "ContextMenu.SettingsMenuItem.LanguageMenuItem.Language" , "Язык" } ,
72+ { "ContextMenu.SettingsMenuItem.LanguageMenuItem.AutoDetectMenuItem.AutoDetect" , "Определять автоматически" } ,
6173 { "ContextMenu.ExitMenuItem.Exit" , "Выход" } ,
6274 { "Error.Mutex.Caption" , "Не удалось создать Mutex" } ,
6375 { "Error.Mutex.Message" , "Произошла ошибка при создании Mutex. Скорее всего, это связано с тем, что при запуске {0} Roblox уже был запущен и успел зарегистрировать свой дескриптор. Вы можете сделать следующее:" } ,
@@ -72,33 +84,29 @@ private void LoadTranslations()
7284 } ;
7385 }
7486
75- public string GetTranslation ( string key )
87+ // Retrieves the localized string for the given key
88+ public string GetLocaleString ( string key )
7689 {
77- string locale = GetLocaleWithoutRegion ( _currentLocale ) ;
78-
79- if ( _translations . ContainsKey ( locale ) && _translations [ locale ] . ContainsKey ( key ) )
90+ if ( Locales . ContainsKey ( CurrentLocale ) && Locales [ CurrentLocale ] . ContainsKey ( key ) )
8091 {
81- return _translations [ locale ] [ key ] ;
92+ return Locales [ CurrentLocale ] [ key ] ;
8293 }
8394
84- // Fallback to English if the translation is not found
85- if ( _translations . ContainsKey ( "en" ) && _translations [ "en" ] . ContainsKey ( key ) )
95+ // Fallback to English if the locale string is not found
96+ if ( Locales . ContainsKey ( "en" ) && Locales [ "en" ] . ContainsKey ( key ) )
8697 {
87- return _translations [ "en" ] [ key ] ;
98+ return Locales [ "en" ] [ key ] ;
8899 }
89100
90- // Fallback to the key if the translation is not found
101+ // Fallback to the key if the locale string is not found
91102 return key ;
92103 }
93104
94- private string GetLocaleWithoutRegion ( string locale )
105+ // Returns a stylized name for the given locale
106+ public string GetStylizedLocaleName ( string locale )
95107 {
96- int index = locale . IndexOf ( '-' ) ;
97- if ( index != - 1 )
98- {
99- return locale . Substring ( 0 , index ) ;
100- }
101- return locale ;
108+ CultureInfo cultureInfo = new CultureInfo ( locale ) ;
109+ return $ "{ cultureInfo . DisplayName } ({ cultureInfo . NativeName } )";
102110 }
103111 }
104112}
0 commit comments