Skip to content

Commit

Permalink
Improve FTL support (#927)
Browse files Browse the repository at this point in the history
* Fix edit_link for FTL strings
* Add variable checks for FTL
  • Loading branch information
flodolo authored Jan 3, 2018
1 parent c4d8d6e commit e93e594
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/classes/Transvision/AnalyseStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public static function differences($tmx_source, $tmx_target, $repo, $ignored_str

$patterns = [
'dtd' => '/&([A-Za-z0-9\.]+);/', // &foobar;
'printf' => '/(%(?:[0-9]+\$){0,1}(?:[0-9].){0,1}([sS]))/', // %1$S or %S. %1$0.S and %0.S are valid too
'properties' => '/(?<!%[0-9])\$[A-Za-z0-9\.]+\b/', // $BrandShortName, but not "My%1$SFeeds-%2$S.opml"
'l10njs' => '/\{\{\s*([A-Za-z0-9_]+)\s*\}\}/u', // {{foobar2}} Used in Loop and PDFViewer
'ftl' => '/\{\s*(\$[A-Za-z0-9_]+)\s*\}/u', // { $foobar } Used in FTL files
'ios' => '/(%(?:[0-9]+\$){0,1}@)/i', // %@, but also %1$@, %2$@, etc.
'l10njs' => '/\{\{\s*([A-Za-z0-9_]+)\s*\}\}/u', // {{foobar2}} Used in Loop and PDFViewer
'printf' => '/(%(?:[0-9]+\$){0,1}(?:[0-9].){0,1}([sS]))/', // %1$S or %S. %1$0.S and %0.S are valid too
'properties' => '/(?<!%[0-9]|\{\s)\$[A-Za-z0-9\.]+\b/', // $BrandShortName, but not "My%1$SFeeds-%2$S.opml" or "{ $brandShortName }"
];
$repo_patterns = Project::$repos_info[$repo]['variable_patterns'];

Expand Down
2 changes: 1 addition & 1 deletion app/classes/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Project
],
'gecko_strings'=> [
'source_type' => 'mixed',
'variable_patterns' => ['dtd', 'l10njs', 'printf', 'properties'],
'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'],
],
'mozilla_org'=> [
'git_repository' => 'www.mozilla.org',
Expand Down
4 changes: 4 additions & 0 deletions app/classes/Transvision/ShowResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public static function getEditLink($tool, $repo, $key, $text, $locale)
} else {
$resource_path = $fileAndRawString[0];
$search_key = $fileAndRawString[1];
// For FTL files, ignore the attribute added to the string ID
if (strpos($resource_path, '.ftl') !== false) {
$search_key = explode('.', $search_key)[0];
}
switch ($component) {
case 'calendar':
$project_name = 'lightning';
Expand Down
8 changes: 8 additions & 0 deletions tests/units/Transvision/AnalyseStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ public function differencesDP()
[],
[],
],
[
// Missing variable for FTL
['browser:foobar16' => '{ $brandname } installed'],
['browser:foobar16' => 'installato'],
'gecko_strings',
[],
['browser:foobar16'],
],
[
// Mispelled variable
['ios:foobar1' => 'Introductory slide %1$@ of %2$@'],
Expand Down
8 changes: 8 additions & 0 deletions tests/units/Transvision/ShowResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ public function getEditLinkDP()
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/fr/thunderbird/chat/commands.properties?search=dnd'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'gecko_strings',
'browser/browser/preferences/main.ftl:default-content-process-count.label',
'test',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/fr/firefox/browser/browser/preferences/main.ftl?search=default-content-process-count'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'gecko_strings',
Expand Down

0 comments on commit e93e594

Please sign in to comment.