From e93e594de413afae35bad9ca431a0e816cf5c599 Mon Sep 17 00:00:00 2001 From: Francesco Lodolo Date: Wed, 3 Jan 2018 20:11:42 +0100 Subject: [PATCH] Improve FTL support (#927) * Fix edit_link for FTL strings * Add variable checks for FTL --- app/classes/Transvision/AnalyseStrings.php | 7 ++++--- app/classes/Transvision/Project.php | 2 +- app/classes/Transvision/ShowResults.php | 4 ++++ tests/units/Transvision/AnalyseStrings.php | 8 ++++++++ tests/units/Transvision/ShowResults.php | 8 ++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/classes/Transvision/AnalyseStrings.php b/app/classes/Transvision/AnalyseStrings.php index 9b9e37fd..48ec44f7 100644 --- a/app/classes/Transvision/AnalyseStrings.php +++ b/app/classes/Transvision/AnalyseStrings.php @@ -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' => '/(? '/\{\{\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' => '/(? [ 'source_type' => 'mixed', - 'variable_patterns' => ['dtd', 'l10njs', 'printf', 'properties'], + 'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'], ], 'mozilla_org'=> [ 'git_repository' => 'www.mozilla.org', diff --git a/app/classes/Transvision/ShowResults.php b/app/classes/Transvision/ShowResults.php index 94f3a5f7..813bb832 100644 --- a/app/classes/Transvision/ShowResults.php +++ b/app/classes/Transvision/ShowResults.php @@ -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'; diff --git a/tests/units/Transvision/AnalyseStrings.php b/tests/units/Transvision/AnalyseStrings.php index 4a86159e..d941056f 100644 --- a/tests/units/Transvision/AnalyseStrings.php +++ b/tests/units/Transvision/AnalyseStrings.php @@ -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$@'], diff --git a/tests/units/Transvision/ShowResults.php b/tests/units/Transvision/ShowResults.php index df893566..9de620cb 100644 --- a/tests/units/Transvision/ShowResults.php +++ b/tests/units/Transvision/ShowResults.php @@ -372,6 +372,14 @@ public function getEditLinkDP() 'fr', " <edit in Pontoon>", ], + [ + 'pontoon', + 'gecko_strings', + 'browser/browser/preferences/main.ftl:default-content-process-count.label', + 'test', + 'fr', + " <edit in Pontoon>", + ], [ 'pontoon', 'gecko_strings',