Localize the GUI chrome - #25
Merged
Merged
Conversation
Second half of localization. Covers the 194 literal strings across the nine XAML schemas, which the first pass left untouched. Substitution happens on the markup before it is parsed rather than by walking the loaded window. A logical tree does not contain text that sits inside a Style or a template: MainWindow carries 113 literal strings but exposes only 99 as logical tree nodes, so a tree walk would have silently missed fourteen of them. Chrome entries are keyed by their English text. Keying by position broke the moment markup was reordered, and only 46 percent of the strings sit on an x:Name element, so keying by element name would have meant adding identifiers to 103 elements across nine files. A source-string key is stable under reordering, shows the translator the original, and resolves to itself when untranslated. Values are read XML-decoded and written back XML-encoded, so a translation containing an ampersand or an angle bracket cannot corrupt the markup. Attribute values that open with a brace are skipped because they are bindings rather than text. All nine load sites now call Get-LocalizedXaml instead of reading the schema directly, which keeps this to one integration point. Two things the extraction had to handle. Forty-one values are icon glyph character references rather than text and are excluded. Three phrases differ only in capitalization, which ConvertFrom-Json cannot represent as distinct properties, so they share one entry and resolve through case-insensitive property lookup. Verified by loading every schema through XamlReader with all 123 entries translated: all nine parse, 153 substitutions land, and the 192 bindings in MainWindow are untouched. A test asserts every translatable schema string has a catalogue entry, so a new string without one fails the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second half of localization for v3.5.0. Covers the 194 literal strings across the nine XAML schemas that #24 left untouched.
Substitution before parse, not a tree walk
My first instinct was to walk the loaded window and set properties. Measuring killed it: a logical tree does not contain text inside a
Styleor a template, and MainWindow carries 113 literal strings but exposes only 99 as logical tree nodes. A tree walk would have silently missed fourteen. Substituting on the markup beforeXamlReaderparses it reaches all of them.Keying
Source-string keys, i.e. the key is the English text.
Content_01) break the moment anyone reorders markup. I built that first and threw it away.x:Namekeys would work, but only 46% of the strings sit on a named element, so it meant adding identifiers to 103 elements across nine files.Values are read XML-decoded and written back XML-encoded, so a translation containing
&or<cannot corrupt the markup. Attribute values opening with a brace are skipped as bindings.All nine load sites now call
Get-LocalizedXamlrather than reading the schema directly, keeping this to one integration point.Two extraction problems
), not text. Excluded. This is whySharedStyles.xamlgets zero substitutions - all three of its strings are glyphs or aTemplateBinding.Restore backup/Restore Backup,Current User/Current user).ConvertFrom-Jsoncannot hold those as distinct PSCustomObject properties and threw. They now share one entry and resolve through case-insensitive property lookup, which I verified rather than assumed.Verification
Loaded every schema through
XamlReaderheadlessly with all 123 entries translated:Also confirmed a translation containing
&,<and a double quote is encoded correctly, and that MainWindow's 192 bindings are identical before and after.A test asserts every translatable schema string has a catalogue entry, so adding a string without one fails the build. 23 localization tests total.
Static validation passes (112 files), standalone rebuilt and parse-checked.
Not verified: the GUI has not been displayed. Windows are constructed and parsed, which is the step substitution could break, but nothing has been rendered on screen.