Skip to content

Commit

Permalink
Fix various issues with the Transliteration API (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed May 2, 2016
1 parent 930e502 commit 85cb8d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/classes/Transvision/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private function isValidServiceCall($service)

break;
case 'transliterate':
// ex: /api/v1/transliterate/serbian/Завиритe
// ex: /api/v1/transliterate/sr-Cyrl/Завиритe
if (! $this->verifyEnoughParameters(4)) {
return false;
}
Expand Down
15 changes: 6 additions & 9 deletions app/models/api/transliterate.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<?php
namespace Transvision;

// Check that the class exists before trying to use it
// Requires php-intl
// Check that the class exists before using it. Requires the php-intl extension
if (! class_exists('Transliterator')) {
$request->error = 'Class Transliterator not available';
$json = $request->invalidAPICall(501);

return;
return $request->invalidAPICall(501);
}

switch ($request->parameters[2]) {
case 'sr-Cyril':
case 'sr-Cyrl':
$transliterated_locale = 'Serbian-Latin/BGN';
break;

default:
$request->error = 'Wrong language';
$request->error = 'Wrong locale code';

return $request->invalidAPICall(501);
return $request->invalidAPICall();
}

$transliterator = \Transliterator::create($transliterated_locale);
$transliterated_string = $transliterator->transliterate($request->parameters[3]);

return $json = [$transliterator->transliterate(Utils::secureText($request->parameters[3]))];
return [$transliterator->transliterate(Utils::secureText($request->parameters[3]))];
4 changes: 2 additions & 2 deletions tests/functional/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
['v1/suggestions/central/en-US/fr/bookmark/?max_results=2', 200, '["Bookmark","Bookmarks"]'],
['v1/tm/central/en-US/fr/Bookmark/?max_results=3&min_quality=80', 200, '[{"source":"Bookmark","target":"Marquer cette page","quality":100},{"source":"Bookmark","target":"Marque-page","quality":100},{"source":"Bookmarks","target":"Marque-pages","quality":88.89}]'],
['v1/tm/global/fr/en-US/Ouvrir/', 200, '[{"source":"Ouvrir dans le Finder","target":"Find in Finder","quality":28.57},{"source":"D\u00e9couvrez comment ouvrir une fen\u00eatre de navigation priv\u00e9e","target":"Learn how to open a private window","quality":8.77}]'],
['v1/transliterate/foo/bar/', 501, '{"error":"Wrong language"}'],
['v1/transliterate/sr-Cyril/%0A%D1%81%D1%80%D0%BF%D1%81%D0%BA%D0%B0/', 200, '["srpska"]'],
['v1/transliterate/foo/bar/', 400, '{"error":"Wrong locale code"}'],
['v1/transliterate/sr-Cyrl/%D1%81%D1%80%D0%BF%D1%81%D0%BA%D0%B0/', 200, '["srpska"]'],
['v1/versions/', 200, '{"v1":"stable"}'],
];

Expand Down

0 comments on commit 85cb8d3

Please sign in to comment.