@@ -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}
0 commit comments