Skip to content

Commit 043455d

Browse files
TheoChevalierflodolo
authored andcommitted
Display the same info in each mainsearch search type (#762)
* Display the same info in each mainsearch search type * Move error check to a function and test it, stop showing meta links when there is no string * Fix capitalization + undefined variable * Add warning on all translations view * Only hide Translate with, the clipboard icon and string errors
1 parent 8243e2b commit 043455d

5 files changed

Lines changed: 187 additions & 51 deletions

File tree

app/classes/Transvision/ShowResults.php

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public static function resultsTable($search_object, $search_results, $page)
340340
];
341341

342342
$target_string = Strings::multipleStringReplace($replacements, $target_string);
343+
$clipboard_target_string = 'clip_' . md5($target_string);
343344

344345
$temp = explode('-', $locale1);
345346
$locale1_short_code = $temp[0];
@@ -355,49 +356,46 @@ public static function resultsTable($search_object, $search_results, $page)
355356
$locale2_path = VersionControl::hgPath($locale2, $current_repo, $key);
356357
}
357358

358-
// Errors
359-
$error_message = '';
360-
361-
// Check for final dot
362-
if (substr(strip_tags($source_string), -1) == '.'
363-
&& substr(strip_tags($target_string), -1) != '.') {
364-
$error_message = '<em class="error"> No final dot?</em>';
365-
}
359+
// Get the potential errors for $target_string (final dot, long/small string)
360+
$error_message = ShowResults::buildErrorString($source_string, $target_string);
366361

367-
// Check abnormal string length
368-
$length_diff = Utils::checkAbnormalStringLength($source_string, $target_string);
369-
if ($length_diff) {
370-
switch ($length_diff) {
371-
case 'small':
372-
$error_message = $error_message . '<em class="error"> Small string?</em>';
373-
break;
374-
case 'large':
375-
$error_message = $error_message . '<em class="error"> Large String?</em>';
376-
break;
377-
}
378-
}
362+
// Don't show meta links by default
363+
$meta_source = $meta_target = $meta_target2 = '';
379364

380-
// Missing string error
365+
// If there is no source_string, display an error, otherwise display the string + meta links
381366
if (! $source_string) {
382-
$source_string = '<em class="error">warning: missing string</em>';
383-
$error_message = '';
367+
$source_string = '<em class="error">Warning: Source string is empty</em>';
368+
} else {
369+
$meta_source = "
370+
<span>Translate with:</span>
371+
<a href='http://translate.google.com/#{$locale1_short_code}/{$locale2_short_code}/"
372+
// We use html_entity_decode twice because we can have strings as &amp;amp; stored
373+
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
374+
. "' target='_blank'>Google</a>
375+
<a href='http://www.bing.com/translator/?from={$locale1_short_code}&to={$locale2_short_code}&text="
376+
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
377+
. "' target='_blank'>BING</a>";
384378
}
385379

380+
// If there is no target_string, display an error, otherwise display the string + meta links
386381
if (! $target_string) {
387-
$target_string = '<em class="error">warning: missing string</em>';
388-
$error_message = '';
382+
$target_string = '<em class="error">Warning: Missing string</em>';
383+
} else {
384+
$meta_target = "
385+
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>
386+
{$error_message}";
389387
}
390388

389+
// If there is no target_string2, display an error, otherwise display the string + meta links
391390
if (! $target_string2) {
392-
$target_string2 = '<em class="error">warning: missing string</em>';
393-
$error_message = '';
391+
$target_string2 = '<em class="error">Warning: Missing string</em>';
392+
} else {
393+
$meta_target2 = "<span class='clipboard' data-clipboard-target='#{$clipboard_target_string2}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>";
394394
}
395395

396396
// Replace / and : in the key name and use it as an anchor name
397397
$anchor_name = str_replace(['/', ':'], '_', $key);
398398

399-
$clipboard_target_string = 'clip_' . md5($target_string);
400-
401399
// 3locales view
402400
if ($extra_locale) {
403401
if (in_array($current_repo, ['firefox_ios', 'mozilla_org'])) {
@@ -420,9 +418,9 @@ public static function resultsTable($search_object, $search_results, $page)
420418
<a class='bug_link' target='_blank' href='{$bz_link[1]}'>
421419
&lt;report a bug&gt;
422420
</a>
423-
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string2}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>
421+
{$meta_target2}
424422
</div>
425-
</td>";
423+
</td>";
426424
} else {
427425
$extra_column_rows = '';
428426
}
@@ -443,14 +441,7 @@ public static function resultsTable($search_object, $search_results, $page)
443441
<a class='source_link' href='{$locale1_path}'>
444442
&lt;source&gt;
445443
</a>
446-
<span>Translate with:</span>
447-
<a href='http://translate.google.com/#{$locale1_short_code}/{$locale2_short_code}/"
448-
// We use html_entity_decode twice because we can have strings as &amp;amp; stored
449-
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
450-
. "' target='_blank'>Google</a>
451-
<a href='http://www.bing.com/translator/?from={$locale1_short_code}&to={$locale2_short_code}&text="
452-
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
453-
. "' target='_blank'>BING</a>
444+
{$meta_source}
454445
</div>
455446
</td>
456447
@@ -465,8 +456,7 @@ public static function resultsTable($search_object, $search_results, $page)
465456
<a class='bug_link' target='_blank' href='{$bz_link[0]}'>
466457
&lt;report a bug&gt;
467458
</a>
468-
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>
469-
{$error_message}
459+
{$meta_target}
470460
</div>
471461
</td>
472462
{$extra_column_rows}
@@ -508,4 +498,45 @@ public static function searchEntities($source_strings, $regex)
508498

509499
return $entities;
510500
}
501+
502+
/**
503+
* Build the error message for target string. Can return a combination of
504+
* errors, including missing final dot, long string and short string.
505+
*
506+
* @param string $source_string String from the source locale
507+
* @param string $target_string String from the target locale
508+
*
509+
* @return string A concatenated string of errors or an empty string if
510+
* there is no error.
511+
*/
512+
public static function buildErrorString($source_string, $target_string)
513+
{
514+
$error_message = '';
515+
516+
// Check for final dot
517+
if (substr(strip_tags($source_string), -1) == '.'
518+
&& substr(strip_tags($target_string), -1) != '.') {
519+
$error_message = '<em class="error">No final dot?</em> ';
520+
}
521+
522+
// Check abnormal string length
523+
$length_diff = Utils::checkAbnormalStringLength($source_string, $target_string);
524+
if ($length_diff) {
525+
switch ($length_diff) {
526+
case 'small':
527+
$error_message = $error_message . '<em class="error">Small string?</em> ';
528+
break;
529+
case 'large':
530+
$error_message = $error_message . '<em class="error">Large string?</em> ';
531+
break;
532+
}
533+
}
534+
535+
// Missing string error
536+
if (! $source_string || ! $target_string) {
537+
$error_message = '';
538+
}
539+
540+
return $error_message;
541+
}
511542
}

app/views/check_variables.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
<span class='celltitle'>{$source_locale}</span>
5454
<div class='string'>" . Utils::secureText($source[$string_id]) . "</div>
5555
<div class='result_meta_link'>
56-
<a class='source_link' href='{$path_locale1}'><em>&lt;source&gt;</em></a>
56+
<a class='source_link' href='{$path_locale1}'>&lt;source&gt;</a>
5757
</div>
5858
</td>
5959
<td dir='{$direction2}'>
6060
<span class='celltitle'>$locale</span>
6161
<div class='string'>" . Utils::secureText($target[$string_id]) . "</div>
6262
<div class='result_meta_link'>
63-
<a class='source_link' href='{$path_locale2}'><em>&lt;source&gt;</em></a>
63+
<a class='source_link' href='{$path_locale2}'>&lt;source&gt;</a>
6464
<a class='bug_link' target='_blank' href='{$bugzilla_link}'>&lt;report a bug&gt;</a>
6565
</div>
6666
</td>

app/views/onestring.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@
3131
$rtl_support = RTLSupport::isRTL($locale) ? 'dir="rtl"' : '';
3232
$search_link = "/?sourcelocale={$reference_locale}&locale={$locale}&repo={$repo}&search_type=entities&recherche={$entity}&perfect_match=perfect_match";
3333
echo "<tr id='{$locale}'>\n" .
34-
" <th><a href='#{$locale}'>{$locale}</a></th>\n" .
35-
" <td lang='#{$locale}' {$rtl_support} >" . Utils::secureText($translation) . "</td>\n" .
36-
" <td><a class='onestring_search' href='{$search_link}' title='Search for the entity in this locale'>🔍</a></td>\n" .
37-
"</tr>\n";
34+
" <th><a href='#{$locale}'>{$locale}</a></th>\n";
35+
36+
if (! $translation) {
37+
echo " <td><em class='error'>Warning: Missing string</em></td><td></td>\n";
38+
} else {
39+
echo " <td lang='#{$locale}' {$rtl_support} >" . Utils::secureText($translation) . "</td>\n" .
40+
" <td><a class='onestring_search' href='{$search_link}' title='Search for the entity in this locale'>🔍</a></td>\n";
41+
}
42+
43+
"</tr>\n";
3844
}
3945
?>
4046
</table>

app/views/results_entities.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,31 @@
6161
$bz_target_string2, $current_repo, $entity_link)
6262
. '">&lt;report a bug&gt;</a>';
6363

64+
// If there is no target_string2, display an error
65+
if (! $target_string2) {
66+
$target_string2 = '<em class="error">Warning: Missing string</em>';
67+
}
68+
6469
$extra_column_rows = "
6570
<td dir='{$direction3}'>
6671
<span class='celltitle'>{$locale2}</span>
6772
<div class='string'>{$target_string2}</div>
6873
<div dir='ltr' class='result_meta_link'>
69-
<a class='source_link' href='{$path_locale3}'><em>&lt;source&gt;</em></a>
74+
<a class='source_link' href='{$path_locale3}'>&lt;source&gt;</a>
7075
{$file_bug}
7176
</div>
7277
</td>";
7378
} else {
7479
$extra_column_rows = '';
7580
}
7681

82+
// Locale codes for machine translation services
83+
$temp = explode('-', $source_locale);
84+
$locale1_short_code = $temp[0];
85+
86+
$temp = explode('-', $locale);
87+
$locale2_short_code = $temp[0];
88+
7789
// Link to entity
7890
$entity_link = "?sourcelocale={$source_locale}"
7991
. "&locale={$locale}"
@@ -85,6 +97,39 @@
8597
$bz_target_string, $current_repo, $entity_link)
8698
. '">&lt;report a bug&gt;</a>';
8799
$anchor_name = str_replace(['/', ':'], '_', $entity);
100+
101+
$clipboard_target_string = 'clip_' . md5($target_string);
102+
103+
// Get the potential errors for $target_string (final dot, long/small string)
104+
$error_message = ShowResults::buildErrorString($source_string, $target_string);
105+
106+
// Don't show meta links by default
107+
$meta_source = $meta_target = '';
108+
109+
// If there is no source_string, display an error, otherwise display the string + meta links
110+
if (! $source_string) {
111+
$source_string = '<em class="error">Warning: Source string is empty</em>';
112+
} else {
113+
$meta_source = "
114+
<span>Translate with:</span>
115+
<a href='http://translate.google.com/#{$locale1_short_code}/{$locale2_short_code}/"
116+
// We use html_entity_decode twice because we can have strings as &amp;amp; stored
117+
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
118+
. "' target='_blank'>Google</a>
119+
<a href='http://www.bing.com/translator/?from={$locale1_short_code}&to={$locale2_short_code}&text="
120+
. urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string))))
121+
. "' target='_blank'>BING</a>";
122+
}
123+
124+
// If there is no target_string, display an error, otherwise display the string + meta links
125+
if (! $target_string) {
126+
$target_string = '<em class="error">Warning: Missing string</em>';
127+
} else {
128+
$meta_target = "
129+
{$error_message}
130+
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>";
131+
}
132+
88133
$table .= "
89134
<tr>
90135
<td>
@@ -97,15 +142,17 @@
97142
<span class='celltitle'>{$source_locale}</span>
98143
<div class='string'>{$source_string}</div>
99144
<div dir='ltr' class='result_meta_link'>
100-
<a class='source_link' href='{$path_locale1}'><em>&lt;source&gt;</em></a>
145+
<a class='source_link' href='{$path_locale1}'>&lt;source&gt;</a>
146+
{$meta_source}
101147
</div>
102148
</td>
103149
<td dir='{$direction2}'>
104150
<span class='celltitle'>{$locale}</span>
105-
<div class='string'>{$target_string}</div>
151+
<div class='string' id='{$clipboard_target_string}'>{$target_string}</div>
106152
<div dir='ltr' class='result_meta_link'>
107-
<a class='source_link' href='{$path_locale2}'><em>&lt;source&gt;</em></a>
153+
<a class='source_link' href='{$path_locale2}'>&lt;source&gt;</a>
108154
{$file_bug}
155+
{$meta_target}
109156
</div>
110157
</td>
111158
{$extra_column_rows}

tests/units/Transvision/ShowResults.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,56 @@ public function testGetSuggestionsResults()
299299
->array($obj->getSuggestionsResults($source, $target, 'Bookmark', 3))
300300
->isEqualTo(['Bookmark', 'Nouveaux marque-pages']);
301301
}
302+
303+
public function buildErrorStringDP()
304+
{
305+
return [
306+
[
307+
'Le système de marque-pages et.',
308+
'Le système de marque-pages et',
309+
'<em class="error">No final dot?</em> ',
310+
],
311+
[
312+
'Le système de marque-pages et',
313+
'Le système de marque-pages et',
314+
'',
315+
],
316+
[
317+
'Le système de marque-pages et.',
318+
'Le système de marque-pages et.',
319+
'',
320+
],
321+
[
322+
'The bookmarks and history system will not be functional because one of files is in use by another application. Some security software can cause this problem.',
323+
'Le système de marque-pages et',
324+
'<em class="error">No final dot?</em> <em class="error">Small string?</em> ',
325+
],
326+
[
327+
'The bookmarks and history system will not be functional because one of files is in use by another application. Some security software can cause this problem.',
328+
'Le système de marque-pages et.',
329+
'<em class="error">Small string?</em> ',
330+
],
331+
[
332+
'The bookmarks and history system will not be functional because one of files is in use by another application. Some security software can cause this problem.',
333+
'Le système de marque-pages et dhistorique ne sera pas opérationnel car lun des fichiers de %S est en cours dutilisation par une autre application. Certains logiciels de sécurité peuvent causer ce problème. Le système de marque-pages et dhistorique ne sera pas opérationnel car lun des fichiers de %S est en cours dutilisation par une autre application. Certains logiciels de sécurité peuvent causer ce problème',
334+
'<em class="error">No final dot?</em> <em class="error">Large string?</em> ',
335+
],
336+
[
337+
'Le système de marque-pages et',
338+
'Le système de marque-pages et dhistorique ne sera pas opérationnel car lun des fichiers de %S est en cours dutilisation par une autre application. Certains logiciels de sécurité peuvent causer ce problème. Le système de marque-pages et dhistorique ne sera pas opérationnel car lun des fichiers de %S est en cours dutilisation par une autre application. Certains logiciels de sécurité peuvent causer ce problème.',
339+
'<em class="error">Large string?</em> ',
340+
],
341+
];
342+
}
343+
344+
/**
345+
* @dataProvider buildErrorStringDP
346+
*/
347+
public function testBuildErrorString($a, $b, $c)
348+
{
349+
$obj = new _ShowResults();
350+
$this
351+
->string($obj->buildErrorString($a, $b))
352+
->isEqualTo($c);
353+
}
302354
}

0 commit comments

Comments
 (0)