Skip to content

Commit 4719efc

Browse files
authored
Improve support for VPN and XLIFF (#1003)
* Consider underscores vs hyphen when extracting XLIFF * Support underscores in VCS links * Fix Pontoon edit link for VPN client * XLIFF: Don't consider missing strings as empty strings * Ignore folders in clean-up script for VPN
2 parents ffcf95b + 81c7e53 commit 4719efc

8 files changed

Lines changed: 44 additions & 15 deletions

File tree

app/classes/Transvision/Project.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Project
3838
*
3939
* locale_mapping: if locale codes need to be mapped (Mozilla code -> Repo code)
4040
*
41+
* underscore_locale: set to true if using underscores as separator (en_CA)
42+
* instead of hyphens (en-CA)
43+
*
4144
* pontoon_project: name of the project in Pontoon
4245
*
4346
* source_type: source type used by the project (xliff, gettext, etc.)
@@ -83,14 +86,15 @@ class Project
8386
'variable_patterns' => ['xml_android'],
8487
],
8588
'vpn_client' => [
86-
'files' => [
89+
'files' => [
8790
'mozillavpn.xliff',
8891
],
89-
'git_repository' => 'mozilla-vpn-client-l10n',
90-
'pontoon_project' => 'mozilla-vpn-client',
91-
'reference_locale' => 'en',
92-
'source_type' => 'xliff',
93-
'variable_patterns' => ['xliff-qt'],
92+
'git_repository' => 'mozilla-vpn-client-l10n',
93+
'underscore_locales' => true,
94+
'pontoon_project' => 'mozilla-vpn-client',
95+
'reference_locale' => 'en',
96+
'source_type' => 'xliff',
97+
'variable_patterns' => ['xliff-qt'],
9498
],
9599
];
96100

@@ -110,6 +114,7 @@ class Project
110114
// Products using free text search on Pontoon
111115
'text_search' => [
112116
'firefox_ios',
117+
'vpn_client',
113118
],
114119
];
115120

app/classes/Transvision/VersionControl.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public static function getPath($locale, $repo, $path)
6161
{
6262
$vcs = self::getVCS($repo);
6363

64+
$repo_data = Project::$repos_info[$repo];
65+
$locale = isset($repo_data['underscore_locales']) && $repo_data['underscore_locales']
66+
? str_replace('-', '_', $locale)
67+
: $locale;
68+
6469
switch ($vcs) {
6570
case 'git':
6671
$path = self::gitPath($locale, $repo, $path);

app/classes/Transvision/Xliff.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ public static function getStrings($xliff_path, $project_name, $reference_locale
3737
$file_orig = $file_node[0]['original'];
3838

3939
$string_id = self::generateStringID($project_name, $file_name, $file_orig, $trans_unit['id']);
40-
// If it's the reference locale, we use the source instead of the target
41-
$translation = $reference_locale
42-
? str_replace("'", "\\'", $trans_unit->source)
43-
: str_replace("'", "\\'", $trans_unit->target);
4440

45-
$strings[$string_id] = $translation;
41+
if ($reference_locale) {
42+
// If it's the reference locale, we use the source instead of the target
43+
$translation = str_replace("'", "\\'", $trans_unit->source);
44+
$strings[$string_id] = $translation;
45+
} elseif (isset($trans_unit->target)) {
46+
/*
47+
We only store the translation if the target is set.
48+
simplexml returns an empty string if the element is
49+
missing.
50+
*/
51+
$translation = str_replace("'", "\\'", $trans_unit->target);
52+
$strings[$string_id] = $translation;
53+
}
4654
}
4755
}
4856

app/scripts/clean_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def main():
9494
excluded_folders = {
9595
"firefox_ios": [".git", "templates"],
9696
"mozilla_org": [".git", "configs", "en"],
97+
"vpn_client": [".git", ".github", "en"],
9798
}
9899

99100
"""

app/scripts/tmx/tmx_xliff

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ error_log('Extraction of strings from XLIFF file');
3636
$base_path = isset($repo_data['git_subfolder'])
3737
? GIT . "{$project_name}/{$repo_data['git_subfolder']}"
3838
: GIT . $project_name;
39-
foreach (Files::getFoldersInPath($base_path, ['templates']) as $locale) {
39+
foreach (Files::getFoldersInPath($base_path, ['templates']) as $locale_folder) {
4040
$out_translation = '';
4141
$total_strings = 0;
4242

43+
# Always use hyphens for locale codes
44+
$locale = isset($repo_data['underscore_locales']) && $repo_data['underscore_locales']
45+
? str_replace('_', '-', $locale_folder)
46+
: $locale_folder;
47+
4348
foreach ($repo_data['files'] as $file_name) {
44-
$xliff_path = "{$base_path}/{$locale}/{$file_name}";
49+
$xliff_path = "{$base_path}/{$locale_folder}/{$file_name}";
4550
if (file_exists($xliff_path)) {
4651
// Make sure there is a reference locale defined
4752
$reference_locale = isset($repo_data['reference_locale'])

tests/testfiles/xliff/firefox-ios.xliff

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
</trans-unit>
8787
<trans-unit id="Cookies">
8888
<source>Cookies</source>
89-
<target>Cookie</target>
9089
</trans-unit>
9190
</body>
9291
</file>

tests/units/Transvision/VersionControl.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ public function getPathDP()
163163
'firefox_ios/firefox-ios.xliff:0f4d892c',
164164
'https://github.com/mozilla-l10n/firefoxios-l10n/blob/master/it/firefox-ios.xliff',
165165
],
166+
[
167+
'sv-SE',
168+
'vpn_client',
169+
'vpn_client/mozillavpn.xliff.xliff:0f4d892c',
170+
'https://github.com/mozilla-l10n/mozilla-vpn-client-l10n/blob/master/sv_SE/mozillavpn.xliff.xliff',
171+
],
166172
];
167173
}
168174

tests/units/Transvision/Xliff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testGetStrings()
1616
// Check total number of strings
1717
$this
1818
->integer(count($strings))
19-
->isEqualTo(14);
19+
->isEqualTo(13);
2020

2121
// Check strings
2222
$this

0 commit comments

Comments
 (0)