Skip to content

Commit 64dda7a

Browse files
flodoloTheoChevalier
authored andcommitted
Differentiate empty from missing strings (#768)
* Remove padding on error labels * Differentiate empty from missing strings * Fix message in onestring view for empty strings * Fix php-cs error * Don't add empty strings to TMX for missing entities
1 parent 6468f1d commit 64dda7a

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

app/classes/Transvision/ShowResults.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static function getRepositorySearchResults($entities, $array_strings)
162162

163163
foreach ($search_results as $entity => $set) {
164164
// We only want results for which we have a translation
165-
if ($set[1]) {
165+
if ($set[1] != '@@missing@@') {
166166
$output[$entity] = [
167167
$clean_string($set[0]) => $clean_string($set[1]),
168168
];
@@ -181,9 +181,9 @@ public static function getRepositorySearchResults($entities, $array_strings)
181181
*/
182182
public static function getStringFromEntity($entity, $strings)
183183
{
184-
return isset($strings[$entity]) && $strings[$entity] != ''
184+
return isset($strings[$entity])
185185
? $strings[$entity]
186-
: false;
186+
: '@@missing@@';
187187
}
188188

189189
/**
@@ -380,17 +380,21 @@ public static function resultsTable($search_object, $search_results, $page)
380380
}
381381

382382
// If there is no target_string, display an error, otherwise display the string + meta links
383-
if (! $target_string) {
383+
if ($target_string == '@@missing@@') {
384384
$target_string = '<em class="error">Warning: Missing string</em>';
385+
} elseif (! $target_string) {
386+
$target_string = '<em class="error">Warning: Empty string</em>';
385387
} else {
386388
$meta_target = "
387389
<span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>
388390
{$error_message}";
389391
}
390392

391393
// If there is no target_string2, display an error, otherwise display the string + meta links
392-
if (! $target_string2) {
394+
if ($target_string2 == '@@missing@@') {
393395
$target_string2 = '<em class="error">Warning: Missing string</em>';
396+
} elseif (! $target_string2) {
397+
$target_string2 = '<em class="error">Warning: Empty string</em>';
394398
} else {
395399
$meta_target2 = "<span class='clipboard' data-clipboard-target='#{$clipboard_target_string2}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>";
396400
}

app/scripts/tmx_products.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ def create_tmx_content(reference_repo, locale_repo, dirs):
145145
get_strings(l10nPackage_locale, directory, strings_locale)
146146
for entity in strings_reference:
147147
# Append string to tmx_content, using the format of a PHP array
148-
# element
148+
# element, but only if there's a translation available
149149
translation = escape(
150-
strings_locale.get(entity, '')).encode('utf-8')
151-
tmx_content.append("'{0}' => '{1}'".format(
152-
entity.encode('utf-8'), translation))
150+
strings_locale.get(entity, '@@missing@@')).encode('utf-8')
151+
if translation != '@@missing@@':
152+
tmx_content.append("'{0}' => '{1}'".format(
153+
entity.encode('utf-8'), translation))
153154
tmx_content.sort()
154155

155156
return tmx_content
@@ -179,8 +180,7 @@ def main():
179180
args.reference_repo, args.locale_repo, args.repository
180181
)
181182
tmx_content = create_tmx_content(
182-
args.reference_repo, args.locale_repo, dirs
183-
)
183+
args.reference_repo, args.locale_repo, dirs)
184184

185185
# Store the actual file on disk
186186
filename_locale = os.path.join(

app/views/onestring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
" <th><a href='#{$locale}'>{$locale}</a></th>\n";
3535

3636
if (! $translation) {
37-
echo " <td><em class='error'>Warning: Missing string</em></td><td></td>\n";
37+
echo " <td><em class='error'>Warning: Empty string</em></td><td></td>\n";
3838
} else {
3939
echo " <td lang='#{$locale}' {$rtl_support} >" . Utils::secureText($translation) . "</td>\n" .
4040
" <td><a class='onestring_search' href='{$search_link}' title='Search for the entity in this locale'>🔍</a></td>\n";

app/views/productization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<fieldset>
5252
<label>Repository</label>
5353
<select name="product" id="product_select">
54-
' . $product_selector . '
54+
' . $product_selector . '
5555
</select>
5656
</fieldset>
5757
<input type="submit" value="Go" alt="Go" />

app/views/results_entities.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// Escape strings for HTML display
3131
$bz_target_string = $target_string = isset($tmx_target[$entity])
3232
? Utils::secureText($tmx_target[$entity])
33-
: '';
33+
: '@@missing@@';
3434
// Highlight non-breaking spaces only after strings have been escaped
3535
$target_string = str_replace(' ', '<span class="highlight-gray"> </span>', $target_string);
3636

@@ -63,8 +63,10 @@
6363
. '">&lt;report a bug&gt;</a>';
6464

6565
// If there is no target_string2, display an error
66-
if (! $target_string2) {
66+
if ($target_string2 == '@@missing@@') {
6767
$target_string2 = '<em class="error">Warning: Missing string</em>';
68+
} elseif (! $target_string2) {
69+
$target_string2 = '<em class="error">Warning: Empty string</em>';
6870
}
6971

7072
$extra_column_rows = "
@@ -124,8 +126,10 @@
124126
}
125127

126128
// If there is no target_string, display an error, otherwise display the string + meta links
127-
if (! $target_string) {
129+
if ($target_string == '@@missing@@') {
128130
$target_string = '<em class="error">Warning: Missing string</em>';
131+
} elseif (! $target_string) {
132+
$target_string = '<em class="error">Warning: Empty string</em>';
129133
} else {
130134
$meta_target = "
131135
{$error_message}

tests/units/Transvision/ShowResults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ public function getStringFromEntityDP()
134134
[
135135
'browser/pdfviewer/viewer.properties:last_page.label',
136136
['entity.is.not.found' => 'Aller à la dernière page'],
137-
false,
137+
'@@missing@@',
138138
],
139139
[
140140
'browser/pdfviewer/viewer.properties:last_page.label',
141141
['browser/pdfviewer/viewer.properties:last_page.label' => ''],
142-
false,
142+
'',
143143
],
144144
];
145145
}

web/style/transvision.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ td em.error {
347347
color: #f00;
348348
}
349349

350-
td em.error {
351-
padding-left: 6px;
352-
}
353-
354350
td a.tag {
355351
font-size: 75%;
356352
color: #808080;

0 commit comments

Comments
 (0)