Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue24 - Link allowing opening a bug for a typo #53

Merged
merged 4 commits into from

3 participants

@tx2z
Collaborator

that's all (I think). Tell me about errors, changes, opinions..etc :)

@tx2z
Collaborator

I've seem that there are 11 Scrutinizer comments (I don´t know the tool :S) but seem that my last changes are not related to this comments. Maybe we have to open a new issue for that?

@pascalchevrel

Scrutinizer is a tool for code quality I recently plugged to our repo, we'll see if it is useful (if not, I will disable it) but I don't intend us to follow all advices it gives to the letter :)

I can't look at your patch today, I am working on a Firefox release now, maybe tomorrow

@tx2z
Collaborator

Sure, no problem at all :)

Tell me if you think any change is needed.

About Scrutinizer for me is perfect to know and improve my php skills :D

@filip42
Collaborator

Seems ok for me.
Ph

web/classes/Transvision/Utils.php
@@ -584,4 +584,44 @@ public static function checkAbnormalStringLength($origin, $translated)
}
return $anormal_length;
}
+
+ /*
+ * Check if we have a cache file with the components (languages) and the cache file is not one week old. If not Connect to Bugzilla API and get components list
+ *
+ * @return $components_list
+ */
+ public static function getBugzillaComponents()
+ {
+
+ if (!file_exists('bugzilla_components.txt') || filemtime('bugzilla_components.txt')+ (7 * 24 * 60 * 60) < time() ) {
+ $json_url = "https://bugzilla.mozilla.org/jsonrpc.cgi?method=Product.get&params=[%20{%20%22names%22:%20[%22Mozilla%20Localizations%22]}%20]";
+ $json = file_get_contents($json_url);
+ file_put_contents('bugzilla_components.txt', file_get_contents($json_url));
@pascalchevrel Owner

either use the $json variable or don"t define it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
web/classes/Transvision/Utils.php
((19 lines not shown))
+ $data = json_decode(file_get_contents('bugzilla_components.txt'), TRUE);
+ $components_list = $data['result']['products'][0]['components'];
+
+ return $components_list;
+ }
+
+ /*
+ * Collect the correct language component for bugzilla URL
+ *
+ * @param $actual_lng string
+ * @param $components_array array
+ * @return $component_string
+ */
+ public static function collectLanguageComponent($actual_lng, $components_array)
+ {
+ $component_string = "Other";
@pascalchevrel Owner

nit: single quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
web/classes/Transvision/Utils.php
((21 lines not shown))
+
+ return $components_list;
+ }
+
+ /*
+ * Collect the correct language component for bugzilla URL
+ *
+ * @param $actual_lng string
+ * @param $components_array array
+ * @return $component_string
+ */
+ public static function collectLanguageComponent($actual_lng, $components_array)
+ {
+ $component_string = "Other";
+ foreach ($components_array as $component) {
+ if (strpos($component['name'],$actual_lng) !== false) {
@pascalchevrel Owner

nit: space after coma parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
web/views/results.php
@@ -15,10 +15,15 @@
$results = new ShowResults();
$search_results = $results->getTMXResults(array_keys($locale1_strings), $tmx_source, $tmx_target);
-echo '<h2><span class="searchedTerm">' . $initial_search . '</span> is in ' . $sourceLocale . ' in:</h2>';
+// Get cached bugzilla components (languages list) or connect to Bugzilla API to retreive them
@pascalchevrel Owner

nit: retrieve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
web/classes/Transvision/ShowResults.php
@@ -124,6 +131,13 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
$path_locale1 = Utils::pathFileInRepo($locale1, $search_options['repo'], $key);
$path_locale2 = Utils::pathFileInRepo($locale2, $search_options['repo'], $key);
+ // collect the correct language component
+ $component = rawurlencode($target_component_name);
+ //Bug message
+ $bug_summary = rawurlencode("Typos in ${key}");
+ $bug_message = rawurlencode("The key '${key}' in '${search_options['repo']}' channel is translated as:\n\n'${target_string}'\n\nand must be\n\n");
@pascalchevrel Owner

change 'and must be' by 'and should be'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pascalchevrel

It looks excellebt, probably better than what I would have done myself :) I made a few comments for minor issues, please fix them and I will merge that in. Thanks!

@tx2z
Collaborator

All changes done :)

@pascalchevrel pascalchevrel merged commit f76733a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. @tx2z

    adding conexion to bugzilla API

    tx2z authored
Commits on Apr 4, 2013
  1. @tx2z
Commits on Apr 6, 2013
  1. @tx2z

    issue 24 - final changes

    tx2z authored
  2. @tx2z

    issue 24 - final changes

    tx2z authored
This page is out of date. Refresh to see the latest.
View
51 web/classes/Transvision/ShowResults.php
@@ -63,11 +63,18 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
$direction1 = RTLSupport::getDirection($locale1);
$direction2 = RTLSupport::getDirection($locale2);
+ // Get cached bugzilla components (languages list) or connect to Bugzilla API to retrieve them
+ $components_array = Utils::getBugzillaComponents();
+
+ // collect the correct language component
+ $source_component_name = Utils::collectLanguageComponent($locale1, $components_array);
+ $target_component_name = Utils::collectLanguageComponent($locale2, $components_array);
+
$table = "<table>
<tr>
<th>Entity</th>
- <th>${locale1}</th>
- <th>${locale2}</th>
+ <th>${source_component_name}</th>
+ <th>${target_component_name}</th>
</tr>";
if (!$search_options['whole_word'] && !$search_options['perfect_match']) {
@@ -124,6 +131,13 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
$path_locale1 = Utils::pathFileInRepo($locale1, $search_options['repo'], $key);
$path_locale2 = Utils::pathFileInRepo($locale2, $search_options['repo'], $key);
+ // collect the correct language component
+ $component = rawurlencode($target_component_name);
+ //Bug message
+ $bug_summary = rawurlencode("Typos in ${key}");
+ $bug_message = rawurlencode("The key '${key}' in '${search_options['repo']}' channel is translated as:\n\n'${target_string}'\n\nand should be\n\n");
+
+ // errors
$error_msg = '';
// check for final dot
@@ -162,16 +176,29 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
<td dir='${direction1}'>
<div class='string'>
<a href='http://translate.google.com/#${short_locale1}/${short_locale2}/"
- . urlencode(strip_tags($source_string))
- . "'>${source_string}</a>
- </div>
- <div dir='ltr' class='infos'><a href='${path_locale1}'><em>&lt;source&gt;</em></a></div>
- </td>
-
- <td dir='${direction2}'>
- <div class='string'>${target_string}</div>
- <div dir='ltr' class='infos'><a href='${path_locale2}'><em>&lt;source&gt;</em></a>${error_msg}</div>
- </td>
+ . urlencode(strip_tags($source_string))
+ . "'>${source_string}</a>
+ </div>
+ <div dir='ltr' class='infos'>
+ <a class='source_link' href='${path_locale1}'>
+ &lt;source&gt;
+ </a>
+ </div>
+ </td>
+
+ <td dir='${direction2}'>
+ <div class='string'>${target_string}</div>
+ <div dir='ltr' class='infos'>
+ <a class='source_link' href='${path_locale2}'>
+ &lt;source&gt;
+ </a>
+ &nbsp;
+ <a class='bug_link' target='_blank' href='https://bugzilla.mozilla.org/enter_bug.cgi?format=__default__&component=${component}&product=Mozilla%20Localizations&short_desc=${bug_summary}&comment=${bug_message}'>
+ &lt;report a bug&gt;
+ </a>
+ ${error_msg}
+ </div>
+ </td>
</tr>";
}
View
39 web/classes/Transvision/Utils.php
@@ -584,4 +584,43 @@ public static function checkAbnormalStringLength($origin, $translated)
}
return $anormal_length;
}
+
+ /*
+ * Check if we have a cache file with the components (languages) and the cache file is not one week old. If not Connect to Bugzilla API and get components list
+ *
+ * @return $components_list
+ */
+ public static function getBugzillaComponents()
+ {
+
+ if (!file_exists('bugzilla_components.txt') || filemtime('bugzilla_components.txt')+ (7 * 24 * 60 * 60) < time() ) {
+ $json_url = 'https://bugzilla.mozilla.org/jsonrpc.cgi?method=Product.get&params=[%20{%20%22names%22:%20[%22Mozilla%20Localizations%22]}%20]';
+ file_put_contents('bugzilla_components.txt', file_get_contents($json_url));
+ }
+
+ $data = json_decode(file_get_contents('bugzilla_components.txt'), TRUE);
+ $components_list = $data['result']['products'][0]['components'];
+
+ return $components_list;
+ }
+
+ /*
+ * Collect the correct language component for bugzilla URL
+ *
+ * @param $actual_lng string
+ * @param $components_array array
+ * @return $component_string
+ */
+ public static function collectLanguageComponent($actual_lng, $components_array)
+ {
+ $component_string = 'Other';
+ foreach ($components_array as $component) {
+ if (strpos($component['name'], $actual_lng) !== false) {
+ $component_string = $component['name'];
+ break;
+ }
+ }
+ return $component_string;
+ }
+
}
View
9 web/style/glossary.css
@@ -144,7 +144,7 @@ td {
td a em,
td em.error {
font-style:normal;
- color: orange;
+ color: red;
}
td em.error {
@@ -158,6 +158,13 @@ td div.infos {
}
td div.infos a {
float:left;
+ margin-right: 5px;
+}
+td div.infos a.source_link {
+ color:orange;
+}
+td div.infos a.bug_link {
+ color:#404D6C;
}
footer {
View
29 web/tests/units/Transvision/Utils.php
@@ -287,4 +287,33 @@ public function testCheckAbnormalStringLength2($a, $b, $c)
->isEqualTo($c)
;
}
+
+ public function collectLanguageComponentDataProvider()
+ {
+ $obj = new \Transvision\Utils();
+ $components_list = $obj->getBugzillaComponents();
+ return array(
+ array(
+ 'en-GB',
+ $components_list,
+ 'en-GB / English (United Kingdom)'
+ ),
+ array(
+ 'unknow_LANG',
+ $components_list,
+ 'Other'
+ )
+ );
+ }
+ /**
+ * @dataProvider collectLanguageComponentDataProvider
+ */
+ public function testCollectLanguageComponent($a, $b, $c)
+ {
+ $obj = new \Transvision\Utils();
+ $this
+ ->string($obj->collectLanguageComponent($a,$b))
+ ->isEqualTo($c)
+ ;
+ }
}
View
9 web/views/results.php
@@ -15,10 +15,15 @@
$results = new ShowResults();
$search_results = $results->getTMXResults(array_keys($locale1_strings), $tmx_source, $tmx_target);
-echo '<h2><span class="searchedTerm">' . $initial_search . '</span> is in ' . $sourceLocale . ' in:</h2>';
+// Get cached bugzilla components (languages list) or connect to Bugzilla API to retrieve them
+$components_array = Utils::getBugzillaComponents();
+
+$source_component_name = Utils::collectLanguageComponent($sourceLocale, $components_array);
+echo '<h2><span class="searchedTerm">' . $initial_search . '</span> in ' . $source_component_name . ':</h2>';
echo ShowResults::resultsTable($search_results, $initial_search, $sourceLocale, $locale, $check);
$search_results = Utils::results(array_keys($locale2_strings), $tmx_source, $tmx_target);
-echo '<h2><span class="searchedTerm">' . $initial_search . '</span> is in ' . $locale . ' in:</h2>';
+$target_component_name = Utils::collectLanguageComponent($locale, $components_array);
+echo '<h2><span class="searchedTerm">' . $initial_search . '</span> in ' . $target_component_name . ':</h2>';
echo ShowResults::resultsTable($search_results, $initial_search, $sourceLocale, $locale, $check);
Something went wrong with that request. Please try again.