Skip to content
Permalink
Browse files

Add Project::getLocaleTool method (#828)

* Save info about tools and supported locales in JSON file
* Add Project::getLocaleTool
  • Loading branch information
flodolo committed Nov 24, 2016
1 parent 301cc02 commit c9bb9a4eec53dee031bceabf9814d2bb6aa41de6
@@ -226,4 +226,28 @@ function ($row) {

return array_unique($reference_components);
}

/**
* Return the name of the tool the requested locale is working in.
*
* @return string Name of the tool, empty if not available
*/
public static function getLocaleTool($locale)
{
// Read list of tools and their supported locales from local sources
$file_name = APP_SOURCES . 'tools.json';
if (file_exists($file_name)) {
$json_tools = (new Json($file_name))->fetchContent();
} else {
die("ERROR: run app/scripts/setup.sh or app/scripts/dev-setup.sh to generate sources.");
}

foreach ($json_tools as $tool => $supported_locales) {
if (in_array($locale, $supported_locales)) {
return $tool;
}
}

return '';
}
}
@@ -50,3 +50,13 @@ ksort($json_repositories);
echo "* Saving JSON record of all supported repositories\n";
$file_name = "{$config_folder}/sources/supported_repositories.json";
file_put_contents($file_name, json_encode($json_repositories));

// Create list of locales working in tools like Pootle and Pontoon
$uri = $server_config['l10nwebservice'] . '/?tool=all';
if (! $file_content = file_get_contents($uri)) {
error_log('JSON source is not reachable.');
exit(1);
}
echo "* Saving JSON record of tools and their supported locales\n";
$file_name = "{$config_folder}/sources/tools.json";
file_put_contents($file_name, $file_content);
@@ -0,0 +1,4 @@
{
"locamotion": ["ach", "ar", "tr"],
"pontoon": ["sr", "te"]
}
@@ -155,4 +155,25 @@ public function testGetLocaleInContext($a, $b, $c)
->string($obj->getLocaleInContext($a, $b))
->isEqualTo($c);
}

public function getLocaleToolDP()
{
return [
['ar', 'locamotion'],
['fr', ''],
['sr', 'pontoon'],
['te', 'pontoon'],
];
}

/**
* @dataProvider getLocaleToolDP
*/
public function testGetLocaleTool($a, $b)
{
$obj = new _Project();
$this
->string($obj->getLocaleTool($a))
->isEqualTo($b);
}
}

0 comments on commit c9bb9a4

Please sign in to comment.
You can’t perform that action at this time.