@@ -166,12 +166,27 @@ class SimSlotItem {
166166 String toString () => 'SimSlotItem($slot , $material x$count )' ;
167167}
168168
169+ /// The lang-key prefix HoloUI shipped before the Gloss merger renamed the
170+ /// preview keys to [kPreviewLangPrefix] . Gloss's importer rewrites these on
171+ /// import; the editor resolves them for display and warns in validation.
172+ const String kLegacyPreviewLangPrefix = 'holoui.preview.' ;
173+
174+ /// The current preview lang-key prefix, matching `GlossMessages.java` .
175+ const String kPreviewLangPrefix = 'gloss.preview.' ;
176+
177+ /// The `gloss.preview.*` twin of a legacy `holoui.preview.*` id, or null when
178+ /// [key] does not carry the legacy prefix.
179+ String ? previewRenamedLangKey (String key) =>
180+ key.startsWith (kLegacyPreviewLangPrefix)
181+ ? '$kPreviewLangPrefix ${key .substring (kLegacyPreviewLangPrefix .length )}'
182+ : null ;
183+
169184/// The English message templates `lang()` renders against.
170185///
171186/// `web/assets/catalog/preview-lang-en.json` is generated from the plugin's
172- /// `HoloMessages .java` by `tool/extract_preview_lang.dart` ; only the templates'
173- /// placeholder names and order matter, which is why the snapshot has to come
174- /// from the Java constants rather than a locale file.
187+ /// `GlossMessages .java` by `tool/extract_preview_lang.dart` ; only the
188+ /// templates' placeholder names and order matter, which is why the snapshot
189+ /// has to come from the Java constants rather than a locale file.
175190class PreviewLangCatalog {
176191 const PreviewLangCatalog (this .messages);
177192
@@ -186,6 +201,16 @@ class PreviewLangCatalog {
186201
187202 String ? template (String key) => messages[key];
188203
204+ /// [template] for [key] , falling back to its `gloss.preview.*` twin when
205+ /// [key] still carries the legacy `holoui.preview.*` prefix — the same
206+ /// rename Gloss's importer applies to a whole document on import.
207+ String ? _resolvedTemplate (String key) {
208+ final String ? direct = messages[key];
209+ if (direct != null ) return direct;
210+ final String ? renamed = previewRenamedLangKey (key);
211+ return renamed == null ? null : messages[renamed];
212+ }
213+
189214 /// Decodes `{"messages":{"<id>":"<template>"}}` . Never throws: a missing or
190215 /// malformed snapshot degrades to [empty] , and every key then renders as
191216 /// itself — which is also what the plugin does for an id its catalog does not
@@ -206,15 +231,16 @@ class PreviewLangCatalog {
206231 /// Renders [key] with [args] bound positionally onto the template's own
207232 /// placeholder names: argument 1 fills the first `{name}` , argument 2 the
208233 /// second, and so on. That is what lets a document write
209- /// `lang("holoui .preview.state.smelting_item", item, percent)` and get
234+ /// `lang("gloss .preview.state.smelting_item", item, percent)` and get
210235 /// `Smelting Iron Ore 42%` out of `Smelting {item} {percent}%` .
211236 ///
212- /// An unknown id renders as itself, arguments past the last placeholder go
213- /// unused, and a placeholder no argument reached stays literal — the lenient
214- /// rendering `HoloLocalization.renderTemplate` performs, which is also the
215- /// path the plugin's own golden snapshots were captured through.
237+ /// An unknown id renders as itself (a legacy `holoui.preview.*` id first
238+ /// tries its `gloss.preview.*` twin), arguments past the last placeholder
239+ /// go unused, and a placeholder no argument reached stays literal — the
240+ /// lenient rendering `GlossLocalization.renderTemplate` performs, which is
241+ /// also the path the plugin's own golden snapshots were captured through.
216242 String render (String key, List <Object ?> args) {
217- final String template = messages[ key] ?? key;
243+ final String template = _resolvedTemplate ( key) ?? key;
218244 if (args.isEmpty) return template;
219245 final List <String > names = orderedPlaceholders (template);
220246 final Map <String , String > bound = < String , String > {};
0 commit comments