Skip to content

Commit

Permalink
Locales support for packages display name and description (#47)
Browse files Browse the repository at this point in the history
LGTM ! 

* Locales in pkg name & description JSON result

* Fixed tests

* Scrutinizer didn't like string interpolation

* JsonOutput $langue default to 'enu'
  • Loading branch information
picrap authored and jdel committed Aug 15, 2017
1 parent 7afa775 commit 842060e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/cache/*.png
/packages/*.spk
/vendor/*
/.idea/
8 changes: 6 additions & 2 deletions lib/SSpkS/Handler/SynologyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function handle()
$minor = trim($_REQUEST['minor']);
$build = trim($_REQUEST['build']);
$channel = trim($_REQUEST['package_update_channel']);
// more parameters: language, timezone and unique
if (isset($_REQUEST['language']))
$language = trim($_REQUEST['language']);
else
$language = '';
// more parameters: timezone and unique

if ($arch == '88f6282') {
$arch = '88f6281';
Expand All @@ -66,6 +70,6 @@ public function handle()

$jo = new JsonOutput($this->config);
$jo->setExcludedServices($this->config->excludedSynoServices);
$jo->outputPackages($filteredPkgList);
$jo->outputPackages($filteredPkgList, $language);
}
}
12 changes: 7 additions & 5 deletions lib/SSpkS/Output/JsonOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ private function ifEmpty($obj, $property, $alternative = null)
* Returns JSON-ready array of Package $pkg.
*
* @param \SSpkS\Package\Package $pkg Package
* @param string $language The output language (this has impact on display name and description)
* @return array JSON-ready array of $pkg.
*/
private function packageToJson($pkg)
private function packageToJson($pkg, $language)
{
/*
package
Expand Down Expand Up @@ -98,8 +99,8 @@ private function packageToJson($pkg)
$packageJSON = array(
'package' => $pkg->package,
'version' => $pkg->version,
'dname' => $pkg->displayname,
'desc' => $pkg->description,
'dname' => $this->ifEmpty($pkg, 'displayname_' . $language, $pkg->displayname),
'desc' => $this->ifEmpty($pkg, 'description_' . $language, $pkg->description),
'price' => 0,
'download_count' => 0, // Will only display values over 1000, do not display it by default
'recent_download_count' => 0,
Expand Down Expand Up @@ -137,14 +138,15 @@ private function packageToJson($pkg)
* Outputs given packages as JSON.
*
* @param \SSpkS\Package\Package[] $pkgList List of packages to output.
* @param string $language The output language (this has impact on display name and description)
*/
public function outputPackages($pkgList)
public function outputPackages($pkgList, $language = 'enu')
{
$jsonOutput = array(
'packages' => array(),
);
foreach ($pkgList as $pkg) {
$pkgJson = $this->packageToJson($pkg);
$pkgJson = $this->packageToJson($pkg, $language);
$jsonOutput['packages'][] = $pkgJson;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/JsonOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testExcludedServices()
$jo = new JsonOutput($this->config);
$jo->setExcludedServices(array('test3'));

$jo->outputPackages($pl);
$jo->outputPackages($pl, null);

$this->expectOutputRegex('/"deppkgs":"test1 test2 test4"/');
}
Expand All @@ -61,7 +61,7 @@ public function testJsonConversion()

$jo = new JsonOutput($this->config);

$jo->outputPackages($pl);
$jo->outputPackages($pl, null);

$pkgMd5 = md5_file($this->tempPkg);
$pkgSize = filesize($this->tempPkg);
Expand Down

0 comments on commit 842060e

Please sign in to comment.