Skip to content

refactor: Update globe button to modify lang in URL paths 🌋#712

Open
darcywong00 wants to merge 12 commits intoepic/i18n-url-schemefrom
fix/rebuild-globe
Open

refactor: Update globe button to modify lang in URL paths 🌋#712
darcywong00 wants to merge 12 commits intoepic/i18n-url-schemefrom
fix/rebuild-globe

Conversation

@darcywong00
Copy link
Copy Markdown
Contributor

@darcywong00 darcywong00 commented Apr 23, 2026

Part of #696

Since i18n redirects /file to <lang>/file, this updates the globe key button to modify the BCP-47 language tag in the URL. The initial implementation of the globe key set the language tag as a query parameter.

Additional changes:

  • Replaces en in .htaccess with a basic regex to allow language-script-region BCP-47 triplets. To keep things simple, intentionally not using the full-blown regex in
    public static function validate_bcp47($bcp47, $default = null) {
    if($bcp47 === null) return $default;
    $bcp47 = trim(strtolower($bcp47));
    // RegEx from https://stackoverflow.com/questions/7035825/regular-expression-for-a-language-tag-as-defined-by-bcp47, https://stackoverflow.com/a/34775980/1836776
    if(preg_match("/^(?<grandfathered>(?:en-GB-oed|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|t(?:a[oy]|su))|sgn-(?:BE-(?:FR|NL)|CH-DE))|(?:art-lojban|cel-gaulish|no-(?:bok|nyn)|zh-(?:guoyu|hakka|min(?:-nan)?|xiang)))|(?:(?<language>(?:[A-Za-z]{2,3}(?:-(?<extlang>[A-Za-z]{3}(?:-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(?:-(?<script>[A-Za-z]{4}))?(?:-(?<region>[A-Za-z]{2}|[0-9]{3}))?(?:-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(?:-(?<extension>[0-9A-WY-Za-wy-z](?:-[A-Za-z0-9]{2,8})+))*)(?:-(?<privateUse>x(?:-[A-Za-z0-9]{1,8})+))?$/Di",
    $bcp47)) {
    return $bcp47;
    }
    return $default;
    }
  • Globe key changes:
    • Update to always be visible (previously implemented to only appear on pages that contained localization)
    • Change phone menu list description from "Keyboard Search UI" to "Display in:"
    • Add (Khmer) to language name

Screenshots

phone layout
Screenshot_2026-04-28_11-08-15

desktop layout
Screenshot_2026-04-28_11-08-37

Test-bot: skip

@darcywong00 darcywong00 added this to the A19S27 milestone Apr 23, 2026
@darcywong00 darcywong00 requested a review from mcdurdin April 23, 2026 07:09
@keymanapp-test-bot
Copy link
Copy Markdown

keymanapp-test-bot Bot commented Apr 23, 2026

User Test Results

Test specification and instructions

User tests are not required

Comment thread _includes/2020/templates/Menu.php Outdated
// Note: Validate::validate_bcp47 differs from regex in .htaccess
if (!empty($parts['path'])) {
$path = explode("/", $parts['path']);
if ($path[1] != null && class_exists('\\Keyman\\Site\\com\\keyman\\Validation') &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 404.php was throwing uncaught error of \Keyman\Site\com\keyman\Validation class not being defined 😕

@keyman-server keyman-server modified the milestones: A19S27, A19S28 Apr 24, 2026
@darcywong00 darcywong00 marked this pull request as ready for review April 28, 2026 01:29
* Change from "Keyboard Search UI" to "Display in:"
* Also add Khmer English name
Comment thread .github/workflows/ci.yml
Comment on lines +44 to +45
npx broken-link-checker http://localhost:8053/_test --recursive --ordered ---host-requests 50 -e --filter-level 3 \
--exclude '*/donate' --exclude '*/de/*' --exclude '*/es/*' --exclude '*/fr/*' --exclude '*/ipa/*' --exclude '*/km/*' --exclude '*lang=*' --exclude '*/lao/*' | tee blc.log
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluding all locales except en will not scale well. I wonder if there is a better way -- can we build a scripted filter using the api published at broken-link-checker?

Comment thread _includes/2020/templates/Menu.php Outdated
Comment on lines +79 to +82
'de' => array(Menu::change_ui_language('de'), 'Deutsch'),
'es' => array(Menu::change_ui_language('es'), 'Español'),
'fr' => array(Menu::change_ui_language('fr'), 'Français'),
'km' => array(Menu::change_ui_language('km'), 'ខ្មែរ')
'km' => array(Menu::change_ui_language('km'), 'ខ្មែរ (Khmer)')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be extracted to a different file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored the list of language names to Locale.php in e9e548d

Base automatically changed from fix/lang/htaccess to epic/i18n-url-scheme April 29, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants