Skip to content

Commit f77f14b

Browse files
committed
Improve code quality
1 parent ac7da2d commit f77f14b

File tree

1 file changed

+62
-31
lines changed

1 file changed

+62
-31
lines changed

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ public class Internationalization
2727
private const string DefaultFile = "en.xaml";
2828
private const string Extension = ".xaml";
2929
private readonly Settings _settings;
30-
private readonly List<string> _languageDirectories = new();
31-
private readonly List<ResourceDictionary> _oldResources = new();
30+
private readonly List<string> _languageDirectories = [];
31+
private readonly List<ResourceDictionary> _oldResources = [];
3232
private static string SystemLanguageCode;
3333

3434
public Internationalization(Settings settings)
3535
{
3636
_settings = settings;
3737
}
3838

39+
#region Initialization
40+
41+
/// <summary>
42+
/// Initialize the system language code based on the current culture.
43+
/// </summary>
3944
public static void InitSystemLanguageCode()
4045
{
4146
var availableLanguages = AvailableLanguages.GetAvailableLanguages();
@@ -133,6 +138,10 @@ private void LoadDefaultLanguage()
133138
_oldResources.Clear();
134139
}
135140

141+
#endregion
142+
143+
#region Change Language
144+
136145
/// <summary>
137146
/// Change language during runtime. Will change app language and plugin language & save settings.
138147
/// </summary>
@@ -213,6 +222,10 @@ public static void ChangeCultureInfo(string languageCode)
213222
thread.CurrentUICulture = currentCulture;
214223
}
215224

225+
#endregion
226+
227+
#region Prompt Pinyin
228+
216229
public bool PromptShouldUsePinyin(string languageCodeToSet)
217230
{
218231
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);
@@ -233,6 +246,10 @@ public bool PromptShouldUsePinyin(string languageCodeToSet)
233246
return true;
234247
}
235248

249+
#endregion
250+
251+
#region Language Resources Management
252+
236253
private void RemoveOldLanguageFiles()
237254
{
238255
var dicts = Application.Current.Resources.MergedDictionaries;
@@ -268,13 +285,51 @@ private void LoadLanguage(Language language)
268285
}
269286
}
270287

288+
private static string LanguageFile(string folder, string language)
289+
{
290+
if (Directory.Exists(folder))
291+
{
292+
var path = Path.Combine(folder, language);
293+
if (File.Exists(path))
294+
{
295+
return path;
296+
}
297+
else
298+
{
299+
API.LogError(ClassName, $"Language path can't be found <{path}>");
300+
var english = Path.Combine(folder, DefaultFile);
301+
if (File.Exists(english))
302+
{
303+
return english;
304+
}
305+
else
306+
{
307+
API.LogError(ClassName, $"Default English Language path can't be found <{path}>");
308+
return string.Empty;
309+
}
310+
}
311+
}
312+
else
313+
{
314+
return string.Empty;
315+
}
316+
}
317+
318+
#endregion
319+
320+
#region Available Languages
321+
271322
public List<Language> LoadAvailableLanguages()
272323
{
273324
var list = AvailableLanguages.GetAvailableLanguages();
274325
list.Insert(0, new Language(Constant.SystemLanguageCode, AvailableLanguages.GetSystemTranslation(SystemLanguageCode)));
275326
return list;
276327
}
277328

329+
#endregion
330+
331+
#region Get Translations
332+
278333
public static string GetTranslation(string key)
279334
{
280335
var translation = Application.Current.TryFindResource(key);
@@ -289,6 +344,10 @@ public static string GetTranslation(string key)
289344
}
290345
}
291346

347+
#endregion
348+
349+
#region Update Metadata
350+
292351
public static void UpdatePluginMetadataTranslations()
293352
{
294353
// Update plugin metadata name & description
@@ -308,34 +367,6 @@ public static void UpdatePluginMetadataTranslations()
308367
}
309368
}
310369

311-
private static string LanguageFile(string folder, string language)
312-
{
313-
if (Directory.Exists(folder))
314-
{
315-
var path = Path.Combine(folder, language);
316-
if (File.Exists(path))
317-
{
318-
return path;
319-
}
320-
else
321-
{
322-
API.LogError(ClassName, $"Language path can't be found <{path}>");
323-
var english = Path.Combine(folder, DefaultFile);
324-
if (File.Exists(english))
325-
{
326-
return english;
327-
}
328-
else
329-
{
330-
API.LogError(ClassName, $"Default English Language path can't be found <{path}>");
331-
return string.Empty;
332-
}
333-
}
334-
}
335-
else
336-
{
337-
return string.Empty;
338-
}
339-
}
370+
#endregion
340371
}
341372
}

0 commit comments

Comments
 (0)