@@ -59,7 +59,7 @@ public async Task CollectI18NKeys()
5959 Console . WriteLine ( $ " { counter : ###,###} files processed, { allI18NContent . Count : ###,###} keys found.") ;
6060
6161 Console . Write ( "- Creating Lua code ..." ) ;
62- var luaCode = this . ExportToLuaTable ( allI18NContent ) ;
62+ var luaCode = this . ExportToLuaAssignments ( allI18NContent ) ;
6363
6464 // Build the path, where we want to store the Lua code:
6565 var luaPath = Path . Join ( cwd , "Assistants" , "I18N" , "allTexts.lua" ) ;
@@ -69,134 +69,68 @@ public async Task CollectI18NKeys()
6969
7070 Console . WriteLine ( " done." ) ;
7171 }
72-
73- private string ExportToLuaTable ( Dictionary < string , string > keyValuePairs )
72+
73+ private string ExportToLuaAssignments ( Dictionary < string , string > keyValuePairs )
7474 {
75- // Collect all nodes:
76- var root = new Dictionary < string , object > ( ) ;
77-
78- //
79- // Split all collected keys into nodes:
80- //
81- foreach ( var key in keyValuePairs . Keys . Order ( ) )
82- {
83- var path = key . Split ( '.' ) ;
84- var current = root ;
85- for ( var i = 0 ; i < path . Length - 1 ; i ++ )
86- {
87- // We ignore the AISTUDIO segment of the path:
88- if ( path [ i ] == "AISTUDIO" )
89- continue ;
90-
91- if ( ! current . TryGetValue ( path [ i ] , out var child ) || child is not Dictionary < string , object > childDict )
92- {
93- childDict = new Dictionary < string , object > ( ) ;
94- current [ path [ i ] ] = childDict ;
95- }
96-
97- current = childDict ;
98- }
99-
100- current [ path . Last ( ) ] = keyValuePairs [ key ] ;
101- }
75+ var sb = new StringBuilder ( ) ;
10276
103- //
104- // Inner method to build Lua code from the collected nodes:
105- //
106- void ToLuaTable ( StringBuilder sb , Dictionary < string , object > innerDict , int indent = 0 )
107- {
108- sb . AppendLine ( "{" ) ;
109- var prefix = new string ( ' ' , indent * 4 ) ;
110- foreach ( var kvp in innerDict )
111- {
112- if ( kvp . Value is Dictionary < string , object > childDict )
113- {
114- sb . Append ( $ "{ prefix } { kvp . Key } ") ;
115- sb . Append ( " = " ) ;
116-
117- ToLuaTable ( sb , childDict , indent + 1 ) ;
118- }
119- else if ( kvp . Value is string s )
120- {
121- sb . AppendLine ( $ "{ prefix } -- { s . Trim ( ) . Replace ( "\n " , " " ) } ") ;
122- sb . Append ( $ "{ prefix } { kvp . Key } ") ;
123- sb . Append ( " = " ) ;
124- sb . Append ( $ """
125- "{ s } "
126- """ ) ;
127- sb . AppendLine ( "," ) ;
128- sb . AppendLine ( ) ;
129- }
130- }
77+ // Add the mandatory plugin metadata:
78+ sb . AppendLine (
79+ """
80+ -- The ID for this plugin:
81+ ID = "77c2688a-a68f-45cc-820e-fa8f3038a146"
13182
132- sb . AppendLine ( prefix + "}," ) ;
133- sb . AppendLine ( ) ;
134- }
135-
136- //
137- // Write the Lua code:
138- //
139- var sbLua = new StringBuilder ( ) ;
140-
141- // To make the later parsing easier, we add the mandatory plugin
142- // metadata:
143- sbLua . AppendLine (
144- """
145- -- The ID for this plugin:
146- ID = "77c2688a-a68f-45cc-820e-fa8f3038a146"
147-
148- -- The icon for the plugin:
149- ICON_SVG = ""
150-
151- -- The name of the plugin:
152- NAME = "Collected I18N keys"
153-
154- -- The description of the plugin:
155- DESCRIPTION = "This plugin is not meant to be used directly. Its a collection of all I18N keys found in the project."
156-
157- -- The version of the plugin:
158- VERSION = "1.0.0"
159-
160- -- The type of the plugin:
161- TYPE = "LANGUAGE"
162-
163- -- The authors of the plugin:
164- AUTHORS = {"MindWork AI Community"}
165-
166- -- The support contact for the plugin:
167- SUPPORT_CONTACT = "MindWork AI Community"
168-
169- -- The source URL for the plugin:
170- SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio"
171-
172- -- The categories for the plugin:
173- CATEGORIES = { "CORE" }
174-
175- -- The target groups for the plugin:
176- TARGET_GROUPS = { "EVERYONE" }
177-
178- -- The flag for whether the plugin is maintained:
179- IS_MAINTAINED = true
180-
181- -- When the plugin is deprecated, this message will be shown to users:
182- DEPRECATION_MESSAGE = ""
183-
184- -- The IETF BCP 47 tag for the language. It's the ISO 639 language
185- -- code followed by the ISO 3166-1 country code:
186- IETF_TAG = "en-US"
187-
188- -- The language name in the user's language:
189- LANG_NAME = "English (United States)"
190-
191- """ ) ;
192-
193- sbLua . Append ( "UI_TEXT_CONTENT = " ) ;
194- if ( root [ "UI_TEXT_CONTENT" ] is Dictionary < string , object > dict )
195- ToLuaTable ( sbLua , dict ) ;
83+ -- The icon for the plugin:
84+ ICON_SVG = ""
85+
86+ -- The name of the plugin:
87+ NAME = "Collected I18N keys"
88+
89+ -- The description of the plugin:
90+ DESCRIPTION = "This plugin is not meant to be used directly. Its a collection of all I18N keys found in the project."
91+
92+ -- The version of the plugin:
93+ VERSION = "1.0.0"
94+
95+ -- The type of the plugin:
96+ TYPE = "LANGUAGE"
97+
98+ -- The authors of the plugin:
99+ AUTHORS = {"MindWork AI Community"}
100+
101+ -- The support contact for the plugin:
102+ SUPPORT_CONTACT = "MindWork AI Community"
103+
104+ -- The source URL for the plugin:
105+ SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio"
106+
107+ -- The categories for the plugin:
108+ CATEGORIES = { "CORE" }
109+
110+ -- The target groups for the plugin:
111+ TARGET_GROUPS = { "EVERYONE" }
112+
113+ -- The flag for whether the plugin is maintained:
114+ IS_MAINTAINED = true
115+
116+ -- When the plugin is deprecated, this message will be shown to users:
117+ DEPRECATION_MESSAGE = ""
118+
119+ -- The IETF BCP 47 tag for the language. It's the ISO 639 language
120+ -- code followed by the ISO 3166-1 country code:
121+ IETF_TAG = "en-US"
122+
123+ -- The language name in the user's language:
124+ LANG_NAME = "English (United States)"
125+
126+ """
127+ ) ;
196128
197- return sbLua . ToString ( ) ;
129+ // Add the UI_TEXT_CONTENT table:
130+ LuaTable . Create ( ref sb , "UI_TEXT_CONTENT" , keyValuePairs ) ;
131+ return sb . ToString ( ) ;
198132 }
199-
133+
200134 private List < string > FindAllTextTags ( ReadOnlySpan < char > fileContent )
201135 {
202136 const string START_TAG = """
0 commit comments