✨ Add labelFormat and header options to LocaleSwitcher - #29
Merged
Merged
Conversation
Apps carrying three or more locales cannot afford the full own-language name in the navbar — "English / Français / Nederlands" eats the space the menu items need — but dropping to `showLocaleName: false` leaves a bare flag with no textual cue at all. Travel and the other apps migrating off enabel/layout-bundle all hand-rolled the same dropdown to get flag + short code back, which is exactly what this component should provide. - `labelFormat`: `name` (default, unchanged), `code` (EN) or `none`. - `header`: optional `dropdown-header` at the top of the menu, e.g. "Change language". Translate at the call site. Flags now render rounded with a subtle border and carry the locale's own-language name as `title`, so `labelFormat: 'none'` stays accessible and the flags read as deliberate chips rather than bare squares. They also render in a fixed 4:3 box with preserveAspectRatio="xMidYMid slice" instead of a 1.5rem square. The cif:* set has no single aspect ratio (cif:nl is 2:1, cif:gb is 3:2), so a square box letterboxed the flag inside its own border — the rounding and the border framed empty space rather than the flag. Width and height are both explicit because a host application's ux_icons.default_icon_attributes (commonly width/height 1em) would otherwise win and force the square back. `showLocaleName` keeps working: `labelFormat` derives from it, so passing `false` still resolves to `none`. An explicit `labelFormat` wins. The property is marked deprecated rather than removed. Also fixes the docs, which documented the parameter as `show_locale_name` while the component has always read `showLocaleName`.
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.
Problem
Apps carrying three or more locales cannot afford the full own-language name in the navbar — English / Français / Nederlands eats the space the menu items need — but the only alternative today,
showLocaleName: false, leaves a bare flag with no textual cue at all.So every app migrating off
enabel/layout-bundlehand-rolls the same dropdown to get flag + short code + a "Change language" heading back. That is exactly what this component should provide.There is also a rendering bug: flags were forced into a
1.5remsquare. Thecif:*set has no single aspect ratio (cif:nlis 2:1,cif:gbis 3:2), so the flag was letterboxed inside its own box and the border framed empty space rather than the flag:Changes
labelFormat—name(default, unchanged),code(EN) ornone(flag only).header— optionaldropdown-headerat the top of the menu, e.g.'Change language'. Translate at the call site. Defaults tonull, so nothing renders unless asked.title, solabelFormat: 'none'stays accessible.1.5rem × 1.125rem) withpreserveAspectRatio="xMidYMid slice". Both width and height are explicit: a host application'sux_icons.default_icon_attributes(commonlywidth/height: 1em) otherwise wins and forces the square back —width: autois not enough.{{ component('Enabel:Ux:LocaleSwitcher', { locales: enabled_locales, labelFormat: 'code', header: 'navigation.language.change'|trans, }) }}Renders
🇬🇧 ENin the navbar, and a dropdown headed Change language listing🇫🇷 FRand🇳🇱 NL.Backward compatibility
showLocaleNamekeeps working —labelFormatis derived from it, so a call site passingfalsestill resolves tonone. An explicitlabelFormatalways wins. The property is marked@deprecatedrather than removed, and its existing tests still pass untouched.The only visual change for callers who pass nothing is the flag styling (correct aspect ratio, rounded, bordered,
title); the label still defaults to the own-language name.Verification
vendor/bin/phpunit— 253 tests, 684 assertions, green (7 newLocaleSwitchertests covering the derivation, the precedence rule, and the rejected values)./en,/frand/nl: verified the emitted DOM carriestitleper locale, therounded border border-dark-subtleclasses, hrefs/frand/nl, the heading, and a 24×18 flag box.Drive-by
The docs documented the parameter as
show_locale_name; the component has always readshowLocaleName.