Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/keyboards/l
# /keyboards/countries to /keyboards/index.php
RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/keyboards/countries/(.*)" "/_content/keyboards/index.php?q=c:id:$7&lang=$1" [NC,END]

# Root keyboard search to pass embed query?
RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/keyboards(/)?$" "/_content/keyboards/index.php?lang=$1" [NC,END,QSA]


#
# contact/exception
Expand Down
25 changes: 19 additions & 6 deletions _content/keyboards/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ function _m($id, ...$args) { return Locale::m(LOCALE_KEYBOARDS, $id, ...$args
'description' => _m('page_description'),
'language' => isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en',
'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')]
'js' => [
Util::cdn('keyboard-search/jquery.mark.js'),
Util::cdn('keyboard-search/dedicated-landing-pages.js'),
Util::cdn('keyboard-search/search.mjs'),
],
'js_i18n_domains' => [
'keyboards' => Locale::domain_js('keyboards'),
],
];

if($embed != 'none') {
Expand All @@ -39,6 +45,7 @@ function _m($id, ...$args) { return Locale::m(LOCALE_KEYBOARDS, $id, ...$args
<script>
var embed='<?=$embed?>';
var embed_query='<?=$session_query?>';
var embed_lang='<?=$head_options['language']?>';

if(embed != 'none') {
// For an iframe hosted in Download Keyboards dialog, we cannot use
Expand All @@ -52,19 +59,25 @@ function _m($id, ...$args) { return Locale::m(LOCALE_KEYBOARDS, $id, ...$args

<div class='<?= $embed == 'none' ? '' : 'embed embed-'.$embed ?>'>

<h2 class="red underline"><a href='/keyboards'><?= _m('page_title') ?></a></h2>
<h2 class="red underline"><a href='/<?= $head_options['language']?>/keyboards'><?= _m('page_title') ?></a></h2>

<div id='search-box'>
<form method='get' action='/keyboards' name='f'>
<form method='get' action='/<?= $head_options['language']?>/keyboards' name='f'>
<label for="search-q"><?= _m('keyboard_search') ?></label><input id="search-q" type="text" placeholder="<?= _m('enter_language') ?>" name="q"
<?php if($embed == 'none') echo 'autofocus'; ?>>
<input id="search-f" type="button" value="<?= _m('search') ?>" onclick="return do_search()">
<label id="search-new"><a href='/keyboards<?=$session_query_q?>'><?= _m('new_search')?></a></label>
<input id="search-f" type="button" value="<?= _m('search') ?>">
<label id="search-new"><a href='/<?= $head_options['language']?>/keyboards<?=$session_query_q?>'><?= _m('new_search')?></a></label>
<input id="search-obsolete" type="hidden" name="obsolete" value="0">
<input id="search-page" type="hidden" name="page" value="1">
</form>
</div>

<script type="module">
// Wrapper to call .mjs function
import { do_search } from '../../cdn/dev/keyboard-search/search.mjs';
document.getElementById('search-f').onclick = do_search;
</script>

<div id='search-results-container' class=''>
<div id='search-results'></div>
<div id='search-results-empty'>
Expand Down
21 changes: 18 additions & 3 deletions _includes/2020/templates/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ static function render($fields = []) {
if(!isset($fields->js)) {
$fields->js = [];
}
if(!isset($fields->js_i18n_domains)) {
$fields->js_i18n_domains = [];
}
?><!DOCTYPE html>
<?php
if (!empty($fields->lang)) {
Expand Down Expand Up @@ -61,15 +64,27 @@ static function render($fields = []) {
<link href='https://fonts.googleapis.com/css?family=Cabin:400,400italic,500,600,700,700italic|Source+Sans+Pro:400,700,900,600,300|Noto+Serif:400' rel='stylesheet' type='text/css'>

<?php
/* Embed json i18n strings for each domain */
foreach($fields->js_i18n_domains as $domain => $locales) {
$localization = '';
foreach($locales as $locale) {
if($localization != '') $localization .= ",\n";
$localization .= "{ \"locale\": \"$locale\", \"strings\": " . file_get_contents(_KEYMANCOM_INCLUDES . "/locale/strings/$domain/$locale.json") . "}";
}
echo "<script id='i18n_$domain' type='application/json'>[\n$localization\n]</script>\n";
}

array_unshift($fields->js,
Util::cdn('js/jquery1-11-1.min.js'),
Util::cdn('js/bowser.es5.2.9.0.min.js'),
Util::cdn('js/kmlive.js')
);

foreach($fields->js as $jsFile) { ?>
<script src='<?=$jsFile?>'></script>
<?php } ?>
foreach($fields->js as $jsFile) {
$jsFileType = str_ends_with($jsFile, '.mjs') ? "type='module'" : "";
echo "<script src='$jsFile' $jsFileType></script>\n";
}
?>
</head>

<?php
Expand Down
40 changes: 29 additions & 11 deletions _includes/locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Locale {
public const DEFAULT_LOCALE = 'en';

// array of the support locales
// array of the support locales
// xx-YY locale as specified in crowdin %locale%
private static $currentLocales = [];

Expand All @@ -44,14 +44,16 @@ public static function currentLocales() {
*/
public static function setLocale($locale) {
// Clear current locales
self::$currentLocales == [];
self::$currentLocales = [];

if (!empty($locale)) {
self::$currentLocales = self::calculateFallbackLocales($locale);
}

// Push default fallback locale to the end
array_push(self::$currentLocales, Locale::DEFAULT_LOCALE);
if(!in_array(Locale::DEFAULT_LOCALE, self::$currentLocales)) {
// Push default fallback locale to the end
array_push(self::$currentLocales, Locale::DEFAULT_LOCALE);
}
}

/**
Expand All @@ -61,8 +63,8 @@ public static function setLocale($locale) {
*/
public static function loadDomain($domain) {
self::$strings[$domain] = [];
$path = __DIR__ . '/strings/' . $domain . '/*.php';
$files = glob(__DIR__ . '/strings/' . $domain . '/*.php');
$path = _KEYMANCOM_INCLUDES . '/locale/strings/' . $domain . '/*.php';
$files = glob(_KEYMANCOM_INCLUDES . '/locale/strings/' . $domain . '/*.php');
if ($files == false) {
return false;
}
Expand All @@ -86,7 +88,7 @@ public static function loadDomain($domain) {
*/
public static function loadStrings($domain, $locale) {
$currentLocaleFilename = sprintf("%s/%s/%s",
__DIR__ . '/strings/',
_KEYMANCOM_INCLUDES . '/locale/strings/',
$domain,
$locale . '.php');

Expand All @@ -96,10 +98,26 @@ public static function loadStrings($domain, $locale) {
}
}

/**
* Return an array of javascript locales available for the given domain, in
* priority order.
*/
public static function domain_js($domain) {
$root = _KEYMANCOM_INCLUDES . "/locale/strings/$domain";
$locales = [];
foreach (self::currentLocales() as $locale) {
if(file_exists("$root/$locale.json")) {
array_push($locales, $locale);
}
}

return $locales;
}

/**
* Defines a global variable for page locale strings and also
* tells locale system that current page uses locales
* @param $define -
* @param $define -
* @param $id - folder containing locale strings, relative to /_includes/locale/strings
*/
public static function definePageLocale($define, $id) {
Expand Down Expand Up @@ -164,21 +182,21 @@ private static function getString($domain, $id) {
}
}

// String not found in any localization -
// String not found in any localization -
if(KeymanHosts::Instance()->Tier() == KeymanHosts::TIER_DEVELOPMENT) {
die('string ' . $id . ' is missing in all the l10ns');
}
return $id;
}

/**
* Wrapper to lookup localized string for webpage domain.
* Wrapper to lookup localized string for webpage domain.
* Formatted string using optional variable args for placeholders
* should escape like %1\$s
* @param $domain - the PHP file using the localized strings
* @param $id - the id for the string
* @param $args - optional remaining args to the format string
*/
*/
public static function m($domain, $id, ...$args) {
$str = self::getString($domain, $id);
if (count($args) == 0) {
Expand Down
3 changes: 0 additions & 3 deletions _includes/locale/strings/keyboards/details/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@

"new_search" => "New search",

## TODO: Previous/Next pagination handled in search.js


## Errors

# Failed to load keyboard package [ID]
Expand Down
2 changes: 1 addition & 1 deletion _includes/locale/strings/keyboards/details/km.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"downloads_since" => "ដំឡើងចាប់តាំងពី %1\$s",

# Date to start counting downloads
"date_counting" => "October 2019",
"date_counting" => "តុលា​ ២០១៩",

"encoding" => "ការអ៊ីនកូដ",

Expand Down
15 changes: 15 additions & 0 deletions _includes/locale/strings/keyboards/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resultOne": "result",
"resultMore": "results",
"pageNumberOfTotalPages": "page {pageNumber} of {totalPages}.",
"keyboardSearchTitle": "- Keyboard search",
"obsoleteKeyboards": "Obsolete keyboards",
"monthlyDownloadZero": "No recent downloads",
"monthlyDownloadOne": "monthly download",
"monthlyDownloadMore": "monthly downloads",
"notUnicode": "Note: Not a Unicode keyboard",
"designedForPlatform": "Designed for {platform}",
"noMatchesFoundForKeyboard": "No matches found for '{keyboard}'",
"previousPager": "< Previous",
"nextPager": "Next >"
}
15 changes: 15 additions & 0 deletions _includes/locale/strings/keyboards/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resultOne": "resultado",
"resultMore": "resultados",
"pageNumberOfTotalPages": "página {pageNumber} de {totalPages}.",
"keyboardSearchTitle": "- Búsqueda por teclado",
"obsoleteKeyboards": "Teclados obsoletos",
"monthlyDownloadZero": "No hay descargas recientes",
"monthlyDownloadOne": "descarga mensual",
"monthlyDownloadMore": "descargas mensuales",
"notUnicode": "Nota: No es un teclado Unicode",
"designedForPlatform": "Diseñado para {platform}",
"noMatchesFoundForKeyboard": "No se encontraron coincidencias para '{keyboard}'",
"previousPager": "< Anterior",
"nextPager": "Siguente >"
}
15 changes: 15 additions & 0 deletions _includes/locale/strings/keyboards/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resultOne": "résultat",
"resultMore": "résultats",
"pageNumberOfTotalPages": "page {pageNumber} sur {totalPages}.",
"keyboardSearchTitle": "- Recherche au clavier",
"obsoleteKeyboards": "Claviers obsolètes",
"monthlyDownloadZero": "Aucun téléchargement récent",
"monthlyDownloadOne": "téléchargement mensuel",
"monthlyDownloadMore": "téléchargements mensuels",
"notUnicode": "Remarque: Ce n'est pas un clavier Unicode.",
"designedForPlatform": "Conçu pour {platform}",
"noMatchesFoundForKeyboard": "Aucun résultat trouvé pour '{keyboard}'",
"previousPager": "< Précédentes",
"nextPager": "Plus >"
}
4 changes: 2 additions & 2 deletions _includes/locale/strings/keyboards/install/km.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* Keyman is copyright (C) SIL Global. MIT License.
*
* Default English strings for keyboards/keyboard-install.php
* Don't escape $s when uploading source to crowdin because exports will escape \$s to \\$s
* When exporting strings from crowdin, convert \\$s to \$s
*/

declare(strict_types=1);

return [
# Page Title
"install_page_title" => "%1\$s ក្តារចុច",
"install_page_title" => "%1\$s​ ក្ដារចុច",

# {Keyboard} download should start shortly
"download_start_shortly" =>
Expand Down
15 changes: 15 additions & 0 deletions _includes/locale/strings/keyboards/km.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resultOne": "លទ្ធផល",
"resultMore": "លទ្ធផល",
"pageNumberOfTotalPages": "ទំព័រ​ទី {pageNumber}​ នៃ {totalPages}។",
"keyboardSearchTitle": "- ស្វែងរកក្ដារចុច",
"obsoleteKeyboards": "ក្ដារចុចបោះបង់ចោល",
"monthlyDownloadZero": "គ្មានការទាញយកថ្មីៗ",
"monthlyDownloadOne": "ចំនួនទាញយកប្រចាំខែ",
"monthlyDownloadMore": "ចំនួនទាញយកទាំងឡាយប្រចាំខែ",
"notUnicode": "ចំណាំ៖​ មិនមែនជាក្ដារចុចយូនីកូដ",
"designedForPlatform": "រចនាសម្រាប់ {platform}",
"noMatchesFoundForKeyboard": "គ្មានឃើញចម្លើយសម្រាប់ {keyboard}",
"previousPager": "< មុន",
"nextPager": "បន្ទាប់ >"
}
11 changes: 6 additions & 5 deletions _includes/locale/strings/keyboards/km.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*
* Default Khmer strings for keyboards/index.php
* Default English strings for keyboards/index.php
* When exporting strings from crowdin, convert \\$s to \$s
*/

declare(strict_types=1);
Expand Down Expand Up @@ -42,14 +43,14 @@
# Search box hint: Description
"searchbox_description" =>
"លទ្ធផល​ស្វែងរក​តែងតែ​បង្ហាញ​ជា​បញ្ជី​ក្ដារចុច ។ វាស្វែងរកអំពីឈ្មោះ និងព័ត៌មានលម្អិតរបស់ក្ដារចុច, ឈ្មោះភាសា, ឈ្មោះប្រទេស, និង ឈ្មោះចារឹកនៃក្ដារចុច ។",

# Search box hint (line 2):
"searchbox_hint_2" =>
"អ្នកអាចភ្ជាប់បុព្វបទទាំងនេះ %1\$s (ឈ្មោះក្ដារចុច) %2\$s (ឈ្មោះភាសា) %3\$s (អក្សរចារឹក, ប្រព័ន្ធសរសេរ) ឫ
%4\$s (ឈ្មោះប្រទេស) ដើម្បីធ្វើឱ្យលទ្ធផលស្វែងរកកាន់តែច្បាស់លាស់។ ឧទាហរណ៍ %5\$s ស្វែងរក​នូវ​ក្ដារចុច​សម្រាប់​ភាសា​ទាំងឡាយ​ដែល​ត្រូវបាន​ប្រើប្រាស់​នៅក្នុង​ប្រទេស​ថៃ។",

# Search box hint (line 3):
"searchbox_hint_3" =>
"ការប្រើបុព្វបទ %1\$s ក្នុងការស្វែងរកស្លាកភាសា BCP 47, ឧទាហរណ៍ %2\$s ស្វែងរកភាសា Tigrigna (អេត្យូពី)។"
"searchbox_hint_3" =>
"ការប្រើបុព្វបទ %1\$s ក្នុងការស្វែងរកស្លាកភាសា BCP 47, ឧទាហរណ៍ %2\$s ស្វែងរកភាសា Tigrigna (អេត្យូពី)។",

];
2 changes: 1 addition & 1 deletion _includes/locale/strings/keyboards/share/km.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Keyman is copyright (C) SIL Global. MIT License.
*
* Default English strings for keyboards/keyboard-share.php
* Don't escape $s when uploading source to crowdin because exports will escape \$s to \\$s
* When exporting strings from crowdin, convert \\$s to \$s
*/

declare(strict_types=1);
Expand Down
Loading
Loading