@@ -139,4 +139,81 @@ void main() {
139139 expect (result, 'No selection chosen' );
140140 });
141141 });
142+
143+ group ('Placeholders without metadata' , () {
144+ Extractor extractor = Extractor ();
145+
146+ test ('should infer and substitute simple placeholders without @metadata' ,
147+ () {
148+ var otaArb = {
149+ "@@locale" : "en" ,
150+ "pageInfo" : "Page {current} of {total}" ,
151+ };
152+
153+ final result = extractor.getText (
154+ 'en' ,
155+ AppResourceBundle (otaArb),
156+ 'pageInfo' ,
157+ {'current' : 3 , 'total' : 10 },
158+ );
159+
160+ expect (result, 'Page 3 of 10' );
161+ });
162+
163+ test ('should handle multiple placeholders without metadata' , () {
164+ var otaArb = {
165+ "@@locale" : "en" ,
166+ "greeting" : "Hello {userName}, you have {count} messages" ,
167+ };
168+
169+ final result = extractor.getText (
170+ 'en' ,
171+ AppResourceBundle (otaArb),
172+ 'greeting' ,
173+ {'userName' : 'John' , 'count' : 10 },
174+ );
175+
176+ expect (result, 'Hello John, you have 10 messages' );
177+ });
178+
179+ test ('should handle mixed: some placeholders with metadata, some without' ,
180+ () {
181+ var mixedArb = {
182+ "@@locale" : "en" ,
183+ "greeting" : "Hello {userName}, you are {age} years old" ,
184+ "@greeting" : {
185+ "placeholders" : {
186+ "userName" : {"type" : "String" }
187+ }
188+ }
189+ };
190+
191+ final result = extractor.getText (
192+ 'en' ,
193+ AppResourceBundle (mixedArb),
194+ 'greeting' ,
195+ {'userName' : 'Alice' , 'age' : 25 },
196+ );
197+
198+ expect (result, 'Hello Alice, you are 25 years old' );
199+ });
200+
201+ test ('should infer placeholders from select expressions without metadata' ,
202+ () {
203+ var selectArb = {
204+ "@@locale" : "en" ,
205+ "gender" : "{choice, select, male{He} female{She} other{They}}" ,
206+ };
207+
208+ final bundle = AppResourceBundle (selectArb);
209+ final message = Message (bundle, 'gender' , false );
210+
211+ expect (message.placeholders.containsKey ('choice' ), true );
212+ expect (message.placeholders['choice' ]? .isSelect, true );
213+
214+ final resultMale =
215+ extractor.getText ('en' , bundle, 'gender' , {'choice' : 'male' });
216+ expect (resultMale, 'He' );
217+ });
218+ });
142219}
0 commit comments