MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / ApplyLanguagePreference

Method ApplyLanguagePreference

ui/App.xaml.cs:23–53  ·  view source on GitHub ↗

Reads the language preference from settings.json and sets the UI culture before any XAML is loaded. Falls back to system locale if missing or "system".

()

Source from the content-addressed store, hash-verified

21 /// before any XAML is loaded. Falls back to system locale if missing or "system".
22 /// </summary>
23 private static void ApplyLanguagePreference()
24 {
25 try
26 {
27 var configDir = Path.Combine(
28 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
29 "CloudRedirect");
30 var settingsPath = Path.Combine(configDir, "settings.json");
31
32 if (!File.Exists(settingsPath)) return;
33
34 var json = File.ReadAllText(settingsPath);
35 using var doc = JsonDocument.Parse(json);
36
37 if (!doc.RootElement.TryGetProperty("language", out var langProp))
38 return;
39
40 var lang = langProp.GetString();
41 if (string.IsNullOrEmpty(lang) || lang == "system")
42 return;
43
44 var culture = new CultureInfo(lang);
45 Thread.CurrentThread.CurrentUICulture = culture;
46 CultureInfo.DefaultThreadCurrentUICulture = culture;
47 }
48 catch
49 {
50 // If settings.json is missing, malformed, or the culture code is invalid,
51 // silently fall back to the system default.
52 }
53 }
54}

Callers

nothing calls this directly

Calls 1

ParseMethod · 0.80

Tested by

no test coverage detected