diff --git a/_includes/locale/locale.php b/_includes/locale/locale.php index a05c7a0..973a9de 100644 --- a/_includes/locale/locale.php +++ b/_includes/locale/locale.php @@ -6,9 +6,23 @@ 'fr-FR' => 'Français' ]; - // Wrapper to format string with gettext '_(' alias and variable args - function _s($s, ...$args) { - return vsprintf(_($s), $args); + /** + * Wrapper to setup locale files + * basePoFile - base filename of the .po file (not including the locales or .po extension) + * pathToLocale - absoluate path to _includes/locale + */ + function setupLocale($basePoFile, $pathToLocale) { + // Container uses English locale, but use setTextDomain to change localization as needed + setLocale(LC_ALL, 'en_US.UTF-8'); + + // Iterate through locales for bindtextdomain + foreach(array_keys($locales) as $code) { + if ($code == 'en') { + // Skip appending English .po name + continue; + } + bindtextdomain("keyboards-${code}", $pathToLocale); + } } /** @@ -28,3 +42,22 @@ function setTextDomain($locale, $basename) { return; } } + + /** + * Wrapper to format string with gettext '_(' alias and variable args + * s - the format string + * args - optional remaining args to the format string + */ + function _s($s, ...$args) { + return vsprintf(_($s), $args); + } + + /** + * Wrapper of echo and _s + */ + function echo_s($s, ...$args) { + $tempString = _s($s, $args); + echo '$tempString'; + } + + diff --git a/keyboards/index.php b/keyboards/index.php index 3f7dbba..37c9b88 100644 --- a/keyboards/index.php +++ b/keyboards/index.php @@ -9,10 +9,7 @@ use Keyman\Site\com\keyman\templates\Body; use Keyman\Site\com\keyman\templates\Foot; - // Container uses English locale, but use setTextDomain to change localization as needed - setLocale(LC_ALL, 'en_US.UTF-8'); - bindtextdomain("keyboards-fr-FR", __DIR__ . "/../_includes/locale"); - bindtextdomain("keyboards-es-ES", __DIR__ . "/../_includes/locale"); + setupLocale("keyboards", __DIR__ . "/../_includes/locale"); // $embed_locale set by session.php setTextDomain($embed_locale, "keyboards");