|
18 | 18 | { |
19 | 19 | try |
20 | 20 | { |
21 | | - // 🔍 جستجوی تمام Session Keys حاوی 'theme' |
| 21 | + // Search all session keys containing 'theme' |
22 | 22 | var detectedTheme = await jsRuntime.InvokeAsync<string>("eval", @" |
23 | 23 | (function() { |
24 | | - // اولویت 1: سشن خود کامپوننت |
| 24 | + // Priority 1: component's own session |
25 | 25 | const ownTheme = localStorage.getItem('json-viewer-theme'); |
26 | 26 | if (ownTheme) return ownTheme; |
27 | 27 |
|
28 | | - // اولویت 2: جستجو در تمام keys |
| 28 | + // Priority 2: search all keys |
29 | 29 | for (let i = 0; i < localStorage.length; i++) { |
30 | 30 | const key = localStorage.key(i); |
31 | 31 | if (key && (key.toLowerCase().includes('theme'))) { |
32 | 32 | const value = localStorage.getItem(key); |
33 | | - // فقط مقادیر معتبر |
| 33 | + // Only valid values |
34 | 34 | if (value === 'light' || value === 'Light' || |
35 | 35 | value === 'dark' || value === 'Dark') { |
36 | 36 | return value; |
37 | 37 | } |
38 | 38 | } |
39 | 39 | } |
40 | 40 |
|
41 | | - // پیشفرض |
| 41 | + // Default |
42 | 42 | return 'light'; |
43 | 43 | })() |
44 | 44 | "); |
45 | 45 |
|
46 | | - // Normalize کردن مقدار |
| 46 | + // Normalize value |
47 | 47 | if (!string.IsNullOrEmpty(detectedTheme)) |
48 | 48 | { |
49 | 49 | IsDark = detectedTheme.ToLower() == "dark"; |
50 | 50 |
|
51 | | - // ذخیره در سشن خود کامپوننت |
| 51 | + // Save in component's own session |
52 | 52 | await jsRuntime.InvokeVoidAsync("localStorage.setItem", |
53 | 53 | "json-viewer-theme", IsDark ? "dark" : "light"); |
54 | 54 |
|
55 | | - // اطلاع به JsonViewer |
| 55 | + // Notify JsonViewer |
56 | 56 | if (OnThemeChanged.HasDelegate) |
57 | 57 | { |
58 | 58 | await OnThemeChanged.InvokeAsync(IsDark); |
|
62 | 62 | catch (Exception ex) |
63 | 63 | { |
64 | 64 | Console.WriteLine($"Error loading theme: {ex.Message}"); |
65 | | - IsDark = false; // پیشفرض light |
| 65 | + IsDark = false; // Default light |
66 | 66 | } |
67 | 67 | } |
68 | 68 |
|
|
73 | 73 |
|
74 | 74 | try |
75 | 75 | { |
76 | | - // 🔄 آپدیت تمام Session Keys حاوی 'theme' |
| 76 | + // Update all session keys containing 'theme' |
77 | 77 | await jsRuntime.InvokeVoidAsync("eval", $@" |
78 | 78 | (function() {{ |
79 | | - // لیست تمام keys حاوی theme |
| 79 | + // List all keys containing theme |
80 | 80 | const themeKeys = []; |
81 | 81 | for (let i = 0; i < localStorage.length; i++) {{ |
82 | 82 | const key = localStorage.key(i); |
|
85 | 85 | }} |
86 | 86 | }} |
87 | 87 |
|
88 | | - // آپدیت همه |
| 88 | + // Update all |
89 | 89 | themeKeys.forEach(key => {{ |
90 | 90 | localStorage.setItem(key, '{themeValue}'); |
91 | 91 | }}); |
92 | 92 |
|
93 | | - // اگر سشن json-viewer-theme وجود نداشت، بسازش |
| 93 | + // If json-viewer-theme session doesn't exist, create it |
94 | 94 | if (!themeKeys.includes('json-viewer-theme')) {{ |
95 | 95 | localStorage.setItem('json-viewer-theme', '{themeValue}'); |
96 | 96 | }} |
|
102 | 102 | Console.WriteLine($"Error syncing theme: {ex.Message}"); |
103 | 103 | } |
104 | 104 |
|
105 | | - // اطلاع به JsonViewer |
| 105 | + // Notify JsonViewer |
106 | 106 | if (OnThemeChanged.HasDelegate) |
107 | 107 | { |
108 | 108 | await OnThemeChanged.InvokeAsync(newTheme); |
|
111 | 111 |
|
112 | 112 | private string GetIconName() => IsDark ? "sun-fill" : "moon-fill"; |
113 | 113 |
|
114 | | - private string GetTooltip() => IsDark ? "Switch to Light Theme ☀️" : "Switch to Dark Theme 🌙"; |
| 114 | + private string GetTooltip() => IsDark ? "Switch to Light Theme" : "Switch to Dark Theme"; |
115 | 115 |
|
116 | 116 | private string GetThemeClass() => IsDark ? "theme-dark" : "theme-light"; |
117 | 117 | } |
|
0 commit comments