Skip to content

Commit 631e6cf

Browse files
committed
Backport tranliterate button into entity view
1 parent 382ee5f commit 631e6cf

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

app/classes/Transvision/ShowResults.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ public static function getTransliteratedString($string, $locale)
157157
$request = new API(parse_url(API_ROOT . "transliterate/$locale/$string"));
158158
$json = include MODELS . 'api/transliterate.php';
159159

160-
return $json[0];
160+
return isset($json[0]) ? $json[0] : 'Function not available';
161161
}
162+
162163
/**
163164
* Return search results in a repository on strings/entities for the API
164165
*
@@ -316,7 +317,7 @@ public static function resultsTable($search_object, $search_results, $page)
316317

317318
/*
318319
Find if we need to transliterate the string.
319-
The string gets transliterated if the target local is serbian,
320+
The string gets transliterated if the target local is Serbian,
320321
if we aren't in the 3locales view and if we have a $target_string
321322
*/
322323
$transliterate = $locale2 == 'sr' && ! $extra_locale && $target_string && $target_string != '@@missing@@';
@@ -349,6 +350,7 @@ public static function resultsTable($search_object, $search_results, $page)
349350
if ($transliterate) {
350351
$transliterated_string = htmlspecialchars($transliterated_string);
351352
$transliterated_string = Utils::highlightString($transliterated_string);
353+
$transliterated_string = Strings::highlightSpecial($transliterated_string);
352354
}
353355

354356
if ($extra_locale) {

app/inc/constants.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
define('CACHE_ENABLED', isset($_GET['nocache']) ? false : true);
1818
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
1919
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
20-
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
20+
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
2121

2222
/*
2323
Determine the last Git hash from cache/version.txt, ignoring new lines.

app/models/api/transliterate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
$transliterator = \Transliterator::create($transliterated_locale);
2323

24-
return [html_entity_decode($transliterator->transliterate(Utils::secureText(urldecode($request->parameters[3]))))];
24+
return [$transliterator->transliterate(urldecode($request->parameters[3]))];

app/views/results_entities.php

+30-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<tbody>\n";
1818

1919
$current_repo = $search->getRepository();
20+
$extra_locale = $url['path'] == '3locales';
21+
2022
// Display results
2123
foreach ($entities as $entity) {
2224
if (in_array($current_repo, ['firefox_ios', 'mozilla_org'])) {
@@ -31,17 +33,34 @@
3133
$bz_target_string = $target_string = isset($tmx_target[$entity])
3234
? Utils::secureText($tmx_target[$entity])
3335
: '@@missing@@';
36+
3437
// Highlight special characters only after strings have been escaped
3538
$target_string = Strings::highlightSpecial($target_string);
3639
$source_string = Strings::highlightSpecial(Utils::secureText($tmx_source[$entity]));
3740

3841
$clipboard_target_string = 'clip_' . md5($target_string);
42+
$string_id = md5($entity . mt_rand());
43+
$regular_string_id = 'string_' . $string_id;
44+
45+
/*
46+
Find if we need to transliterate the string.
47+
The string gets transliterated if the target local is serbian,
48+
if we aren't in the 3locales view and if we have a $target_string
49+
*/
50+
$transliterate = $locale == 'sr' && ! $extra_locale && $target_string && $target_string != '@@missing@@';
51+
52+
if ($transliterate) {
53+
$transliterated_string = Utils::secureText($tmx_target[$entity]);
54+
$transliterated_string = ShowResults::getTransliteratedString(urlencode($transliterated_string), 'sr-Cyrl');
55+
$transliterated_string = Strings::highlightSpecial($transliterated_string);
56+
$transliterate_string_id = 'transliterate_' . $string_id;
57+
}
3958

4059
// Don't show meta links by default
4160
$meta_source = $meta_target = $meta_target2 = '';
4261

4362
// 3locales view
44-
if ($url['path'] == '3locales') {
63+
if ($extra_locale) {
4564
$bz_target_string2 = $target_string2 = isset($tmx_target2[$entity])
4665
? Utils::secureText($tmx_target2[$entity])
4766
: '';
@@ -135,9 +154,11 @@
135154
} elseif (! $target_string) {
136155
$target_string = '<em class="error">Warning: Empty string</em>';
137156
} else {
138-
$meta_target = "
139-
{$error_message}
140-
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'></span>";
157+
$meta_target = "<span class='clipboard' data-clipboard-target='#{$regular_string_id}' alt='Copy to clipboard'></span>";
158+
if ($transliterate) {
159+
$meta_target .= "<input type='button' value='To Latin' data-transliterated-id='{$string_id}' class='transliterate_button button action'>";
160+
}
161+
$meta_target .= $error_message;
141162
}
142163

143164
$table .= "
@@ -158,7 +179,11 @@
158179
</td>
159180
<td dir='{$direction2}'>
160181
<span class='celltitle'>{$locale}</span>
161-
<div class='string' id='{$clipboard_target_string}'>{$target_string}</div>
182+
<div class='string' id='{$regular_string_id}'>{$target_string}</div>";
183+
if ($transliterate) {
184+
$table .= "<div class='string toggle' id='{$transliterate_string_id}' style='display: none;'>{$transliterated_string}</div>";
185+
}
186+
$table .= "
162187
<div dir='ltr' class='result_meta_link'>
163188
<a class='source_link' href='{$path_locale2}'>&lt;source&gt;</a>
164189
{$file_bug}

web/js/toggle_transliterated_string.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ $(document).ready(function() {
88
$transliterated.toggle();
99
if ($normal.css('display') === 'none') {
1010
$(this).val('To Cyrillic');
11-
$('span[data-clipboard-target="#string_'+id+'"]').attr('data-clipboard-target', '#transliterate_' + id);
11+
$('span[data-clipboard-target="#string_' + id + '"]').attr('data-clipboard-target', '#transliterate_' + id);
1212
} else {
1313
$(this).val('To Latin');
14-
$('span[data-clipboard-target="#transliterate_' + id +'"]').attr('data-clipboard-target', '#string_' + id);
14+
$('span[data-clipboard-target="#transliterate_' + id + '"]').attr('data-clipboard-target', '#string_' + id);
1515
}
1616
});
1717
});

0 commit comments

Comments
 (0)