Skip to content

Commit

Permalink
feat: Localize strings on keyboards index
Browse files Browse the repository at this point in the history
  • Loading branch information
darcywong00 committed Dec 11, 2024
1 parent e2f44a4 commit 82c5a54
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 14 deletions.
51 changes: 49 additions & 2 deletions _includes/locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
}
}
85 changes: 85 additions & 0 deletions _includes/locale/en/LC_MESSAGES/keyboards-en.po
Original file line number Diff line number Diff line change
@@ -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"
94 changes: 94 additions & 0 deletions _includes/locale/en/LC_MESSAGES/keyboards-es-ES.po
Original file line number Diff line number Diff line change
@@ -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"

94 changes: 94 additions & 0 deletions _includes/locale/en/LC_MESSAGES/keyboards-fr-FR.po
Original file line number Diff line number Diff line change
@@ -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"

Loading

0 comments on commit 82c5a54

Please sign in to comment.