Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Localize strings on keyboards details 📡 #524

Draft
wants to merge 4 commits into
base: feat/localize/keyboard-search
Choose a base branch
from
Draft
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
119 changes: 70 additions & 49 deletions _includes/includes/ui/keyboard-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
require_once('includes/template.php');
require_once('includes/playstore.php');
require_once('includes/appstore.php');
require_once __DIR__ . '/../../../keyboards/session.php';

use \DateTime;
use \Keyman\Site\com\keyman\KeymanWebHost;
use \Keyman\Site\Common\KeymanHosts;
use Keyman\Site\com\keyman\Locale;

Locale::localize('keyboards-details');

define('GITHUB_ROOT', 'https://github.com/keymanapp/keyboards/tree/master/');
define('DOCUMENTATION_ROOT', KeymanHosts::Instance()->help_keyman_com . '/keyboard/');

Expand Down Expand Up @@ -102,10 +106,10 @@ protected static function WriteDeveloperCloneBox() {
$installLink = 'keyman:keyboard/install/' . rawurlencode(self::$id);
if(!empty(self::$bcp47)) $installLink .= "?bcp47=" . rawurlencode(self::$bcp47);
$h_filename = htmlspecialchars($filename);

$new_project_details = Locale::_s('Fill in New Project Details box below and click OK to clone %1$s.', $h_filename);
return <<<END
<div class="download download-developer">
<div class="download-description">Fill in New Project Details box below and click OK to clone $h_filename.</div>
<div class="download-description">$new_project_details</div>
</div>
END;
// <script>location.href = '$installLink';</script>
Expand All @@ -121,10 +125,13 @@ protected static function download_box($platform) {
$h_filename = htmlspecialchars($filename);
$platformTitle = self::platformTitles[$platform];

// Get the localized strings to pass to heredoc syntax
$install_keyboard = _('Install keyboard');
$install_keyboard_description = Locale::_s('Installs %1$s for %2$s on this device', $h_filename, $platformTitle);
return <<<END
<div class="download download-$platform">
<a class='download-link binary-download' href='$installLink'><span>Install keyboard</span></a>
<div class="download-description">Installs {$h_filename} for $platformTitle on this device</div>
<a class='download-link binary-download' href='$installLink'><span>$install_keyboard</span></a>
<div class="download-description">$install_keyboard_description</div>
</div>
END;
} else {
Expand Down Expand Up @@ -169,11 +176,13 @@ protected static function WriteWebBoxes($useDescription) {
$url = "{$KeymanHosts->keymanweb_com}/#$lang,Keyboard_" . self::GetWebKeyboardId();
if($useDescription) {
$description = htmlentities(self::$keyboard->name);
$description = "<div class=\"download-description\">Use $description in your web browser. No need to install anything.</div>";
$linktext = 'Use keyboard online';
$useKeyboardDescription = Locale::_s('Use %1$s in your web browser. No need to install anything.', $description);
$description = "<div class=\"download-description\">
$useKeyboardDescription</div>";
$linktext = _('Use keyboard online');
} else {
$description = '';
$linktext = 'Full online editor';
$linktext = _('Full online editor');
}
return <<<END
<div class="download download-web">
Expand All @@ -191,7 +200,7 @@ protected static function LoadData() {
if ($s === FALSE) {
// Will fail later in the script
self::$error .= error_get_last()['message'] . "\n";
self::$title = 'Failed to load keyboard package ' . self::$id;
self::$title = Locale::_s('Failed to load keyboard package %1$s', self::$id);
header('HTTP/1.0 404 Keyboard not found');
} else {
$s = json_decode($s);
Expand All @@ -204,19 +213,19 @@ protected static function LoadData() {
self::$minVersion = isset(self::$keyboard->minKeymanVersion) ? self::$keyboard->minKeymanVersion : $stable_version;
self::$license = self::map_license(isset(self::$keyboard->license) ? self::$keyboard->license : 'Unknown');
} else {
self::$error .= "Error returned from {$KeymanHosts->api_keyman_com}: $s\n";
self::$title = 'Failed to load keyboard package ' . self::$id;
self::$error .= Locale::_s('Error returned from %1$s: %2$s', $KeymanHosts->api_keyman_com, "$s\n");
self::$title = Locale::_s('Failed to load keyboard package %1%s', self::$id);
header('HTTP/1.0 500 Internal Server Error');
}
}

if(!empty(self::$keyboard)) {
if (in_array('unicode', self::$keyboard->encodings) && in_array('ansi', self::$keyboard->encodings))
self::$keyboardEncoding = 'Unicode, Legacy (ANSI)';
self::$keyboardEncoding = _('Unicode, Legacy (ANSI)');
else if (in_array('unicode', self::$keyboard->encodings))
self::$keyboardEncoding = 'Unicode';
self::$keyboardEncoding = _('Unicode');
else // ansi
self::$keyboardEncoding = 'Legacy (ANSI)';
self::$keyboardEncoding = _('Legacy (ANSI)');

$date = new DateTime(self::$keyboard->lastModifiedDate);
self::$keyboardLastModifiedDate = $date->format('Y-m-d H:i');
Expand Down Expand Up @@ -321,7 +330,7 @@ protected static function WriteTitle() {
// If parameters are missing ...
?>
<h1 class='red underline'><?= self::$id ?></h1>
<p>Keyboard package <?= self::$id ?> not found.</p>
<p><?= Locale::_s('Keyboard package %1$s not found.', self::$id) ?></p>
<?php
// DEBUG: Only display errors on local sites
global $KeymanHosts;
Expand All @@ -335,7 +344,7 @@ protected static function WriteTitle() {
?>

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

Expand All @@ -345,9 +354,9 @@ protected static function WriteTitle() {

<div id='search-box'>
<form method='get' action='/keyboards' name='f'>
<input id="search-q" type="text" placeholder="New keyboard search" name="q">
<input id="search-q" type="text" placeholder="<?= _('New keyboard search') ?>" name="q">
<input id='search-page' type='hidden' name='page'>
<input id="search-f" type="image" src="<?= cdn('img/search-button.png') ?>" value="Search">
<input id="search-f" type="image" src="<?= cdn('img/search-button.png') ?>" value="<?= _('Search') ?>">
</form>
</div>
<?php
Expand All @@ -363,11 +372,14 @@ protected static function WriteTitle() {
$dep = self::$deprecatedBy;
echo "
<div>
<a href='/keyboards/$dep$session_query_q' class='deprecated'><span>Important note:</span>
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>
<a href='/keyboards/$dep$session_query_q' class='deprecated'>
<span> " . _('Important note:') . " </span>" .
_('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>
</div>
<div>
<p class='deprecated-link'><a href='javascript:toggleDeprecatedVersionDetails()'>View details for obsolete version instead</a></p>
<p class='deprecated-link'><a href='javascript:toggleDeprecatedVersionDetails()'>" .
_('View details for obsolete version instead') . "</a></p>
<div id='deprecated-old'>

";
Expand Down Expand Up @@ -396,7 +408,7 @@ protected static function WriteDownloadBoxes() {

if ($embed_win && isset(self::$keyboard->minKeymanVersion) && version_compare(self::$keyboard->minKeymanVersion, $embed_version) > 0) {
?>
<p>Sorry, this keyboard requires Keyman <?= self::$keyboard->minKeymanVersion ?> or higher.</p>
<p><?= Locale::_s("Sorry, this keyboard requires Keyman %1$s or higher.", self::$keyboard->minKeymanVersion) ?> </p>
<?php
} else {
echo $text;
Expand Down Expand Up @@ -465,7 +477,7 @@ protected static function WriteKeymanWebBox() {
$webtext = self::WriteWebBoxes(false);
$cdnUrlBase = KeymanWebHost::getKeymanWebUrlBase();
?>
<h2 id='try-header' class='red underline'>Try this keyboard</h2>
<h2 id='try-header' class='red underline'><?= _('Try this keyboard') ?></h2>
<div id='try-box'>
<input type='text' id='try-keyboard'>
<div id='osk-host'></div>
Expand Down Expand Up @@ -505,45 +517,46 @@ protected static function WriteKeyboardDetails() {

// this is html, trusted in database
?>
<h2 class='red underline'>Keyboard Details</h2>
<h2 class='red underline'><?= _("Keyboard Details") ?></h2>
<div class='cols' id='keyboard-details-col'>
<div class='col'>

<table id='keyboard-details'>
<tbody>
<tr>
<th>Keyboard ID</th>
<th><?= _("Keyboard ID") ?></th>
<td><?= htmlentities(self::$id) ?></td>
</tr>
<tr>
<th>Supported Platforms</th>
<th><?= _("Supported Platforms") ?></th>
<td><?= self::$keyboardPlatforms ?></td>
</tr>
<tr>
<th>Author</th>
<th><?= _("Author") ?></th>
<td><?= htmlentities(self::$authorName) ?></td>
</tr>
<tr>
<th>License</th>
<th><?= _("License") ?></th>
<td><?= self::$license ?></td>
</tr>
<tr>
<th>Documentation</th>
<th><?= _("Documentation") ?></th>
<td>
<?php
if (isset(self::$keyboard->helpLink)) {
?>
<a <?= $embed_target ?>
href='<?= self::$keyboard->helpLink ?>'>Keyboard help</a>
href='<?= self::$keyboard->helpLink ?>'><?= _("Keyboard help") ?></a>
<?php
} else {
echo "Help not available.";
$helpNotAvailable = _('Help not available.');
echo $helpNotAvailable;
}
?>
</td>
</tr>
<tr>
<th>Source</th>
<th><?= _("Source") ?></th>
<td>
<?php
if (isset(self::$keyboard->sourcePath) && preg_match('/^(release|experimental)\//', self::$keyboard->sourcePath)) {
Expand All @@ -552,15 +565,15 @@ protected static function WriteKeyboardDetails() {
href='<?= GITHUB_ROOT . htmlentities(self::$keyboard->sourcePath) ?>'><?= htmlentities(self::$keyboard->sourcePath) ?></a>
<?php
} else {
echo "Source not available.";
echo _("Source not available.");
} ?>
</td>
<tr>
<th>Keyboard Version</th>
<th><?= _("Keyboard Version") ?></th>
<td><?= htmlentities(self::$keyboard->version) ?></td>
</tr>
<tr>
<th>Last Updated</th>
<th><?= _("Last Updated") ?></th>
<td><?= self::$keyboardLastModifiedDate ?></td>
</tr>
</tbody>
Expand All @@ -575,31 +588,31 @@ protected static function WriteKeyboardDetails() {
if(isset(self::$keyboard->packageFilename)) {
?>
<tr>
<th>Package Download</th>
<th><?= _("Package Download") ?></th>
<td><a href="<?= self::$kmpDownloadUrl ?>" rel="nofollow"><?= self::$keyboard->id ?>.kmp</a></td>
</tr>
<?php
}
?>
<tr>
<th>Monthly Downloads</th>
<th><?= _("Monthly Downloads") ?></th>
<td><?= number_format(self::$downloadCount) ?></td>
</tr>
<tr>
<th>Total Downloads</th>
<td title='Downloads since October 2019'><?= number_format(self::$totalDownloadCount) ?></td>
<th><?= _("Total Downloads") ?></th>
<td title='<?= Locale::_s('Downloads since %1$s', "October 2019") ?>'><?= number_format(self::$totalDownloadCount) ?></td>
</tr>
<tr>
<th>Encoding</th>
<th><?= _("Encoding") ?></th>
<td><?= self::$keyboardEncoding ?></td>
</tr>
<tr>
<th>Minimum Keyman Version</th>
<th><?= Locale::_s('Minimum %1$s Version', "Keyman") ?></th>
<td><?= self::$minVersion ?></td>
</tr>
<?php if (isset(self::$keyboard->related)) { ?>
<tr>
<th>Related Keyboards</th>
<th><?= _("Related Keyboards") ?></th>
<td>
<?php
foreach (self::$keyboard->related as $name => $value) {
Expand All @@ -609,19 +622,25 @@ protected static function WriteKeyboardDetails() {
// schema.
$s = @file_get_contents($KeymanHosts->api_keyman_com . '/keyboard/' . rawurlencode($name));
if ($s === FALSE) {
echo "<span class='keyboard-unavailable' title='This keyboard is not available on {$KeymanHosts->keyman_com_host}'>$hname</span> ";
echo "<span class='keyboard-unavailable' title='" .
Locale::_s('This keyboard is not available on %1$s', $KeymanHosts->keyman_com_host) .
"'>$hname</span> ";
} else {
echo "<a href='/keyboards/$hname$session_query_q'>$hname</a> ";
}
if (isset($value->deprecates) && $value->deprecates) echo " (deprecated) ";
if (isset($value->deprecatedBy) && $value->deprecatedBy) echo " (new version) ";
if (isset($value->deprecates) && $value->deprecates) {
echo _('(deprecated)');
}
if (isset($value->deprecatedBy) && $value->deprecatedBy) {
echo _('(new version)');
}
}
?>
</td>
</tr>
<?php } ?>
<tr>
<th>Supported Languages</th>
<th><?= _("Supported Languages") ?></th>
<td class='supported-languages'>
<?php
(function() {
Expand All @@ -634,8 +653,10 @@ protected static function WriteKeyboardDetails() {

foreach($langs as $bcp47 => $detail) {
if($n == 3) {
echo " <a id='expand-languages' href='#expand-languages'>Expand $count more &gt;&gt;</a>";
echo "<a id='collapse-languages' href='#collapse-languages'>&lt;&lt; Collapse</a> <span class='expand-languages'>";
echo " <a id='expand-languages' href='#expand-languages'>" .
Locale::_s('Expand %1$s more >>', $count) . "</a>";
echo "<a id='collapse-languages' href='#collapse-languages'>" .
_('<< Collapse') . "</a> <span class='expand-languages'>";
}
if (property_exists($detail, 'languageName')) {
echo
Expand All @@ -661,7 +682,7 @@ protected static function WriteKeyboardDetails() {
</div>

<p id='permalink'>
Permanent link to this keyboard:
<?= _("Permanent link to this keyboard:") ?>
<a <?= $embed_target ?> href='<?= KeymanHosts::Instance()->keyman_com ?>/keyboards/<?= self::$keyboard->id ?>'>
<?= KeymanHosts::Instance()->keyman_com ?>/keyboards/<?= self::$keyboard->id ?>
</a>
Expand All @@ -673,7 +694,7 @@ protected static function WriteQRCode($context) {
?>
<div class='qrcode-host qrcode-<?=$context?>'>
<div id="qrcode-<?=$context?>"></div>
<div class='qrcode-caption'>Scan this code to load this keyboard on another device</div>
<div class='qrcode-caption'><?= _("Scan this code to load this keyboard on another device") ?></div>
</div>
<script type="text/javascript">
new QRCode(document.getElementById("qrcode-<?=$context?>"), {
Expand Down
Loading