Skip to content

Commit 85cb8d3

Browse files
committed
Fix various issues with the Transliteration API (#742)
1 parent 930e502 commit 85cb8d3

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

app/classes/Transvision/API.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private function isValidServiceCall($service)
294294

295295
break;
296296
case 'transliterate':
297-
// ex: /api/v1/transliterate/serbian/Завиритe
297+
// ex: /api/v1/transliterate/sr-Cyrl/Завиритe
298298
if (! $this->verifyEnoughParameters(4)) {
299299
return false;
300300
}

app/models/api/transliterate.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
<?php
22
namespace Transvision;
33

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

10-
return;
8+
return $request->invalidAPICall(501);
119
}
1210

1311
switch ($request->parameters[2]) {
14-
case 'sr-Cyril':
12+
case 'sr-Cyrl':
1513
$transliterated_locale = 'Serbian-Latin/BGN';
1614
break;
1715

1816
default:
19-
$request->error = 'Wrong language';
17+
$request->error = 'Wrong locale code';
2018

21-
return $request->invalidAPICall(501);
19+
return $request->invalidAPICall();
2220
}
2321

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

27-
return $json = [$transliterator->transliterate(Utils::secureText($request->parameters[3]))];
24+
return [$transliterator->transliterate(Utils::secureText($request->parameters[3]))];

tests/functional/api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
['v1/suggestions/central/en-US/fr/bookmark/?max_results=2', 200, '["Bookmark","Bookmarks"]'],
2222
['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}]'],
2323
['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}]'],
24-
['v1/transliterate/foo/bar/', 501, '{"error":"Wrong language"}'],
25-
['v1/transliterate/sr-Cyril/%0A%D1%81%D1%80%D0%BF%D1%81%D0%BA%D0%B0/', 200, '["srpska"]'],
24+
['v1/transliterate/foo/bar/', 400, '{"error":"Wrong locale code"}'],
25+
['v1/transliterate/sr-Cyrl/%D1%81%D1%80%D0%BF%D1%81%D0%BA%D0%B0/', 200, '["srpska"]'],
2626
['v1/versions/', 200, '{"v1":"stable"}'],
2727
];
2828

0 commit comments

Comments
 (0)