Skip to content

Commit

Permalink
Update edit links (remove Pootle, support FxiOS and mozilla.org) (#878)
Browse files Browse the repository at this point in the history
* (fixes #881) Update edit links
* Add support for mozilla.org and Firefox for iOS (text search)
* Remove support for Pootle
* Hide link if translation is missing
  • Loading branch information
flodolo authored Sep 5, 2017
1 parent 1d93e96 commit 044784e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 75 deletions.
69 changes: 43 additions & 26 deletions app/classes/Transvision/ShowResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,44 +240,61 @@ public static function formatEntity($entity, $highlight = false)
/**
* Return link to edit a message on external tool used by requested locale
*
* @param string $tool Name of the external tool (locamotion, pontoon)
* @param string $repo Repository
* @param string $key Key of the current string
* @param string $text Text of the current strings
* @param string $locale Current locale
*
* @return string HTML link to edit the string inside the tool used by this locale
*/
public static function getEditLink($tool, $key, $locale)
public static function getEditLink($repo, $key, $text, $locale)
{
$component = explode('/', $key)[0];
$fileAndRawString = explode(':', $key);

$excluded_repos = ['beta', 'release'];
$free_text_repos = ['mozilla_org', 'firefox_ios'];

// Ignore files in /extensions
if ($component == 'extensions') {
return '';
}

if ($tool == 'locamotion') {
switch ($component) {
case 'calendar':
$project_name = 'lightning';
break;
case 'chat':
case 'editor':
case 'mail':
$project_name = 'thunderbird';
break;
case 'mobile':
$project_name = 'mobile';
break;
case 'suite':
$project_name = 'seamonkey';
break;
default:
$project_name = 'firefox';
// Ignore Beta and Release
if (in_array($repo, $excluded_repos)) {
return '';
}

/*
If search is performed on the string, limit search at 250 characters
and URLencode the text.
*/
if (in_array($repo, $free_text_repos)) {
# Disable link if the translation is missing
if ($text == '@@missing@@' || Strings::startsWith($text, '<em class="error">Warning:')) {
return '';
}
$limit = 250;
if (mb_strlen($text) > $limit) {
$text = mb_strcut($text, 0, $limit);
}
$edit_link = "https://mozilla.locamotion.org/{$locale}/{$project_name}/translate/{$fileAndRawString[0]}.po#search={$fileAndRawString[1]}&sfields=locations";
$tool_name = 'Pootle';
$text = urlencode($text);
}

// We only support Pontoon
$tool_name = 'Pontoon';

if ($repo == 'mozilla_org') {
$project_name = 'mozillaorg';
$resource_path = ltrim($fileAndRawString[0], 'mozilla_org/');
$search_key = $text;
} elseif ($repo == 'firefox_ios') {
$project_name = 'firefox-for-ios';
$resource_path = 'firefox-ios.xliff';
$search_key = $text;
} else {
$resource_path = $fileAndRawString[0];
$search_key = $fileAndRawString[1];
switch ($component) {
case 'calendar':
$project_name = 'lightning';
Expand All @@ -296,10 +313,10 @@ public static function getEditLink($tool, $key, $locale)
default:
$project_name = 'firefox';
}
$edit_link = "https://pontoon.mozilla.org/{$locale}/{$project_name}/{$fileAndRawString[0]}?search={$fileAndRawString[1]}";
$tool_name = 'Pontoon';
}

$edit_link = "https://pontoon.mozilla.org/{$locale}/{$project_name}/{$resource_path}?search={$search_key}";

return "&nbsp;<a class='edit_link' target='_blank' href='{$edit_link}'>&lt;edit in {$tool_name}&gt;</a>";
}

Expand Down Expand Up @@ -396,8 +413,8 @@ public static function resultsTable($search_object, $search_results, $page)
*/
$transliterate = $locale2 == 'sr' && ! $extra_locale && $target_string && $target_string != '@@missing@@';

$edit_link = ($current_repo == 'central' && $toolUsedByTargetLocale != '')
? self::getEditLink($toolUsedByTargetLocale, $key, $locale2)
$edit_link = $toolUsedByTargetLocale != ''
? self::getEditLink($current_repo, $key, $target_string, $locale2)
: '';

if ($transliterate) {
Expand Down
4 changes: 2 additions & 2 deletions app/views/results_entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
// Get the tool used to edit strings for the target locale
$toolUsedByTargetLocale = Project::getLocaleTool($locale);

$edit_link = ($current_repo == 'central' && $toolUsedByTargetLocale != '')
? ShowResults::getEditLink($toolUsedByTargetLocale, $entity, $locale)
$edit_link = $toolUsedByTargetLocale != ''
? ShowResults::getEditLink($current_repo, $entity, $target_string, $locale)
: '';

$table .= "
Expand Down
1 change: 0 additions & 1 deletion tests/testfiles/config/tools.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"locamotion": ["ach", "ar", "tr"],
"pontoon": ["sr", "te"]
}
1 change: 0 additions & 1 deletion tests/units/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public function testGetLocaleInContext($a, $b, $c)
public function getLocaleToolDP()
{
return [
['ar', 'locamotion'],
['fr', ''],
['sr', 'pontoon'],
['te', 'pontoon'],
Expand Down
99 changes: 54 additions & 45 deletions tests/units/Transvision/ShowResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,113 +349,122 @@ public function getEditLinkDP()
return [
// Pontoon links
[
'pontoon',
'central',
'browser/chrome/browser/browser.properties:webextPerms.hostDescription.allUrls',
'test',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/fr/firefox/browser/chrome/browser/browser.properties?search=webextPerms.hostDescription.allUrls'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'central',
'calendar/chrome/calendar/calendar.dtd:calendar.calendar.label',
'test',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/fr/lightning/calendar/chrome/calendar/calendar.dtd?search=calendar.calendar.label'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'central',
'chat/commands.properties:dnd',
'test',
'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',
'central',
'editor/ui/chrome/composer/editingOverlay.dtd:fileRecentMenu.label',
'test',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/fr/thunderbird/editor/ui/chrome/composer/editingOverlay.dtd?search=fileRecentMenu.label'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'central',
'extensions/irc/chrome/about.dtd:chatzilla.label',
'es',
'test',
'',
'',
],
[
'pontoon',
'central',
'mail/chrome/messenger/addressbook/abContactsPanel.dtd:ccButton.label',
'test',
'de',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/de/thunderbird/mail/chrome/messenger/addressbook/abContactsPanel.dtd?search=ccButton.label'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'central',
'mobile/android/base/android_strings.dtd:activity_stream_highlights',
'test',
'bg',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/bg/firefox-for-android/mobile/android/base/android_strings.dtd?search=activity_stream_highlights'>&lt;edit in Pontoon&gt;</a>",
],
[
'pontoon',
'central',
'suite/chrome/browser/taskbar.properties:taskbar.tasks.composeMessage.description',
'test',
'it',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/it/seamonkey/suite/chrome/browser/taskbar.properties?search=taskbar.tasks.composeMessage.description'>&lt;edit in Pontoon&gt;</a>",
],
// Locamotion links
[
'locamotion',
'browser/chrome/browser/browser.properties:webextPerms.hostDescription.allUrls',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/fr/firefox/translate/browser/chrome/browser/browser.properties.po#search=webextPerms.hostDescription.allUrls&sfields=locations'>&lt;edit in Pootle&gt;</a>",
'beta',
'suite/chrome/browser/taskbar.properties:taskbar.tasks.composeMessage.description',
'test',
'it',
'',
],
[
'locamotion',
'chat/commands.properties:dnd',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/fr/thunderbird/translate/chat/commands.properties.po#search=dnd&sfields=locations'>&lt;edit in Pootle&gt;</a>",
'release',
'suite/chrome/browser/taskbar.properties:taskbar.tasks.composeMessage.description',
'test',
'it',
'',
],
[
'locamotion',
'calendar/chrome/calendar/calendar.dtd:calendar.calendar.label',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/fr/lightning/translate/calendar/chrome/calendar/calendar.dtd.po#search=calendar.calendar.label&sfields=locations'>&lt;edit in Pootle&gt;</a>",
'mozilla_org',
'mozilla_org/firefox/android/index.lang:4e0bc9d4',
'test',
'it',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/it/mozillaorg/firefox/android/index.lang?search=test'>&lt;edit in Pontoon&gt;</a>",
],
[
'locamotion',
'editor/ui/chrome/composer/editingOverlay.dtd:fileRecentMenu.label',
'fr',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/fr/thunderbird/translate/editor/ui/chrome/composer/editingOverlay.dtd.po#search=fileRecentMenu.label&sfields=locations'>&lt;edit in Pootle&gt;</a>",
'firefox_ios',
'mozilla_org/firefox/android/index.lang:4e0bc9d4',
'test',
'it',
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/it/firefox-for-ios/firefox-ios.xliff?search=test'>&lt;edit in Pontoon&gt;</a>",
],
[
'locamotion',
'extensions/irc/chrome/about.dtd:chatzilla.label',
'es',
'firefox_ios',
'mozilla_org/firefox/android/index.lang:4e0bc9d4',
'@@missing@@',
'it',
'',
],
[
'locamotion',
'mail/chrome/messenger/addressbook/abContactsPanel.dtd:ccButton.label',
'de',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/de/thunderbird/translate/mail/chrome/messenger/addressbook/abContactsPanel.dtd.po#search=ccButton.label&sfields=locations'>&lt;edit in Pootle&gt;</a>",
],
[
'locamotion',
'mobile/android/base/android_strings.dtd:activity_stream_highlights',
'bg',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/bg/mobile/translate/mobile/android/base/android_strings.dtd.po#search=activity_stream_highlights&sfields=locations'>&lt;edit in Pootle&gt;</a>",
'firefox_ios',
'mozilla_org/firefox/android/index.lang:4e0bc9d4',
'<em class="error">Warning: Missing string</em>',
'it',
'',
],
// Test URLencode
[
'locamotion',
'suite/chrome/browser/taskbar.properties:taskbar.tasks.composeMessage.description',
'firefox_ios',
'mozilla_org/firefox/android/index.lang:4e0bc9d4',
'%(test)',
'it',
"&nbsp;<a class='edit_link' target='_blank' href='https://mozilla.locamotion.org/it/seamonkey/translate/suite/chrome/browser/taskbar.properties.po#search=taskbar.tasks.composeMessage.description&sfields=locations'>&lt;edit in Pootle&gt;</a>",
"&nbsp;<a class='edit_link' target='_blank' href='https://pontoon.mozilla.org/it/firefox-for-ios/firefox-ios.xliff?search=%25%28test%29'>&lt;edit in Pontoon&gt;</a>",
],
];
}

/**
* @dataProvider getEditLinkDP
*/
public function testGetEditLink($a, $b, $c, $d)
public function testGetEditLink($a, $b, $c, $d, $e)
{
$obj = new _ShowResults();
$this
->string($obj->getEditLink($a, $b, $c))
->isEqualTo($d);
->string($obj->getEditLink($a, $b, $c, $d))
->isEqualTo($e);
}
}

0 comments on commit 044784e

Please sign in to comment.