Skip to content

Commit f84266e

Browse files
committed
feat: Localize keyboard details
1 parent 509165c commit f84266e

File tree

4 files changed

+613
-47
lines changed

4 files changed

+613
-47
lines changed

_includes/includes/ui/keyboard-details.php

+68-47
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
require_once('includes/template.php');
55
require_once('includes/playstore.php');
66
require_once('includes/appstore.php');
7+
require_once __DIR__ . '/../../../keyboards/session.php';
78

89
use \DateTime;
910
use \Keyman\Site\com\keyman\KeymanWebHost;
1011
use \Keyman\Site\Common\KeymanHosts;
12+
use Keyman\Site\com\keyman\Locale;
1113

14+
Locale::localize('keyboards-details');
15+
1216
define('GITHUB_ROOT', 'https://github.com/keymanapp/keyboards/tree/master/');
1317
define('DOCUMENTATION_ROOT', KeymanHosts::Instance()->help_keyman_com . '/keyboard/');
1418

@@ -107,10 +111,13 @@ protected static function download_box($platform) {
107111
$h_filename = htmlspecialchars($filename);
108112
$platformTitle = self::platformTitles[$platform];
109113

114+
// Get the localized strings to pass to heredoc syntax
115+
$install_keyboard = _('Install keyboard');
116+
$install_keyboard_description = Locale::_s('Installs %1$s for %2$s on this device', $h_filename, $platformTitle);
110117
return <<<END
111118
<div class="download download-$platform">
112-
<a class='download-link binary-download' href='$installLink'><span>Install keyboard</span></a>
113-
<div class="download-description">Installs {$h_filename} for $platformTitle on this device</div>
119+
<a class='download-link binary-download' href='$installLink'><span>$install_keyboard</span></a>
120+
<div class="download-description">$install_keyboard_description</div>
114121
</div>
115122
END;
116123
} else {
@@ -155,11 +162,13 @@ protected static function WriteWebBoxes($useDescription) {
155162
$url = "{$KeymanHosts->keymanweb_com}/#$lang,Keyboard_" . self::GetWebKeyboardId();
156163
if($useDescription) {
157164
$description = htmlentities(self::$keyboard->name);
158-
$description = "<div class=\"download-description\">Use $description in your web browser. No need to install anything.</div>";
159-
$linktext = 'Use keyboard online';
165+
$useKeyboardDescription = Locale::_s('Use %1$s in your web browser. No need to install anything.', $description);
166+
$description = "<div class=\"download-description\">
167+
$useKeyboardDescription</div>";
168+
$linktext = _('Use keyboard online');
160169
} else {
161170
$description = '';
162-
$linktext = 'Full online editor';
171+
$linktext = _('Full online editor');
163172
}
164173
return <<<END
165174
<div class="download download-web">
@@ -177,7 +186,7 @@ protected static function LoadData() {
177186
if ($s === FALSE) {
178187
// Will fail later in the script
179188
self::$error .= error_get_last()['message'] . "\n";
180-
self::$title = 'Failed to load keyboard package ' . self::$id;
189+
self::$title = Locale::_s('Failed to load keyboard package %1$s', self::$id);
181190
header('HTTP/1.0 404 Keyboard not found');
182191
} else {
183192
$s = json_decode($s);
@@ -190,19 +199,19 @@ protected static function LoadData() {
190199
self::$minVersion = isset(self::$keyboard->minKeymanVersion) ? self::$keyboard->minKeymanVersion : $stable_version;
191200
self::$license = self::map_license(isset(self::$keyboard->license) ? self::$keyboard->license : 'Unknown');
192201
} else {
193-
self::$error .= "Error returned from {$KeymanHosts->api_keyman_com}: $s\n";
194-
self::$title = 'Failed to load keyboard package ' . self::$id;
202+
self::$error .= Locale::_s('Error returned from %1$s: %2$s', $KeymanHosts->api_keyman_com, "$s\n");
203+
self::$title = Locale::_s('Failed to load keyboard package %1%s', self::$id);
195204
header('HTTP/1.0 500 Internal Server Error');
196205
}
197206
}
198207

199208
if(!empty(self::$keyboard)) {
200209
if (in_array('unicode', self::$keyboard->encodings) && in_array('ansi', self::$keyboard->encodings))
201-
self::$keyboardEncoding = 'Unicode, Legacy (ANSI)';
210+
self::$keyboardEncoding = _('Unicode, Legacy (ANSI)');
202211
else if (in_array('unicode', self::$keyboard->encodings))
203-
self::$keyboardEncoding = 'Unicode';
212+
self::$keyboardEncoding = _('Unicode');
204213
else // ansi
205-
self::$keyboardEncoding = 'Legacy (ANSI)';
214+
self::$keyboardEncoding = _('Legacy (ANSI)');
206215

207216
$date = new DateTime(self::$keyboard->lastModifiedDate);
208217
self::$keyboardLastModifiedDate = $date->format('Y-m-d H:i');
@@ -307,7 +316,7 @@ protected static function WriteTitle() {
307316
// If parameters are missing ...
308317
?>
309318
<h1 class='red underline'><?= self::$id ?></h1>
310-
<p>Keyboard package <?= self::$id ?> not found.</p>
319+
<p><?= Locale::_s('Keyboard package %1$s not found.', self::$id) ?></p>
311320
<?php
312321
// DEBUG: Only display errors on local sites
313322
global $KeymanHosts;
@@ -321,7 +330,7 @@ protected static function WriteTitle() {
321330
?>
322331

323332
<div id='search-box'>
324-
<label id='search-new'><a href='/keyboards<?= $session_query_q ?>'>New search</a></label>
333+
<label id='search-new'><a href='/keyboards<?= $session_query_q ?>'><?= _('New search') ?></a></label>
325334
<h1 class='red'><?= self::$title ?></h1>
326335
</div>
327336

@@ -331,9 +340,9 @@ protected static function WriteTitle() {
331340

332341
<div id='search-box'>
333342
<form method='get' action='/keyboards' name='f'>
334-
<input id="search-q" type="text" placeholder="New keyboard search" name="q">
343+
<input id="search-q" type="text" placeholder="<?= _('New keyboard search') ?>" name="q">
335344
<input id='search-page' type='hidden' name='page'>
336-
<input id="search-f" type="image" src="<?= cdn('img/search-button.png') ?>" value="Search">
345+
<input id="search-f" type="image" src="<?= cdn('img/search-button.png') ?>" value="<?= _('Search') ?>">
337346
</form>
338347
</div>
339348
<?php
@@ -349,11 +358,14 @@ protected static function WriteTitle() {
349358
$dep = self::$deprecatedBy;
350359
echo "
351360
<div>
352-
<a href='/keyboards/$dep$session_query_q' class='deprecated'><span>Important note:</span>
353-
This is an obsolete version of this keyboard. Unless you have a good reason, click here to install the new version, called <span>$dep</span>, instead.</a>
361+
<a href='/keyboards/$dep$session_query_q' class='deprecated'>
362+
<span> " . _('Important note:') . " </span>" .
363+
_('This is an obsolete version of this keyboard. Unless you have a good reason, click here to install the new version, called') .
364+
" <span>$dep</span>" . _(', instead.') . "</a>
354365
</div>
355366
<div>
356-
<p class='deprecated-link'><a href='javascript:toggleDeprecatedVersionDetails()'>View details for obsolete version instead</a></p>
367+
<p class='deprecated-link'><a href='javascript:toggleDeprecatedVersionDetails()'>" .
368+
_('View details for obsolete version instead') . "</a></p>
357369
<div id='deprecated-old'>
358370
359371
";
@@ -378,7 +390,7 @@ protected static function WriteDownloadBoxes() {
378390

379391
if ($embed_win && isset(self::$keyboard->minKeymanVersion) && version_compare(self::$keyboard->minKeymanVersion, $embed_version) > 0) {
380392
?>
381-
<p>Sorry, this keyboard requires Keyman <?= self::$keyboard->minKeymanVersion ?> or higher.</p>
393+
<p><?= Locale::_s("Sorry, this keyboard requires Keyman %1$s or higher.", self::$keyboard->minKeymanVersion) ?> </p>
382394
<?php
383395
} else {
384396
echo $text;
@@ -446,7 +458,7 @@ protected static function WriteKeymanWebBox() {
446458
$webtext = self::WriteWebBoxes(false);
447459
$cdnUrlBase = KeymanWebHost::getKeymanWebUrlBase();
448460
?>
449-
<h2 id='try-header' class='red underline'>Try this keyboard</h2>
461+
<h2 id='try-header' class='red underline'><?= _('Try this keyboard') ?></h2>
450462
<div id='try-box'>
451463
<input type='text' id='try-keyboard'>
452464
<div id='osk-host'></div>
@@ -486,45 +498,46 @@ protected static function WriteKeyboardDetails() {
486498

487499
// this is html, trusted in database
488500
?>
489-
<h2 class='red underline'>Keyboard Details</h2>
501+
<h2 class='red underline'><?= _("Keyboard Details") ?></h2>
490502
<div class='cols' id='keyboard-details-col'>
491503
<div class='col'>
492504

493505
<table id='keyboard-details'>
494506
<tbody>
495507
<tr>
496-
<th>Keyboard ID</th>
508+
<th><?= _("Keyboard ID") ?></th>
497509
<td><?= htmlentities(self::$id) ?></td>
498510
</tr>
499511
<tr>
500-
<th>Supported Platforms</th>
512+
<th><?= _("Supported Platforms") ?></th>
501513
<td><?= self::$keyboardPlatforms ?></td>
502514
</tr>
503515
<tr>
504-
<th>Author</th>
516+
<th><?= _("Author") ?></th>
505517
<td><?= htmlentities(self::$authorName) ?></td>
506518
</tr>
507519
<tr>
508-
<th>License</th>
520+
<th><?= _("License") ?></th>
509521
<td><?= self::$license ?></td>
510522
</tr>
511523
<tr>
512-
<th>Documentation</th>
524+
<th><?= _("Documentation") ?></th>
513525
<td>
514526
<?php
515527
if (isset(self::$keyboard->helpLink)) {
516528
?>
517529
<a <?= $embed_target ?>
518-
href='<?= self::$keyboard->helpLink ?>'>Keyboard help</a>
530+
href='<?= self::$keyboard->helpLink ?>'><?= _("Keyboard help") ?></a>
519531
<?php
520532
} else {
521-
echo "Help not available.";
533+
$helpNotAvailable = _('Help not available.');
534+
echo $helpNotAvailable;
522535
}
523536
?>
524537
</td>
525538
</tr>
526539
<tr>
527-
<th>Source</th>
540+
<th><?= _("Source") ?></th>
528541
<td>
529542
<?php
530543
if (isset(self::$keyboard->sourcePath) && preg_match('/^(release|experimental)\//', self::$keyboard->sourcePath)) {
@@ -533,15 +546,15 @@ protected static function WriteKeyboardDetails() {
533546
href='<?= GITHUB_ROOT . htmlentities(self::$keyboard->sourcePath) ?>'><?= htmlentities(self::$keyboard->sourcePath) ?></a>
534547
<?php
535548
} else {
536-
echo "Source not available.";
549+
echo _("Source not available.");
537550
} ?>
538551
</td>
539552
<tr>
540-
<th>Keyboard Version</th>
553+
<th><?= _("Keyboard Version") ?></th>
541554
<td><?= htmlentities(self::$keyboard->version) ?></td>
542555
</tr>
543556
<tr>
544-
<th>Last Updated</th>
557+
<th><?= _("Last Updated") ?></th>
545558
<td><?= self::$keyboardLastModifiedDate ?></td>
546559
</tr>
547560
</tbody>
@@ -556,31 +569,31 @@ protected static function WriteKeyboardDetails() {
556569
if(isset(self::$keyboard->packageFilename)) {
557570
?>
558571
<tr>
559-
<th>Package Download</th>
572+
<th><?= _("Package Download") ?></th>
560573
<td><a href="<?= self::$kmpDownloadUrl ?>" rel="nofollow"><?= self::$keyboard->id ?>.kmp</a></td>
561574
</tr>
562575
<?php
563576
}
564577
?>
565578
<tr>
566-
<th>Monthly Downloads</th>
579+
<th><?= _("Monthly Downloads") ?></th>
567580
<td><?= number_format(self::$downloadCount) ?></td>
568581
</tr>
569582
<tr>
570-
<th>Total Downloads</th>
571-
<td title='Downloads since October 2019'><?= number_format(self::$totalDownloadCount) ?></td>
583+
<th><?= _("Total Downloads") ?></th>
584+
<td title='<?= Locale::_s('Downloads since %1$s', "October 2019") ?>'><?= number_format(self::$totalDownloadCount) ?></td>
572585
</tr>
573586
<tr>
574-
<th>Encoding</th>
587+
<th><?= _("Encoding") ?></th>
575588
<td><?= self::$keyboardEncoding ?></td>
576589
</tr>
577590
<tr>
578-
<th>Minimum Keyman Version</th>
591+
<th><?= Locale::_s('Minimum %1$s Version', "Keyman") ?></th>
579592
<td><?= self::$minVersion ?></td>
580593
</tr>
581594
<?php if (isset(self::$keyboard->related)) { ?>
582595
<tr>
583-
<th>Related Keyboards</th>
596+
<th><?= _("Related Keyboards") ?></th>
584597
<td>
585598
<?php
586599
foreach (self::$keyboard->related as $name => $value) {
@@ -590,19 +603,25 @@ protected static function WriteKeyboardDetails() {
590603
// schema.
591604
$s = @file_get_contents($KeymanHosts->api_keyman_com . '/keyboard/' . rawurlencode($name));
592605
if ($s === FALSE) {
593-
echo "<span class='keyboard-unavailable' title='This keyboard is not available on {$KeymanHosts->keyman_com_host}'>$hname</span> ";
606+
echo "<span class='keyboard-unavailable' title='" .
607+
Locale::_s('This keyboard is not available on %1$s', $KeymanHosts->keyman_com_host) .
608+
"'>$hname</span> ";
594609
} else {
595610
echo "<a href='/keyboards/$hname$session_query_q'>$hname</a> ";
596611
}
597-
if (isset($value->deprecates) && $value->deprecates) echo " (deprecated) ";
598-
if (isset($value->deprecatedBy) && $value->deprecatedBy) echo " (new version) ";
612+
if (isset($value->deprecates) && $value->deprecates) {
613+
echo _('(deprecated)');
614+
}
615+
if (isset($value->deprecatedBy) && $value->deprecatedBy) {
616+
echo _('(new version)');
617+
}
599618
}
600619
?>
601620
</td>
602621
</tr>
603622
<?php } ?>
604623
<tr>
605-
<th>Supported Languages</th>
624+
<th><?= _("Supported Languages") ?></th>
606625
<td class='supported-languages'>
607626
<?php
608627
(function() {
@@ -615,8 +634,10 @@ protected static function WriteKeyboardDetails() {
615634

616635
foreach($langs as $bcp47 => $detail) {
617636
if($n == 3) {
618-
echo " <a id='expand-languages' href='#expand-languages'>Expand $count more &gt;&gt;</a>";
619-
echo "<a id='collapse-languages' href='#collapse-languages'>&lt;&lt; Collapse</a> <span class='expand-languages'>";
637+
echo " <a id='expand-languages' href='#expand-languages'>" .
638+
Locale::_s('Expand %1$s more >>', $count) . "</a>";
639+
echo "<a id='collapse-languages' href='#collapse-languages'>" .
640+
_('<< Collapse') . "</a> <span class='expand-languages'>";
620641
}
621642
if (property_exists($detail, 'languageName')) {
622643
echo
@@ -642,7 +663,7 @@ protected static function WriteKeyboardDetails() {
642663
</div>
643664

644665
<p id='permalink'>
645-
Permanent link to this keyboard:
666+
<?= _("Permanent link to this keyboard:") ?>
646667
<a <?= $embed_target ?> href='<?= KeymanHosts::Instance()->keyman_com ?>/keyboards/<?= self::$keyboard->id ?>'>
647668
<?= KeymanHosts::Instance()->keyman_com ?>/keyboards/<?= self::$keyboard->id ?>
648669
</a>
@@ -654,7 +675,7 @@ protected static function WriteQRCode($context) {
654675
?>
655676
<div class='qrcode-host qrcode-<?=$context?>'>
656677
<div id="qrcode-<?=$context?>"></div>
657-
<div class='qrcode-caption'>Scan this code to load this keyboard on another device</div>
678+
<div class='qrcode-caption'><?= _("Scan this code to load this keyboard on another device") ?></div>
658679
</div>
659680
<script type="text/javascript">
660681
new QRCode(document.getElementById("qrcode-<?=$context?>"), {

0 commit comments

Comments
 (0)