Permalink
Browse files

Fix various issues with the Transliteration API (#742)

  • Loading branch information...
pascalchevrel committed May 2, 2016
1 parent 930e502 commit 85cb8d3fdfc3e3f9e84295b0008d2c48d1d26799
Showing with 9 additions and 12 deletions.
  1. +1 −1 app/classes/Transvision/API.php
  2. +6 −9 app/models/api/transliterate.php
  3. +2 −2 tests/functional/api.php
@@ -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;
}
@@ -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]))];
View
@@ -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"}'],
];

0 comments on commit 85cb8d3

Please sign in to comment.