From be6871ad88df12e8d841a8fea3ed133faacc0cba Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 4 Dec 2024 10:01:50 +0700 Subject: [PATCH 01/17] chore: Ssed feat/localize/keyboard-search branch --- _includes/locale/en/LC_MESSAGES/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 _includes/locale/en/LC_MESSAGES/.gitkeep diff --git a/_includes/locale/en/LC_MESSAGES/.gitkeep b/_includes/locale/en/LC_MESSAGES/.gitkeep new file mode 100644 index 00000000..e69de29b From d34b47bb6f80d43d0ba00d8407de6c5b14d33c74 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 4 Dec 2024 11:12:14 +0700 Subject: [PATCH 02/17] feat: Configure en_US locale in Dockerfile --- Dockerfile | 16 ++++++++ _includes/locale/README.md | 45 ++++++++++++++++++++++ _includes/locale/en/LC_MESSAGES/.gitignore | 2 + _includes/locale/en/LC_MESSAGES/.gitkeep | 0 resources/init-container.sh | 17 ++++++++ 5 files changed, 80 insertions(+) create mode 100644 _includes/locale/README.md create mode 100644 _includes/locale/en/LC_MESSAGES/.gitignore delete mode 100644 _includes/locale/en/LC_MESSAGES/.gitkeep diff --git a/Dockerfile b/Dockerfile index 71f0b396..1a69fbff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,5 +23,21 @@ COPY resources/keyman-site.conf /etc/apache2/conf-available/ RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini RUN chown -R www-data:www-data /var/www/html/ +# Because the base Docker image doesn't include locales, install these to generate locale files. +# gettext needed to compile .po files to .mo with msgfmt +RUN apt-get update && apt-get install -y \ + locales \ + gettext + +# Install PHP-extension gettext for localization at runtime +RUN docker-php-ext-install gettext +RUN docker-php-ext-enable gettext + +# Only enable en_US locale in /etc/locale.gen +# PHP will use textdomain() to specify "localization" .mo files +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ + && dpkg-reconfigure --frontend=noninteractive locales \ + && update-locale + COPY --from=composer-builder /composer/vendor /var/www/vendor RUN a2enmod rewrite headers; a2enconf keyman-site diff --git a/_includes/locale/README.md b/_includes/locale/README.md new file mode 100644 index 00000000..5d6e3559 --- /dev/null +++ b/_includes/locale/README.md @@ -0,0 +1,45 @@ +### Setup for Localization + +[init-container.sh](../../resources/init-container.sh) contains steps for the Docker container to compile .po files to .mo files which PHP uses for `gettext()`. + +If you want to compile the files on your host machine, install `gettext`. + +```bash +sudo apt-get install gettext +``` + +### Adding locales + +The Docker image has the "en_US.UTF-8" locale enabled in `/etc/locale.gen` +We'll use `textdomain` to specify filenames for "switching" localization. +The filenames will include the `%locale%` as defined in the [crowdin.com project](https://crowdin.com/project/keymancom). + +Note: the details below will get refactored to use a Locale.php class + +In the example below, the English file `keyboards-en.po` is copied to `keyboards-fr-FR.po` for French. + +1. In `/_includes/locale/en/LC_MESSAGES/` + * Copy `keyboards-en.po` file and rename to the `keyboards-fr-FR.po`. + * Translate/upload the new .po file to crowdin + * Convert .po file to .mo with the following + +```bash +msgfmt keyboards-fr-FR.po --output-file=keyboards-fr-FR.mo +``` + +(The container handles the msgfmt step in init-container.sh) + +2. Add the file to the PHP (path is relative the PHP file) + +```php +bindtextdomain("keyboards-fr-FR", "../_includes/locale"); +``` + +3. To use French, +```php +textdomain('keyboards-fr-FR'); +``` + +---- + +For formatted string, use the PHP wrapper [`_s(msgstr, $args)`](./locale.php). diff --git a/_includes/locale/en/LC_MESSAGES/.gitignore b/_includes/locale/en/LC_MESSAGES/.gitignore new file mode 100644 index 00000000..e1b0b2c1 --- /dev/null +++ b/_includes/locale/en/LC_MESSAGES/.gitignore @@ -0,0 +1,2 @@ +# Ignore generated files from msgfmt +*.mo diff --git a/_includes/locale/en/LC_MESSAGES/.gitkeep b/_includes/locale/en/LC_MESSAGES/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/resources/init-container.sh b/resources/init-container.sh index 033c7bcd..388218ca 100755 --- a/resources/init-container.sh +++ b/resources/init-container.sh @@ -10,3 +10,20 @@ else echo "Skip Generating CDN and clean CDN cache" rm -rf cdn/deploy fi + +echo "---- Generating .mo localization files ----" +cd _includes/locale/en/LC_MESSAGES/ + +# cleanup previous .mo files +find . -type f -name '*.mo' -delete + +# Compile .po to .mo localization files +for filename in `find . -type f -name "*.po"`; do + # Remove the .po extension + base_name=`echo ${filename} | sed 's/\.[^.]*$//'` + msgfmt "${base_name}.po" --output-file="${base_name}".mo + retVal=$? + if [[ ${retVal} -ne 0 ]]; then + exit 1 + fi +done From a60d92a15820480298158d8edc6a7230468c4b10 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 6 Dec 2024 06:08:40 +0700 Subject: [PATCH 03/17] Update resources/init-container.sh Co-authored-by: Marc Durdin --- resources/init-container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/init-container.sh b/resources/init-container.sh index 388218ca..df1f87ea 100755 --- a/resources/init-container.sh +++ b/resources/init-container.sh @@ -20,7 +20,7 @@ find . -type f -name '*.mo' -delete # Compile .po to .mo localization files for filename in `find . -type f -name "*.po"`; do # Remove the .po extension - base_name=`echo ${filename} | sed 's/\.[^.]*$//'` + base_name="${filename%.po}" msgfmt "${base_name}.po" --output-file="${base_name}".mo retVal=$? if [[ ${retVal} -ne 0 ]]; then From feb2a26d8385a31f77878aae031571ed14baf90d Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 6 Dec 2024 13:50:08 +0700 Subject: [PATCH 04/17] fix: restore path in init-container.sh --- resources/init-container.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/init-container.sh b/resources/init-container.sh index df1f87ea..abdc71f6 100755 --- a/resources/init-container.sh +++ b/resources/init-container.sh @@ -27,3 +27,5 @@ for filename in `find . -type f -name "*.po"`; do exit 1 fi done + +cd ../../../../ From 583a9cda6adb7b497c12c6c5affd6e83427dd71d Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 6 Dec 2024 15:47:44 +0700 Subject: [PATCH 05/17] feat: Add Locale.php class to control currentLocale --- _includes/includes/template.php | 3 +++ _includes/locale/Locale.php | 35 +++++++++++++++++++++++++++++++++ keyboards/index.php | 2 ++ keyboards/session.php | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 _includes/locale/Locale.php diff --git a/_includes/includes/template.php b/_includes/includes/template.php index 52cd8b85..913ab845 100644 --- a/_includes/includes/template.php +++ b/_includes/includes/template.php @@ -3,9 +3,12 @@ // *Don't* use autoloader here because of potential side-effects in older pages require_once(__DIR__ . '/../2020/Util.php'); + //require_once(__DIR__ . '/../locale/Locale.php'); require_once(__DIR__ . '/../2020/KeymanVersion.php'); require_once(__DIR__ . '/../2020/templates/Head.php'); + use Keyman\Site\com\keyman\Locale; + function template_finish($foot) { //ob_end_flush(); diff --git a/_includes/locale/Locale.php b/_includes/locale/Locale.php new file mode 100644 index 00000000..c5a5c46d --- /dev/null +++ b/_includes/locale/Locale.php @@ -0,0 +1,35 @@ +currentLocale; + } + + public static function Rebuild() { + self::$instance = new Locale(); + } + + public function overrideCurrentLocale($locale) { + $this->currentLocale = $locale; + } + + function __construct() { + $this->currentLocale = 'en'; + } + } diff --git a/keyboards/index.php b/keyboards/index.php index c188fa85..5b4a921a 100644 --- a/keyboards/index.php +++ b/keyboards/index.php @@ -70,6 +70,8 @@
  • You can apply prefixes k: (keyboards), l: (languages), s: (scripts, writing systems) or c: (countries) to filter your search results. For example c:thailand searches for keyboards for languages used in Thailand.
  • Use prefix l:id: to search for a BCP 47 language tag, for example l:id:ti-et searches for Tigrigna (Ethiopia).
  • +
  • Current locale is getCurrentLocale() ?>
  • "; + ?> diff --git a/keyboards/session.php b/keyboards/session.php index 1bb02b19..d8592a70 100644 --- a/keyboards/session.php +++ b/keyboards/session.php @@ -31,6 +31,10 @@ $embed_android = $embed == 'android'; $embed_ios = $embed == 'ios'; + if(isset($_Request['locale'])) { + Locale::Instance()->overrideCurrentLocale($_REQUEST['locale']); + } + if($embed != 'none') { // Poor man's session control because IE embedded in downlevel Windows destroys cookie support by // default, including in existing versions of Keyman. From 008a6b8a4b3b347d93cf94d56be49c0a7fdb9a7c Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 9 Dec 2024 10:39:07 +0700 Subject: [PATCH 06/17] Undo singleton --- _includes/includes/template.php | 4 +--- _includes/locale/Locale.php | 31 ++++++++++--------------------- keyboards/index.php | 3 +-- keyboards/session.php | 4 ++-- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/_includes/includes/template.php b/_includes/includes/template.php index 913ab845..315d2911 100644 --- a/_includes/includes/template.php +++ b/_includes/includes/template.php @@ -3,12 +3,10 @@ // *Don't* use autoloader here because of potential side-effects in older pages require_once(__DIR__ . '/../2020/Util.php'); - //require_once(__DIR__ . '/../locale/Locale.php'); + require_once(__DIR__ . '/../locale/Locale.php'); require_once(__DIR__ . '/../2020/KeymanVersion.php'); require_once(__DIR__ . '/../2020/templates/Head.php'); - use Keyman\Site\com\keyman\Locale; - function template_finish($foot) { //ob_end_flush(); diff --git a/_includes/locale/Locale.php b/_includes/locale/Locale.php index c5a5c46d..676e413f 100644 --- a/_includes/locale/Locale.php +++ b/_includes/locale/Locale.php @@ -4,32 +4,21 @@ namespace Keyman\Site\com\keyman; class Locale { - private $currentLocale; - - private static $instance; - - public static function Instance(): Locale { - if(!self::$instance) - self::Rebuild(); - return self::$instance; - } + private static $currentLocale = 'en'; /** * Return the current locale. Fallback to 'en' + * @return $currentLocale */ - static function CurrentLocale() { - return $this->currentLocale; - } - - public static function Rebuild() { - self::$instance = new Locale(); + public static function currentLocale() { + return Locale::$currentLocale; } - public function overrideCurrentLocale($locale) { - $this->currentLocale = $locale; - } - - function __construct() { - $this->currentLocale = 'en'; + /** + * Override the current locale + * @param $locale - the new current locale + */ + public static function overrideCurrentLocale($locale) { + Locale::$currentLocale = $locale; } } diff --git a/keyboards/index.php b/keyboards/index.php index 5b4a921a..de968d43 100644 --- a/keyboards/index.php +++ b/keyboards/index.php @@ -7,6 +7,7 @@ use Keyman\Site\com\keyman\templates\Menu; use Keyman\Site\com\keyman\templates\Body; use Keyman\Site\com\keyman\templates\Foot; + use Keyman\Site\com\keyman\Locale; $head_options = [ 'title' =>'Keyboard Search', @@ -70,8 +71,6 @@
  • You can apply prefixes k: (keyboards), l: (languages), s: (scripts, writing systems) or c: (countries) to filter your search results. For example c:thailand searches for keyboards for languages used in Thailand.
  • Use prefix l:id: to search for a BCP 47 language tag, for example l:id:ti-et searches for Tigrigna (Ethiopia).
  • -
  • Current locale is getCurrentLocale() ?>
  • "; - ?> diff --git a/keyboards/session.php b/keyboards/session.php index d8592a70..a75cfd2d 100644 --- a/keyboards/session.php +++ b/keyboards/session.php @@ -31,8 +31,8 @@ $embed_android = $embed == 'android'; $embed_ios = $embed == 'ios'; - if(isset($_Request['locale'])) { - Locale::Instance()->overrideCurrentLocale($_REQUEST['locale']); + if(isset($_REQUEST['locale'])) { + \Keyman\Site\com\keyman\Locale::overrideCurrentLocale($_REQUEST['locale']); } if($embed != 'none') { From b483df47db8c8bc577c4b724cc63b79cb5dd3a0a Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 9 Dec 2024 11:35:20 +0700 Subject: [PATCH 07/17] Use `lang` query parameter --- _includes/locale/README.md | 2 +- keyboards/session.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_includes/locale/README.md b/_includes/locale/README.md index 5d6e3559..8b754c0f 100644 --- a/_includes/locale/README.md +++ b/_includes/locale/README.md @@ -42,4 +42,4 @@ textdomain('keyboards-fr-FR'); ---- -For formatted string, use the PHP wrapper [`_s(msgstr, $args)`](./locale.php). +For formatted string, use the PHP wrapper [`_s(msgstr, $args)`](./Locale.php). diff --git a/keyboards/session.php b/keyboards/session.php index a75cfd2d..24f86209 100644 --- a/keyboards/session.php +++ b/keyboards/session.php @@ -31,8 +31,8 @@ $embed_android = $embed == 'android'; $embed_ios = $embed == 'ios'; - if(isset($_REQUEST['locale'])) { - \Keyman\Site\com\keyman\Locale::overrideCurrentLocale($_REQUEST['locale']); + if(isset($_REQUEST['lang'])) { + \Keyman\Site\com\keyman\Locale::overrideCurrentLocale($_REQUEST['lang']); } if($embed != 'none') { From 239d4c7af19dc8555e4502df9e71fae54f1847be Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 11 Dec 2024 09:54:13 +0700 Subject: [PATCH 08/17] set _SESSION['lang'] --- keyboards/session.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/keyboards/session.php b/keyboards/session.php index 24f86209..116416a0 100644 --- a/keyboards/session.php +++ b/keyboards/session.php @@ -33,7 +33,10 @@ if(isset($_REQUEST['lang'])) { \Keyman\Site\com\keyman\Locale::overrideCurrentLocale($_REQUEST['lang']); + } else if (isset($_SESSION['lang'])) { + \Keyman\Site\com\keyman\Locale::overrideCurrentLocale($_SESSION['lang']); } + $_SESSION['lang'] = \Keyman\Site\com\keyman\Locale::currentLocale(); if($embed != 'none') { // Poor man's session control because IE embedded in downlevel Windows destroys cookie support by From 82c5a54e0d9f6a5b0795c62c65fd33a5482b9e9c Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 9 Dec 2024 14:48:56 +0700 Subject: [PATCH 09/17] feat: Localize strings on keyboards index --- _includes/locale/Locale.php | 51 +++++++++- .../locale/en/LC_MESSAGES/keyboards-en.po | 85 +++++++++++++++++ .../locale/en/LC_MESSAGES/keyboards-es-ES.po | 94 +++++++++++++++++++ .../locale/en/LC_MESSAGES/keyboards-fr-FR.po | 94 +++++++++++++++++++ keyboards/index.php | 84 ++++++++++++++--- 5 files changed, 394 insertions(+), 14 deletions(-) create mode 100644 _includes/locale/en/LC_MESSAGES/keyboards-en.po create mode 100644 _includes/locale/en/LC_MESSAGES/keyboards-es-ES.po create mode 100644 _includes/locale/en/LC_MESSAGES/keyboards-fr-FR.po diff --git a/_includes/locale/Locale.php b/_includes/locale/Locale.php index 676e413f..fd5fcd2e 100644 --- a/_includes/locale/Locale.php +++ b/_includes/locale/Locale.php @@ -4,7 +4,10 @@ namespace Keyman\Site\com\keyman; class Locale { - private static $currentLocale = 'en'; + public const DEFAULT_LOCALE = 'en'; + + // xx-YY locale as specified in crowdin %locale% + private static $currentLocale = Locale::DEFAULT_LOCALE; /** * Return the current locale. Fallback to 'en' @@ -16,9 +19,53 @@ public static function currentLocale() { /** * Override the current locale - * @param $locale - the new current locale + * @param $locale - the new current locale (xx-YY as specified in crowdin %locale%) */ public static function overrideCurrentLocale($locale) { Locale::$currentLocale = $locale; } + + /** + * Validate $locale is an acceptable locale. + * Using xx-YY as specified in crowdin %locale% + * @param $locale - the locale to validate + * @return true if valid locale + */ + public static function validateLocale($locale) { + + } + + /** + * Use textdomain to specify the localization file for "localization". + * Ignore if locale is "en" or the filename doesn't exist + * Filename expected to be "$basename-$locale.mo" + * @param $basename - base name of the .mo file to use + * @return current message domain + */ + public static function setTextDomain($basename) { + // Container uses English locale, and then we use textdomain to change "localization" files + setLocale(LC_ALL, 'en_US.UTF-8'); + + if (Locale::$currentLocale == Locale::DEFAULT_LOCALE) { + return; + } + + $filename = sprintf("%s-%s", $basename, Locale::$currentLocale); + $fullPath = sprintf("%s/en/LC_MESSAGES/%s.mo", __DIR__, $filename); + if(file_exists($fullPath)) { + return textdomain($filename); + } else { + //echo "textdomain $fullPath doesn't exist"; + return; + } + } + + /** + * Wrapper to format string with gettext '_(' alias and variable args + * @param $s - the format string + * @param $args - optional remaining args to the format string + */ + public static function _s($s, ...$args) { + return vsprintf($s, $args); + } } diff --git a/_includes/locale/en/LC_MESSAGES/keyboards-en.po b/_includes/locale/en/LC_MESSAGES/keyboards-en.po new file mode 100644 index 00000000..21ea45b7 --- /dev/null +++ b/_includes/locale/en/LC_MESSAGES/keyboards-en.po @@ -0,0 +1,85 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" + +# Default English strings for keyboards/index.php + +# Page Title +msgid "Keyboard Search" +msgstr "Keyboard Search" + +# Page Description +msgid "Keyman Keyboard Search" +msgstr "Keyman Keyboard Search" + +# Keyboard search bar +msgid "Keyboard search%s" +msgstr "Keyboard search%s" + +# Search bar placeholder +msgid "Enter language or keyboard" +msgstr "Enter language or keyboard" + +# Search Button Value +msgid "Search" +msgstr "Search" + +# Link to start a new keyboard search +msgid "New search" +msgstr "New search" + +# Search box prompt +msgid "Enter the name of a keyboard or language to search for%s" +msgstr "Enter the name of a keyboard or language to search for%s" + +# Search box link for popular keyboards +msgid "Popular keyboards" +msgstr "Popular keyboards" + +# Search box link for all Keyman keyboards +msgid "All keyboards" +msgstr "All keyboards" + +# Search box hint: List header +msgid "Hints" +msgstr "Hints" + +# Search box hint: Description +msgid "The search always returns a list of keyboards. It searches for keyboard names and details, language names, country names and script names." +msgstr "The search always returns a list of keyboards. It searches for keyboard names and details, language names, country names and script names." + +# Search box hint: available prefixes to use in the search +msgid "You can apply prefixes" +msgstr "You can apply prefixes" + +# (keyboards) +msgid "%skeyboards%s" +msgstr "%skeyboards%s" + +# (languages) +msgid "%slanguages%s" +msgstr "%slanguages%s" + +# (scripts, writing systems) or... +msgid "%sscripts, writing systems%s or" +msgstr "%sscripts, writing systems%s or" + +# (countries) to filter your search results... +msgid "%scountries%s to filter your search results. For example" +msgstr "%scountries%s to filter your search results. For example" + +# Search box hint: example of country search +msgid "searches for keyboards for languages used in Thailand." +msgstr "searches for keyboards for languages used in Thailand." + +# Search box hint: BCP 47 prefix +msgid "Use prefix" +msgstr "Use prefix" + +# Seach box hint: BCP 47 language example +msgid "to search for a BCP 47 language tag, for example" +msgstr "to search for a BCP 47 language tag, for example" + +# Search box hint: BCP 47 language example +msgid "searches for Tigrigna %sEthiopia%s" +msgstr "searches for Tigrigna %sEthiopia%s" diff --git a/_includes/locale/en/LC_MESSAGES/keyboards-es-ES.po b/_includes/locale/en/LC_MESSAGES/keyboards-es-ES.po new file mode 100644 index 00000000..4f185937 --- /dev/null +++ b/_includes/locale/en/LC_MESSAGES/keyboards-es-ES.po @@ -0,0 +1,94 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Crowdin-Project: keymancom\n" +"X-Crowdin-Project-ID: 740839\n" +"X-Crowdin-Language: es-ES\n" +"X-Crowdin-File: /master/keyboards/keyboards.po\n" +"X-Crowdin-File-ID: 2\n" +"Project-Id-Version: keymancom\n" +"Language-Team: Spanish\n" +"Language: es_ES\n" +"PO-Revision-Date: 2024-11-11 08:20\n" + +# Page Title +msgid "Keyboard Search" +msgstr "Búsqueda por Teclado" + +# Page Description +msgid "Keyman Keyboard Search" +msgstr "Keyman Búsqueda por Teclado" + +# Keyboard search bar +msgid "Keyboard search%s" +msgstr "Búsqueda por teclado%s" + +# Search bar placeholder +msgid "Enter language or keyboard" +msgstr "Ingresar idioma o teclado" + +# Search Button Value +msgid "Search" +msgstr "Buscar" + +# Link to start a new keyboard search +msgid "New search" +msgstr "Nueva buscar" + +# Search box prompt +msgid "Enter the name of a keyboard or language to search for%s" +msgstr "Introduzca el nombre de un teclado o idioma para buscar%s" + +# Search box link for popular keyboards +msgid "Popular keyboards" +msgstr "Teclados populares" + +# Search box link for all Keyman keyboards +msgid "All keyboards" +msgstr "Todos los teclados" + +# Search box hint: List header +msgid "Hints" +msgstr "Consejos" + +# Search box hint: Description +msgid "The search always returns a list of keyboards. It searches for keyboard names and details, language names, country names and script names." +msgstr "La búsqueda siempre devuelve una lista de teclados. Busca nombres de teclados y detalles, nombres de idiomas, nombres de países y nombres de alfabetos." + +# Search box hint: available prefixes to use in the search +msgid "You can apply prefixes" +msgstr "Puedes aplicar prefijos" + +# (keyboards) +msgid "%skeyboards%s" +msgstr "%stescados%s" + +# (languages) +msgid "%slanguages%s" +msgstr "%sidiomas%s" + +# (scripts, writing systems) or... +msgid "%sscripts, writing systems%s or" +msgstr "%sguiones, sistemas de escritura%s o" + +# (countries) to filter your search results... +msgid "%scountries%s to filter your search results. For example" +msgstr "%spaíses%s para filtrar los resultados de búsqueda. Por ejemplo" + +# Search box hint: example of country search +msgid "searches for keyboards for languages used in Thailand." +msgstr "busca teclados para los idiomas utilizados en Tailandia." + +# Search box hint: BCP 47 prefix +msgid "Use prefix" +msgstr "Utilice prefijo" + +# Seach box hint: BCP 47 language example +msgid "to search for a BCP 47 language tag, for example" +msgstr "para buscar una etiqueta de idioma BCP 47, por ejemplo" + +# Search box hint: BCP 47 language example +msgid "searches for Tigrigna %sEthiopia%s" +msgstr "busca Tigrigna %sEtiopía%s" + diff --git a/_includes/locale/en/LC_MESSAGES/keyboards-fr-FR.po b/_includes/locale/en/LC_MESSAGES/keyboards-fr-FR.po new file mode 100644 index 00000000..dcc57b1f --- /dev/null +++ b/_includes/locale/en/LC_MESSAGES/keyboards-fr-FR.po @@ -0,0 +1,94 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Crowdin-Project: keymancom\n" +"X-Crowdin-Project-ID: 740839\n" +"X-Crowdin-Language: fr\n" +"X-Crowdin-File: /master/keyboards/keyboards.po\n" +"X-Crowdin-File-ID: 2\n" +"Project-Id-Version: keymancom\n" +"Language-Team: French\n" +"Language: fr_FR\n" +"PO-Revision-Date: 2024-11-11 08:15\n" + +# Page Title +msgid "Keyboard Search" +msgstr "Recherche au clavier" + +# Page Description +msgid "Keyman Keyboard Search" +msgstr "Recherche de clavier Keyman" + +# Keyboard search bar +msgid "Keyboard search%s" +msgstr "Recherche au clavier%s" + +# Search bar placeholder +msgid "Enter language or keyboard" +msgstr "Entrez la langue ou le clavier" + +# Search Button Value +msgid "Search" +msgstr "Recherche" + +# Link to start a new keyboard search +msgid "New search" +msgstr "Nouvelle recherche" + +# Search box prompt +msgid "Enter the name of a keyboard or language to search for%s" +msgstr "Saisissez le nom d'un clavier ou d'une langue à rechercher%s" + +# Search box link for popular keyboards +msgid "Popular keyboards" +msgstr "Claviers populaires" + +# Search box link for all Keyman keyboards +msgid "All keyboards" +msgstr "Tous les claviers" + +# Search box hint: List header +msgid "Hints" +msgstr "Conseils" + +# Search box hint: Description +msgid "The search always returns a list of keyboards. It searches for keyboard names and details, language names, country names and script names." +msgstr "La recherche renvoie toujours une liste de claviers. Elle recherche les noms et les détails des claviers, les noms de langues, les noms de pays et les noms d'écritures." + +# Search box hint: available prefixes to use in the search +msgid "You can apply prefixes" +msgstr "Vous pouvez appliquer des préfixes" + +# (keyboards) +msgid "%skeyboards%s" +msgstr "%sclaviers%s" + +# (languages) +msgid "%slanguages%s" +msgstr "%slangues%s" + +# (scripts, writing systems) or... +msgid "%sscripts, writing systems%s or" +msgstr "%sscripts, systèmes d'écriture%s ou" + +# (countries) to filter your search results... +msgid "%scountries%s to filter your search results. For example" +msgstr "%spays%s pour filtrer vos résultats de recherche. Par exemple" + +# Search box hint: example of country search +msgid "searches for keyboards for languages used in Thailand." +msgstr "recherche des claviers pour les langues utilisées en Thaïlande." + +# Search box hint: BCP 47 prefix +msgid "Use prefix" +msgstr "Utiliser le préfixe" + +# Seach box hint: BCP 47 language example +msgid "to search for a BCP 47 language tag, for example" +msgstr "pour rechercher une balise de langue BCP 47, par exemple" + +# Search box hint: BCP 47 language example +msgid "searches for Tigrigna %sEthiopia%s" +msgstr "busca Tigrigna %sEtiopía%s" + diff --git a/keyboards/index.php b/keyboards/index.php index de968d43..4f0b0d49 100644 --- a/keyboards/index.php +++ b/keyboards/index.php @@ -9,9 +9,52 @@ use Keyman\Site\com\keyman\templates\Foot; use Keyman\Site\com\keyman\Locale; + // Of array of strings at top of file + // by msgid + $keyboardIndexStrings = localize('keyboards', [ + 'Keyboard Search', + 'Keyman Keyboard Search', + 'Keyboard search%s', + 'Enter language or keyboard', + 'Search', + 'New search', + 'Enter the name of a keyboard or language to search for%s', + 'Popular keyboards', + 'All keyboards', + 'Hints', + 'The search always returns a list of keyboards. It searches for keyboard names and details, language names, country names and script names.', + 'You can apply prefixes', + '%skeyboards%s', + '%slanguages%s', + '%sscripts, writing systems%s or', + '%scountries%s to filter your search results. For example', + 'searches for keyboards for languages used in Thailand.', + 'Use prefix', + 'to search for a BCP 47 language tag, for example', + 'searches for Tigrigna %sEthiopia%s', + ]); + + function localize($domain, $strings) { + bindtextdomain("$domain-fr-FR", __DIR__ . "/../_includes/locale"); + bindtextdomain("$domain-es-ES", __DIR__ . "/../_includes/locale"); + + $previousTextDomain = textdomain(NULL); + Locale::setTextDomain($domain); + + $result = []; + foreach($strings as $s) { + $result[$s] = _($s); + } + + // Restore textdomain + textdomain($previousTextDomain); + return $result; + } + $head_options = [ - 'title' =>'Keyboard Search', - 'description' => 'Keyman Keyboard Search', + 'title' => $keyboardIndexStrings['Keyboard Search'], + 'description' => $keyboardIndexStrings['Keyman Keyboard Search'], + 'language' => Locale::currentLocale(), 'css' => [Util::cdn('css/template.css'), Util::cdn('keyboard-search/search.css')], 'js' => [Util::cdn('keyboard-search/jquery.mark.js'), Util::cdn('keyboard-search/dedicated-landing-pages.js'), Util::cdn('keyboard-search/search.js')] @@ -47,14 +90,14 @@
    '> -

    Keyboard Search

    +