-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Localize keyboards index page 📡 #521
feat: Localize keyboards index page 📡 #521
Conversation
_includes/locale/Locale.php
Outdated
public static function localize($domain, $strings) { | ||
foreach(Locale::CROWDIN_LOCALES as $l) { | ||
if ($l == Locale::DEFAULT_LOCALE) { | ||
// Skip English | ||
continue; | ||
} | ||
|
||
bindtextdomain("$domain-$l", __DIR__); | ||
} | ||
|
||
$previousTextDomain = textdomain(NULL); | ||
Locale::setTextDomain($domain); | ||
|
||
$result = []; | ||
foreach($strings as $s) { | ||
$result[$s] = _($s); | ||
} | ||
|
||
// Restore textdomain | ||
textdomain($previousTextDomain); | ||
return $result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored from #500 to Locale.php.
This way, pages don't need to make all the calls to bindtextdomain()
and setTextDomain()
msgid "%skeyboards%s" | ||
msgstr "%stescados%s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto for this file
msgid "Keyboard search%s" | ||
msgstr "Recherche au clavier%s" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
keyboards/index.php
Outdated
@@ -9,9 +9,35 @@ | |||
use Keyman\Site\com\keyman\templates\Foot; | |||
use Keyman\Site\com\keyman\Locale; | |||
|
|||
// Of array of strings at top of file | |||
// by msgid | |||
$keyboardIndexStrings = Locale::localize('keyboards', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all feels very fragile -- arrays across multiple files which have to match up. A lot of duplication of these strings -- 6 times:
- twice in keyboards-en.po
- once each in keyboards-es-ES.po, keyboards-fr-FR.po
- twice in keyboards/index.php -- here and where referenced.
This will need automatic validation to keep in sync or it's going to get very hard to maintain. (Why do we need the array defined here as well as in the keyboards-en.po file? Can't we just use the list in that file as our starting point?)
It may be better to use an identifier which is not the whole string? e.g. I see we have also 'keyboard search' 'keyman keyboard search' 'keyboard search%s', 'search', 'new search' ... lots of repetition here and risk of confusion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be sensible to establish a convention for a shorthand reference e.g. $_
rather than a long name like $keyboardIndexStrings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on 🦆 -
- Replaced $keyboardIndexStrings array with
_()
alias - Updated
Locale::localize()
so it doesn't restore textdomain
keyboards/index.php
Outdated
|
||
<div id='search-box'> | ||
<form method='get' action='/keyboards' name='f'> | ||
<label for="search-q">Keyboard search:</label><input id="search-q" type="text" placeholder="Enter language or keyboard" name="q" | ||
<label for="search-q"><?= Locale::_s($keyboardIndexStrings['Keyboard search%s'], ":") ?></label><input id="search-q" type="text" placeholder="<?= $keyboardIndexStrings['Enter language or keyboard'] ?>" name="q" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you split the :
out from the string? Here and other places? Seems to make the strings much more complicated than they need to be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I've consolidated punctuation back into the strings in edd7430
Add indexes to parameters Co-authored-by: Marc Durdin <[email protected]>
* Replace array of indexes with `_()` alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a lot easier to maintain. Good work!
Re-implements #500 for #384
This updates Locale.php for localizing the keyboards/ index page
Changes
Locale.php
setTextDomain()
to manage the localization files_s()
wrapperkeyboards/index.php
Screenshots
Note: the "Search" button image asset contains English text.
French
http://keyman.com.localhost/keyboards/?lang=fr-FR
Spanish
http://keyman.com.localhost/keyboards/?lang=es-ES