Skip to content

Commit 4153e53

Browse files
committed
Add support for VPN Client
1 parent 2a53225 commit 4153e53

8 files changed

Lines changed: 60 additions & 10 deletions

File tree

app/classes/Transvision/AnalyseStrings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static function differences($tmx_source, $tmx_target, $repo, $ignored_str
6060
'properties' => '/(?<!%[0-9]|\{\s|\{)(\$[A-Za-z0-9\.]+)\b/',
6161
// %1$s or %s. %d
6262
'xml_android' => '/(%(?:[0-9]+\$){0,1}([sd]))/',
63+
// %1, %2, etc.
64+
'xliff-qt' => '/(%[0-9])/',
6365
];
6466
$repo_patterns = Project::$repos_info[$repo]['variable_patterns'];
6567

app/classes/Transvision/Project.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ class Project
8282
'source_type' => 'xml',
8383
'variable_patterns' => ['xml_android'],
8484
],
85+
'vpn_client' => [
86+
'files' => [
87+
'mozillavpn.xliff',
88+
],
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'],
94+
],
8595
];
8696

8797
/*
@@ -95,7 +105,7 @@ class Project
95105
],
96106
// Products using Git
97107
'git' => [
98-
'android_l10n', 'firefox_ios', 'mozilla_org',
108+
'android_l10n', 'firefox_ios', 'mozilla_org', 'vpn_client',
99109
],
100110
// Products using free text search on Pontoon
101111
'text_search' => [

app/classes/Transvision/Xliff.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ class Xliff
1414
*
1515
* Loads strings from a .xliff file
1616
*
17-
* @param string $xliff_path Path to the .xliff to load
18-
* @param string $project_name The project this string belongs to
17+
* @param string $xliff_path Path to the .xliff to load
18+
* @param string $project_name The project this string belongs to
19+
* @param boolean $reference_locale If the current file belongs to the reference locale
1920
*
2021
* @return array Array of strings as [string_id => translation]
2122
*/
22-
public static function getStrings($xliff_path, $project_name)
23+
public static function getStrings($xliff_path, $project_name, $reference_locale = false)
2324
{
2425
$strings = [];
2526
if ($xml = simplexml_load_file($xliff_path)) {
@@ -36,7 +37,10 @@ public static function getStrings($xliff_path, $project_name)
3637
$file_orig = $file_node[0]['original'];
3738

3839
$string_id = self::generateStringID($project_name, $file_name, $file_orig, $trans_unit['id']);
39-
$translation = str_replace("'", "\\'", $trans_unit->target);
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);
4044

4145
$strings[$string_id] = $translation;
4246
}

app/scripts/bash_variables.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ folders+=( $gecko_strings_path $sources_path )
1616
mozilla_org=$local_git/mozilla_org/
1717
folders+=( $mozilla_org )
1818

19-
# Firefox for iOS, Android-l10n
20-
firefox_ios=$local_git/firefox_ios/
19+
# Firefox for iOS, Android-l10n, VPN Client
2120
android_l10n=$local_git/android_l10n/
22-
folders+=( $firefox_ios $android_l10n)
21+
firefox_ios=$local_git/firefox_ios/
22+
vpn_client=$local_git/vpn_client/
23+
folders+=( $firefox_ios $android_l10n $vpn_client)

app/scripts/glossaire.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ source $install/python-venv/bin/activate || exit 1
311311
updateGeckoStringsChannelRepo
312312
updateMozOrg
313313
updateOtherProduct firefox_ios "Firefox for iOS" tmx_xliff
314+
updateOtherProduct vpn_client "Mozilla VPN Client" tmx_xliff
314315
updateAndroidl10n
315316

316317
# Create a file to get the timestamp of the last string extraction for caching

app/scripts/setup.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,17 @@ fi
165165
cd $android_l10n
166166
if [ ! -d $android_l10n/.git ]
167167
then
168-
echogreen "Checking out Focus for android-l10n repo"
168+
echogreen "Checking out android-l10n repo"
169169
git clone https://github.com/mozilla-l10n/android-l10n .
170170
fi
171171

172+
cd $vpn_client
173+
if [ ! -d $vpn_client/.git ]
174+
then
175+
echogreen "Checking out VPN Client repo"
176+
git clone https://github.com/mozilla-l10n/mozilla-vpn-client-l10n .
177+
fi
178+
172179
# Add .htaccess to download folder. Folder should already exists, but check in
173180
# advance to be sure. I overwrite an existing .htaccess if already present.
174181
echogreen "Add .htaccess to download folder"

app/scripts/tmx/tmx_xliff

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ foreach (Files::getFoldersInPath($base_path, ['templates']) as $locale) {
4343
foreach ($repo_data['files'] as $file_name) {
4444
$xliff_path = "{$base_path}/{$locale}/{$file_name}";
4545
if (file_exists($xliff_path)) {
46-
$strings = Xliff::getStrings($xliff_path, $project_name);
46+
// Make sure there is a reference locale defined
47+
$reference_locale = isset($repo_data['reference_locale'])
48+
? $repo_data['reference_locale']
49+
: 'en-US';
50+
$is_reference_locale = $locale == $reference_locale;
51+
$strings = Xliff::getStrings($xliff_path, $project_name, $is_reference_locale);
4752
$total_strings = count($strings);
4853
foreach ($strings as $string_id => $translation) {
4954
$out_translation .= "'{$string_id}' => '{$translation}', \n";

tests/units/Transvision/Xliff.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ public function testGetStrings()
2828
->isEqualTo('Segnalibri pc desktop');
2929
}
3030

31+
public function testGetStringsReference()
32+
{
33+
$obj = new _Xliff();
34+
$strings = $obj->getStrings(TEST_FILES . 'xliff/firefox-ios.xliff', 'firefox_ios', true);
35+
36+
// Check total number of strings
37+
$this
38+
->integer(count($strings))
39+
->isEqualTo(14);
40+
41+
// Check strings
42+
$this
43+
->string($strings['firefox_ios/firefox-ios.xliff:4c8cc9416b11b77e88809ff17e7f180e'])
44+
->isEqualTo('Browsing History');
45+
46+
$this
47+
->string($strings['firefox_ios/firefox-ios.xliff:f6b6d1aff4ade5b867d563d74b01a429'])
48+
->isEqualTo('Desktop Bookmarks');
49+
}
50+
3151
public function generateStringID_DP()
3252
{
3353
return [

0 commit comments

Comments
 (0)