Skip to content

Commit 5561bca

Browse files
committed
add debug code to find missing translations
1 parent 45e5a2f commit 5561bca

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

src/avrdudess/Language.cs

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ public struct SupportedEntry
2323
[XmlAttribute] public string file;
2424
}
2525

26+
[XmlArray("supported")]
27+
[XmlArrayItem("x")]
28+
public List<SupportedEntry> Supported = new List<SupportedEntry>();
29+
2630
#if DEBUG
2731
public struct KeyEntry
2832
{
2933
[XmlAttribute] public string name;
3034
}
31-
#endif
32-
33-
[XmlArray("supported")]
34-
[XmlArrayItem("x")]
35-
public List<SupportedEntry> Supported = new List<SupportedEntry>();
3635

37-
#if DEBUG
3836
[XmlArray("keys")]
3937
[XmlArrayItem("k")]
4038
public List<KeyEntry> Expectedkeys = new List<KeyEntry>();
@@ -115,19 +113,6 @@ private void LoadLanguage(string langsDir, string language)
115113
throw new Exception($"Duplicate translation key: {t.name}");
116114
translations.Add(t.name, t.str);
117115
});
118-
#if DEBUG
119-
foreach (var k in expectedKeys.Keys)
120-
{
121-
if (!translations.ContainsKey(k))
122-
Util.consoleWarning($"Missing translation key: {k}");
123-
}
124-
125-
foreach (var k in translations.Keys)
126-
{
127-
if (!expectedKeys.Contains(k))
128-
Util.consoleWarning($"Unexpected translation key: {k}");
129-
}
130-
#endif
131116
}
132117

133118
public void Load()
@@ -142,6 +127,10 @@ public void Load()
142127
{
143128
MsgBox.error($"Error loading languages:{Environment.NewLine}{ex.Message}");
144129
}
130+
131+
#if DEBUG
132+
Debug(langsDir);
133+
#endif
145134
}
146135

147136
public string get(string key) // TODO get -> Get (use indexer instead?)
@@ -158,5 +147,41 @@ public string get(string key) // TODO get -> Get (use indexer instead?)
158147

159148
return str;
160149
}
150+
151+
#if DEBUG
152+
// Process all translation files and make sure they all have the translations keys as defined in _meta.xml
153+
private void Debug(string langsDir)
154+
{
155+
foreach (var l in languages)
156+
{
157+
var dbgTranslations = new Dictionary<string, string>();
158+
var file = $"{l.Key}.xml";
159+
160+
Util.consoleWarning($"{file}: Checking...");
161+
162+
var langFile = Path.Combine(langsDir, file);
163+
var langData = new XmlFile<TranslationData>(langFile).Read();
164+
langData.Translations.ForEach(t =>
165+
{
166+
if (dbgTranslations.ContainsKey(t.name))
167+
Util.consoleError($"{file}: Duplicate translation key: {t.name}");
168+
else
169+
dbgTranslations.Add(t.name, t.str);
170+
});
171+
172+
foreach (var k in expectedKeys.Keys)
173+
{
174+
if (!dbgTranslations.ContainsKey(k))
175+
Util.consoleError($"{file}: Missing translation key: {k}");
176+
}
177+
178+
foreach (var k in dbgTranslations.Keys)
179+
{
180+
if (!expectedKeys.Contains(k))
181+
Util.consoleError($"{file}: Unexpected translation key: {k}");
182+
}
183+
}
184+
}
185+
#endif
161186
}
162187
}

src/avrdudess/Languages/Traditional_Chinese(Taiwan).xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<string name="ABOUT">關於</string>
7474
<string name="SELECTPROG">選擇燒錄器...</string>
7575
<string name="SELECTMCU">選擇MCU...</string>
76-
<string name="FUSEREADFAIL">無法讀取熔絲位/加密位</string>
76+
<string name="FUSELOCKREADFAIL">無法讀取熔絲位/加密位</string>
7777
<string name="READINGFUSES">讀取熔絲位...</string>
7878
<string name="READINGLOCKBITS">讀取加密位...</string>
7979
<string name="WRITINGINGFUSES">寫入熔絲位...</string>

0 commit comments

Comments
 (0)