Skip to content

Commit d9d6028

Browse files
authored
Use git repos for gecko-strings (#1037)
1 parent 027817f commit d9d6028

File tree

7 files changed

+62
-161
lines changed

7 files changed

+62
-161
lines changed

.github/workflows/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: composer install --prefer-dist
5050

5151
- name: Install Node packages
52-
run: sudo npm install -g eslint
52+
run: sudo npm install -g eslint@8.57.0
5353

5454
- name: Run JS linter (eslint)
5555
run: eslint web/js

app/classes/Transvision/Project.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Project
6060
'variable_patterns' => ['ios'],
6161
],
6262
'gecko_strings'=> [
63+
'git_repository' => 'firefox-l10n',
64+
'git_branch' => 'main',
6365
'source_type' => 'mixed',
6466
'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'],
6567
],
@@ -105,7 +107,8 @@ class Project
105107
],
106108
// Products using Git
107109
'git' => [
108-
'android_l10n', 'firefox_ios', 'mozilla_org', 'vpn_client',
110+
'android_l10n', 'firefox_ios', 'gecko_strings', 'mozilla_org',
111+
'vpn_client',
109112
],
110113
// Products using free text search on Pontoon
111114
'text_search' => [

app/classes/Transvision/VersionControl.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,8 @@ public static function hgPath($locale, $repo, $path)
101101
$exploded_path = explode('/', $path);
102102
$base_folder = $exploded_path[0];
103103

104-
if ($repo == 'comm_l10n') {
105-
$url = "https://hg.mozilla.org/projects/comm-l10n/file/default/{$locale}/";
106-
} else {
107-
if ($locale != 'en-US') {
108-
$url = "https://hg.mozilla.org/l10n-central/{$locale}/file/default/";
109-
} else {
110-
$url = 'https://hg.mozilla.org/l10n/gecko-strings/file/default/';
111-
}
112-
}
104+
# comm-l10n is the last repository using Mercurial
105+
$url = "https://hg.mozilla.org/projects/comm-l10n/file/default/{$locale}/";
113106

114107
return $url . $path . '/' . $entity_file;
115108
}
@@ -135,6 +128,15 @@ public static function gitPath($locale, $repo, $path)
135128
if (isset($repo_data['git_subfolder'])) {
136129
$file_path = "{$repo_data['git_subfolder']}/{$file_path}";
137130
}
131+
if ($repo == 'gecko_strings') {
132+
// Special case for gecko-strings (Firefox)
133+
$file_path = explode(':', $path)[0];
134+
if ($locale == 'en-US') {
135+
return "https://github.com/mozilla-l10n/firefox-l10n-source/blob/main/{$file_path}";
136+
}
137+
138+
return "https://github.com/mozilla-l10n/{$git_repo}/blob/{$git_branch}/{$locale}/{$file_path}";
139+
}
138140
if ($repo == 'android_l10n') {
139141
// Special case for android-l10n (Android)
140142
$locale_android = $locale == 'en-US'

app/scripts/bash_variables.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
folders=( $libraries )
77
path_sources=${config}/sources
88

9-
# Path and list of locales for gecko-strings
10-
gecko_strings_path=${local_hg}/gecko_strings
9+
# Path and list of locales for Gecko locales (Firefox)
10+
gecko_strings_path=${local_git}/gecko_strings
1111
gecko_strings_locales=${path_sources}/gecko_strings.txt
1212
folders+=( $gecko_strings_path )
1313

app/scripts/glossaire.sh

+23-119
Original file line numberDiff line numberDiff line change
@@ -111,147 +111,51 @@ fi
111111
# Create all bash variables
112112
source $script_path/bash_variables.sh
113113

114-
function updateLocale() {
115-
# Update this locale's repository
116-
# $1: Path to l10n repository
117-
# $2: Locale code
118-
# $3: Repository name
119-
120-
# Assign input variables to variables with meaningful names
121-
l10n_path="$1"
122-
locale="$2"
123-
repository_name="$3"
124-
125-
cd $l10n_path/$locale
126-
# Check if there are incoming changesets
127-
hg incoming -r default --bundle incoming.hg 2>&1 >/dev/null
128-
incoming_changesets=$?
129-
if [ $incoming_changesets -eq 0 ]
130-
then
131-
# Update with incoming changesets and remove the bundle
132-
echogreen "Updating $repository_name"
133-
hg pull --update incoming.hg
134-
rm incoming.hg
135-
136-
# Return 1: we need to create the cache for this locale
137-
return 1
138-
else
139-
echogreen "There are no changes to pull for $repository_name"
140-
141-
# Return 0: no need to create the cache
142-
return 0
143-
fi
144-
}
145-
146114
function updateGeckoStrings() {
147115
function buildCache() {
148116
# Build the cache
149-
# $1: Locale code
150-
echogreen "Create cache for $repo_name/$1"
117+
# $1: Path containing locale folder
118+
# $2: Locale code
119+
local path="$1"
120+
local locale="$2"
121+
echogreen "Create cache for $path/$locale"
151122
mkdir -p "${root}TMX/${locale}/"
152-
nice -20 python $install/app/scripts/tmx/tmx_products.py --path $repo_folder/$1/ --locale $1 --ref en-US --repo $repo_name
123+
nice -20 python $install/app/scripts/tmx/tmx_products.py --path $path/$locale/ --locale $locale --ref en-US --repo $repo_name
153124
}
154125

155126
local repo_name="gecko_strings"
156127
local repo_folder="$gecko_strings_path"
157128
local locale_list="gecko_strings_locales"
158129

159-
updated_english=false
130+
# Update en-US, create TMX for en-US
131+
git -C $repo_folder/en-US pull
132+
buildCache $repo_folder en-US
160133

161-
# Store md5 of the existing en-US cache before updating the repositories
162-
cache_file="${root}TMX/en-US/cache_en-US_${repo_name}.php"
163-
if [ -f $cache_file ]
164-
then
165-
existing_md5=($(md5sum $cache_file))
166-
else
167-
existing_md5=0
168-
fi
169-
170-
# Update en-US, create TMX for en-US and check the updated md5
171-
hg --cwd $repo_folder/en-US pull --update -r default
172-
buildCache en-US
173-
updated_md5=($(md5sum $cache_file))
174-
if [ $existing_md5 != $updated_md5 ]
134+
# Pull l10n repository if necessary
135+
if [ "$checkrepo" = true ]
175136
then
176-
echo "English strings have been updated."
177-
updated_english=true
137+
git -C $repo_folder/l10n pull
178138
fi
179139

180140
if [ "$all_locales" = true ]
181141
then
182-
for locale in $(cat ${!locale_list})
183-
do
184-
if [ $locale != "en-US" ]
185-
then
186-
if [ -d $repo_folder/$locale ]
187-
then
188-
updated_locale=0
189-
if [ "$checkrepo" = true ]
190-
then
191-
updateLocale $repo_folder $locale $repo_name/$locale
192-
updated_locale=$?
193-
fi
194-
195-
# Check if we have a cache file for this locale. If it's a brand
196-
# new locale, we'll have the folder and no updates, but we
197-
# still need to create the cache.
198-
cache_file="${root}TMX/${locale}/cache_${locale}_${repo_name}.php"
199-
if [ ! -f $cache_file ]
200-
then
201-
echored "Cache doesn't exist for ${repo_name}/${locale}"
202-
updated_locale=1
203-
else
204-
php -l $cache_file 2>&1 1>/dev/null
205-
if [ $? -ne 0 ]
206-
then
207-
# There are PHP errors, force the rebuild
208-
echored "PHP errors in $cache_file. Forcing rebuild."
209-
updated_locale=1
210-
fi
211-
fi
212-
213-
if [ "$forceTMX" = true -o "$updated_english" = true -o "$updated_locale" -eq 1 ]
214-
then
215-
buildCache $locale
216-
fi
217-
else
218-
echored "Folder $repo_folder/$locale does not exist. Run setup.sh to fix the issue."
219-
fi
220-
fi
221-
done
142+
locales=$(cat ${!locale_list})
222143
else
223-
if [ -d $repo_folder/$locale_code ]
224-
then
225-
updated_locale=0
226-
if [ "$checkrepo" = true ]
227-
then
228-
updateLocale $repo_folder $locale_code $repo_name/$locale_code
229-
updated_locale=$?
230-
fi
144+
locales=($locale_code)
145+
fi
231146

232-
cache_file="${root}TMX/${locale_code}/cache_${locale_code}_${repo_name}.php"
233-
if [ ! -f $cache_file ]
147+
for locale in $locales
148+
do
149+
if [ $locale != "en-US" ]
150+
then
151+
if [ -d $repo_folder/l10n/$locale ]
234152
then
235-
echored "Cache doesn't exist for ${repo_name}/${locale_code}"
236-
updated_locale=1
153+
buildCache $repo_folder/l10n $locale
237154
else
238-
php -l $cache_file 2>&1 1>/dev/null
239-
if [ $? -ne 0 ]
240-
then
241-
# There are PHP errors, force the rebuild
242-
echored "PHP errors in $cache_file. Forcing rebuild."
243-
updated_locale=1
244-
fi
155+
echored "Folder $repo_folder/l10n/$locale does not exist. Run setup.sh to fix the issue."
245156
fi
246-
247-
if [ "$forceTMX" = true -o "$updated_english" = true -o "$updated_locale" -eq 1 ]
248-
then
249-
buildCache $locale_code
250-
fi
251-
else
252-
echored "Folder $repo_folder/$locale_code does not exist."
253157
fi
254-
fi
158+
done
255159
}
256160

257161
function updateCommL10n() {

app/scripts/setup.sh

+13-21
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,23 @@ function setupVirtualEnv() {
4343
function initGeckoStringsRepo() {
4444
local repo_folder="gecko_strings_path"
4545
local repo_path="https://hg.mozilla.org/l10n-central"
46-
local locale_list="gecko_strings_locales"
4746

4847
# If repo_folder="gecko_strings_path", ${!repo_folder} is equal to $gecko_strings_path
4948
cd ${!repo_folder}
5049

51-
# Checkout all locales, including en-US
52-
for locale in $(cat ${!locale_list})
53-
do
54-
if [ ! -d $locale ]
55-
then
56-
mkdir $locale
57-
fi
58-
59-
if [ ! -d $locale/.hg ]
60-
then
61-
echogreen "Checking out the following repo:"
62-
echogreen "$repo_path/$locale/"
63-
if [ "$locale" = "en-US" ]
64-
then
65-
hg clone https://hg.mozilla.org/l10n/gecko-strings/ $locale
66-
else
67-
hg clone $repo_path/$locale $locale
68-
fi
69-
fi
70-
done
50+
# Clone source repository as en-US
51+
if [ ! -d "en-US" ];
52+
then
53+
echogreen "Checking out firefox-l10n-source"
54+
git clone https://github.com/mozilla-l10n/firefox-l10n-source en-US
55+
fi
56+
57+
# Clone l10n monorepo as l10n
58+
if [ ! -d "l10n" ];
59+
then
60+
echogreen "Checking out firefox-l10n-source"
61+
git clone https://github.com/mozilla-l10n/firefox-l10n l10n
62+
fi
7163
}
7264

7365
function initCommL10nRepo() {

tests/units/Transvision/VersionControl.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function getVCSDP()
1515
'mozilla_org', 'git',
1616
],
1717
[
18-
'gecko_strings', 'hg',
18+
'gecko_strings', 'git',
1919
],
2020
[
2121
'firefox_ios', 'git',
@@ -63,12 +63,6 @@ public function testVCSRepoName($a, $b)
6363
public function hgPathDP()
6464
{
6565
return [
66-
[
67-
'fr',
68-
'gecko_strings',
69-
'browser/updater/updater.ini:TitleText',
70-
'https://hg.mozilla.org/l10n-central/fr/file/default/browser/updater/updater.ini',
71-
],
7266
[
7367
'en-US',
7468
'comm_l10n',
@@ -151,11 +145,17 @@ public function testGitPath($a, $b, $c, $d)
151145
public function getPathDP()
152146
{
153147
return [
148+
[
149+
'en-US',
150+
'gecko_strings',
151+
'browser/updater/updater.ini:TitleText',
152+
'https://github.com/mozilla-l10n/firefox-l10n-source/blob/main/browser/updater/updater.ini',
153+
],
154154
[
155155
'fr',
156156
'gecko_strings',
157157
'browser/updater/updater.ini:TitleText',
158-
'https://hg.mozilla.org/l10n-central/fr/file/default/browser/updater/updater.ini',
158+
'https://github.com/mozilla-l10n/firefox-l10n/blob/main/fr/browser/updater/updater.ini',
159159
],
160160
[
161161
'it',

0 commit comments

Comments
 (0)