Skip to content

Commit 2a8d2d1

Browse files
authored
Support comm-l10n and search across all projects (#1021)
* Support search across all projects in main UI (it was already supported via API) * Run mozilla-l10n-query locally during setup instead of depending on an external service * Add Thunderbird as a separate project, remove Chatzilla ### Other fixes * Don't show Bugzilla link on reference locale * Remove t2t view * Switch repository from `master` to `main`
1 parent ea2f28b commit 2a8d2d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1083
-806
lines changed

.github/workflows/tests.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: Run Tests
22
on:
3-
# Trigger on push to master
3+
# Trigger on push to the default branch
44
push:
55
branches:
6-
- master
6+
- main
77
# Trigger the workflow on pull request events
8-
# but only for the master branch
8+
# but only for the default branch
99
pull_request:
10-
branches: [ master ]
10+
branches: [ main ]
1111
types: [ opened, synchronize, reopened ]
1212
workflow_dispatch:
1313
jobs:
@@ -58,6 +58,7 @@ jobs:
5858
run: |
5959
cp app/config/config.ini-ghactions app/config/config.ini
6060
vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report
61+
6162
- name: Functional tests (API, pages)
6263
run: |
6364
php tests/functional/api.php

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'no_leading_import_slash' => true,
3737
'no_leading_namespace_whitespace' => true,
3838
'no_singleline_whitespace_before_semicolons' => true,
39-
'no_trailing_comma_in_singleline_array' => true,
39+
'no_trailing_comma_in_singleline' => true,
4040
'no_unused_imports' => true,
4141
'no_whitespace_in_blank_line' => true,
4242
'object_operator_without_whitespace' => true,

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ php-cs-fixer will tell you if it changed some of the files in the repository, do
3838
```bash
3939
git remote add upstream git@github.com:mozfr/transvision.git
4040
```
41-
- Update your master branch to the latest version of Transvision every time you want to do some dev work:
41+
- Update your default branch to the latest version of Transvision every time you want to do some dev work:
4242
```bash
43-
git checkout master
44-
git pull upstream master
43+
git checkout main
44+
git pull upstream main
4545
```
4646
Then switch to a new branch where you will work on the patch you want to propose:
4747
```bash

app/classes/Transvision/API.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ private function isValidServiceCall($service)
231231
*/
232232
if (isset($this->parameters[2])) {
233233
$match = false;
234-
235-
foreach (Project::getRepositories() as $repository) {
234+
foreach (Project::getRepositories(true) as $repository) {
236235
if ($this->verifyLocaleExists($this->parameters[2], $repository)) {
237236
$match = true;
238237
break;
@@ -354,8 +353,8 @@ private function verifyEnoughParameters($number)
354353
private function verifyRepositoryExists($repository, $alias = false)
355354
{
356355
$this->valid_repositories = $alias
357-
? array_merge(Project::getRepositories(), ['global'])
358-
: Project::getRepositories();
356+
? array_merge(Project::getRepositories(true), ['global'])
357+
: Project::getRepositories(true);
359358

360359
if (! in_array($repository, $this->valid_repositories)) {
361360
$this->log("The repo queried ({$repository}) doesn't exist.");

app/classes/Transvision/Project.php

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
*/
1414
class Project
1515
{
16-
/**
17-
* This array maps different subfolders name for Desktop products
18-
* with their display name
19-
*/
20-
public static $components_names = [
21-
'browser' => 'Firefox Desktop',
22-
'mobile' => 'Firefox for Android',
23-
'mail' => 'Thunderbird',
24-
'suite' => 'SeaMonkey',
25-
'calendar' => 'Lightning',
26-
];
27-
2816
/*
2917
* This array contains information about supported repositories.
3018
*
@@ -52,6 +40,9 @@ class Project
5240
*
5341
*/
5442
public static $repos_info = [
43+
'all_projects' => [
44+
'meta' => true,
45+
],
5546
'firefox_ios' => [
5647
'git_repository' => 'firefoxios-l10n',
5748
'locale_mapping' => [
@@ -68,15 +59,21 @@ class Project
6859
'source_type' => 'mixed',
6960
'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'],
7061
],
62+
'comm_l10n'=> [
63+
'source_type' => 'mixed',
64+
'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'],
65+
],
7166
'mozilla_org'=> [
7267
'git_repository' => 'www-l10n',
68+
'git_branch' => 'master',
7369
'pontoon_project' => 'mozillaorg',
7470
'reference_locale' => 'en',
7571
'source_type' => 'mixed',
7672
'variable_patterns' => ['ftl'],
7773
],
7874
'android_l10n' => [
7975
'git_repository' => 'android-l10n',
76+
'git_branch' => 'master',
8077
'locale_mapping' => [], // To avoid using Bugzilla
8178
'pontoon_project' => 'android-l10n',
8279
'source_type' => 'xml',
@@ -100,6 +97,7 @@ class Project
10097
// Desktop products
10198
'desktop' => [
10299
'gecko_strings',
100+
'comm_l10n',
103101
],
104102
// Products using Git
105103
'git' => [
@@ -115,10 +113,12 @@ class Project
115113
/**
116114
* Create a list of all supported repositories.
117115
*
116+
* @param boolean $exclude_meta Exclude meta project
117+
*
118118
* @return array List of supported repositories, key is the repo, value is
119119
* the nice name for the repo for display purposes.
120120
*/
121-
public static function getSupportedRepositories()
121+
public static function getSupportedRepositories($exclude_meta = false)
122122
{
123123
// Read list of repositories from supported_repositories.json
124124
$file_name = APP_SOURCES . 'supported_repositories.json';
@@ -130,6 +130,9 @@ public static function getSupportedRepositories()
130130

131131
$repositories = [];
132132
foreach ($json_repositories as $repository) {
133+
if ($exclude_meta && self::isMetaRepository($repository['id'])) {
134+
continue;
135+
}
133136
$repositories[$repository['id']] = $repository['name'];
134137
}
135138

@@ -139,11 +142,13 @@ public static function getSupportedRepositories()
139142
/**
140143
* Get the list of repositories.
141144
*
145+
* @param boolean $exclude_meta Exclude meta projects
146+
*
142147
* @return array list of local repositories values
143148
*/
144-
public static function getRepositories()
149+
public static function getRepositories($exclude_meta = false)
145150
{
146-
$repositories = array_keys(self::getSupportedRepositories());
151+
$repositories = array_keys(self::getSupportedRepositories($exclude_meta));
147152
sort($repositories);
148153

149154
return $repositories;
@@ -154,11 +159,13 @@ public static function getRepositories()
154159
* The array has repo folder names as keys and Display names as value:
155160
* ex: ['firefox_ios' => 'Firefox for iOS', 'mozilla_org' => 'mozilla.org']
156161
*
162+
* @param boolean $exclude_meta Exclude meta project
163+
*
157164
* @return array list of local repositories and their Display names
158165
*/
159-
public static function getRepositoriesNames()
166+
public static function getRepositoriesNames($exclude_meta = false)
160167
{
161-
return self::getSupportedRepositories();
168+
return self::getSupportedRepositories($exclude_meta);
162169
}
163170

164171
/**
@@ -214,6 +221,23 @@ public static function getRepositoryLocales($repository, $ignored = [])
214221
return $supported_locales;
215222
}
216223

224+
/**
225+
* Get the list of all locales available by looking at the meta project
226+
*
227+
* @return array A sorted list of all supported locales
228+
*/
229+
public static function getAllLocales()
230+
{
231+
$file_name = APP_SOURCES . 'all_projects.txt';
232+
$supported_locales = [];
233+
if (file_exists($file_name)) {
234+
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
235+
}
236+
sort($supported_locales);
237+
238+
return $supported_locales;
239+
}
240+
217241
/**
218242
* Get the list of repositories available for a locale
219243
*
@@ -224,7 +248,7 @@ public static function getRepositoryLocales($repository, $ignored = [])
224248
public static function getLocaleRepositories($locale)
225249
{
226250
$matches = [];
227-
foreach (self::getRepositories() as $repository) {
251+
foreach (self::getRepositories(true) as $repository) {
228252
if (in_array($locale, self::getRepositoryLocales($repository))) {
229253
$matches[] = $repository;
230254
}
@@ -238,7 +262,7 @@ public static function getLocaleRepositories($locale)
238262
/**
239263
* Return the reference locale for a repository
240264
*
241-
* @param string $repository Name of the folder for the repository
265+
* @param string $repository Name of the repository
242266
*
243267
* @return string Name of the reference locale
244268
*/
@@ -249,10 +273,37 @@ public static function getReferenceLocale($repository)
249273
: 'en-US';
250274
}
251275

276+
/**
277+
* Return true if it's a meta repository
278+
*
279+
* @param string $repository Name of the repository
280+
*
281+
* @return boolean True if the repository is set as meta
282+
*/
283+
public static function isMetaRepository($repository)
284+
{
285+
return isset(self::$repos_info[$repository]['meta'])
286+
? self::$repos_info[$repository]['meta']
287+
: false;
288+
}
289+
290+
/**
291+
* Return true if the locale is the reference locale for a repository
292+
*
293+
* @param string $locale Locale code
294+
* @param string $repository Name of the repository
295+
*
296+
* @return boolean True is it's the reference locale
297+
*/
298+
public static function isReferenceLocale($locale, $repository)
299+
{
300+
return self::getReferenceLocale($repository) == $locale;
301+
}
302+
252303
/**
253304
* Check if the specified repository is supported
254305
*
255-
* @param string $repository Name of the folder for the repository
306+
* @param string $repository Name of the repository
256307
*
257308
* @return boolean True if supported repository, False if unknown
258309
*/

app/classes/Transvision/Search.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Search
9898
*/
9999
protected $form_search_options = [
100100
'case_sensitive', 'entire_string', 'repo',
101-
'search_type', 't2t', 'each_word', 'entire_words',
101+
'search_type', 'each_word', 'entire_words',
102102
];
103103

104104
/**
@@ -332,13 +332,23 @@ public function getRegexSearchTerms()
332332
/**
333333
* Grep data in regex
334334
*
335-
* @param array $source_strings The array of strings to be filtered
335+
* @param array $source_strings The array of strings to be filtered
336+
* @param boolean $flat_source If true, the source source is a flat array
336337
*
337338
* @return array Return an array of filtered strings
338339
*/
339-
public function grep($source_strings)
340+
public function grep($source_strings, $flat = true)
340341
{
341-
return preg_grep($this->getRegex(), $source_strings);
342+
if ($flat) {
343+
return preg_grep($this->getRegex(), $source_strings);
344+
} else {
345+
$results = [];
346+
foreach ($source_strings as $repo => $strings) {
347+
$results[$repo] = preg_grep($this->getRegex(), $strings);
348+
}
349+
350+
return $results;
351+
}
342352
}
343353

344354
/**

0 commit comments

Comments
 (0)