Permalink
Browse files

Backport tranliterate button into entity view

  • Loading branch information...
TheoChevalier committed Aug 4, 2016
1 parent 382ee5f commit 631e6cf7f2c2b3d06fe186d2bfcb7ca1f67081c1
@@ -157,8 +157,9 @@ public static function getTransliteratedString($string, $locale)
$request = new API(parse_url(API_ROOT . "transliterate/$locale/$string"));
$json = include MODELS . 'api/transliterate.php';
return $json[0];
return isset($json[0]) ? $json[0] : 'Function not available';
}
/**
* Return search results in a repository on strings/entities for the API
*
@@ -316,7 +317,7 @@ public static function resultsTable($search_object, $search_results, $page)
/*
Find if we need to transliterate the string.
The string gets transliterated if the target local is serbian,
The string gets transliterated if the target local is Serbian,
if we aren't in the 3locales view and if we have a $target_string
*/
$transliterate = $locale2 == 'sr' && ! $extra_locale && $target_string && $target_string != '@@missing@@';
@@ -349,6 +350,7 @@ public static function resultsTable($search_object, $search_results, $page)
if ($transliterate) {
$transliterated_string = htmlspecialchars($transliterated_string);
$transliterated_string = Utils::highlightString($transliterated_string);
$transliterated_string = Strings::highlightSpecial($transliterated_string);
}
if ($extra_locale) {
View
@@ -17,7 +17,7 @@
define('CACHE_ENABLED', isset($_GET['nocache']) ? false : true);
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
/*
Determine the last Git hash from cache/version.txt, ignoring new lines.
@@ -21,4 +21,4 @@
$transliterator = \Transliterator::create($transliterated_locale);
return [html_entity_decode($transliterator->transliterate(Utils::secureText(urldecode($request->parameters[3]))))];
return [$transliterator->transliterate(urldecode($request->parameters[3]))];
@@ -17,6 +17,8 @@
<tbody>\n";
$current_repo = $search->getRepository();
$extra_locale = $url['path'] == '3locales';
// Display results
foreach ($entities as $entity) {
if (in_array($current_repo, ['firefox_ios', 'mozilla_org'])) {
@@ -31,17 +33,34 @@
$bz_target_string = $target_string = isset($tmx_target[$entity])
? Utils::secureText($tmx_target[$entity])
: '@@missing@@';
// Highlight special characters only after strings have been escaped
$target_string = Strings::highlightSpecial($target_string);
$source_string = Strings::highlightSpecial(Utils::secureText($tmx_source[$entity]));
$clipboard_target_string = 'clip_' . md5($target_string);
$string_id = md5($entity . mt_rand());
$regular_string_id = 'string_' . $string_id;
/*
Find if we need to transliterate the string.
The string gets transliterated if the target local is serbian,
if we aren't in the 3locales view and if we have a $target_string
*/
$transliterate = $locale == 'sr' && ! $extra_locale && $target_string && $target_string != '@@missing@@';
if ($transliterate) {
$transliterated_string = Utils::secureText($tmx_target[$entity]);
$transliterated_string = ShowResults::getTransliteratedString(urlencode($transliterated_string), 'sr-Cyrl');
$transliterated_string = Strings::highlightSpecial($transliterated_string);
$transliterate_string_id = 'transliterate_' . $string_id;
}
// Don't show meta links by default
$meta_source = $meta_target = $meta_target2 = '';
// 3locales view
if ($url['path'] == '3locales') {
if ($extra_locale) {
$bz_target_string2 = $target_string2 = isset($tmx_target2[$entity])
? Utils::secureText($tmx_target2[$entity])
: '';
@@ -135,9 +154,11 @@
} elseif (! $target_string) {
$target_string = '<em class="error">Warning: Empty string</em>';
} else {
$meta_target = "
{$error_message}
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'></span>";
$meta_target = "<span class='clipboard' data-clipboard-target='#{$regular_string_id}' alt='Copy to clipboard'></span>";
if ($transliterate) {
$meta_target .= "<input type='button' value='To Latin' data-transliterated-id='{$string_id}' class='transliterate_button button action'>";
}
$meta_target .= $error_message;
}
$table .= "
@@ -158,7 +179,11 @@
</td>
<td dir='{$direction2}'>
<span class='celltitle'>{$locale}</span>
<div class='string' id='{$clipboard_target_string}'>{$target_string}</div>
<div class='string' id='{$regular_string_id}'>{$target_string}</div>";
if ($transliterate) {
$table .= "<div class='string toggle' id='{$transliterate_string_id}' style='display: none;'>{$transliterated_string}</div>";
}
$table .= "
<div dir='ltr' class='result_meta_link'>
<a class='source_link' href='{$path_locale2}'>&lt;source&gt;</a>
{$file_bug}
@@ -8,10 +8,10 @@ $(document).ready(function() {
$transliterated.toggle();
if ($normal.css('display') === 'none') {
$(this).val('To Cyrillic');
$('span[data-clipboard-target="#string_'+id+'"]').attr('data-clipboard-target', '#transliterate_' + id);
$('span[data-clipboard-target="#string_' + id + '"]').attr('data-clipboard-target', '#transliterate_' + id);
} else {
$(this).val('To Latin');
$('span[data-clipboard-target="#transliterate_' + id +'"]').attr('data-clipboard-target', '#string_' + id);
$('span[data-clipboard-target="#transliterate_' + id + '"]').attr('data-clipboard-target', '#string_' + id);
}
});
});

0 comments on commit 631e6cf

Please sign in to comment.