Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Cyrillic characters #1337

Closed
Mio11 opened this issue Jun 9, 2015 · 2 comments
Closed

Cyrillic characters #1337

Mio11 opened this issue Jun 9, 2015 · 2 comments

Comments

@Mio11
Copy link

Mio11 commented Jun 9, 2015

When I make a call to wp-json/posts on a blog with cyrillic characters (russian) I will get this respose:
Would it be possible that the cyrillic characters would show up directly in the response? The file size would be less, for each chracter 3 signs less?

[{"ID":1,"title":"\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0438\u0440!","status":"publish","type":"post","author":{"ID":1,"username":"wlt","name":"wlt","first_name":"","last_name":"","nickname":"wlt","slug":"wlt","URL":"","avatar":"http:\/\/2.gravatar.com\/avatar\/83f79ef3eb15204e048c82c4232a3ffd?s=96","description":"","registered":"2015-04-30T10:28:25+00:00","meta":{"links":{"self":"http:\/\/cerkovnsk.chu\/new\/wp-json\/users\/1","archives":"http:\/\/cerkovnsk.chu\/new\/wp-json\/users\/1\/posts"}}},"content":"<p>\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 WordPress. \u042d\u0442\u043e \u0432\u0430\u0448\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c. \u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0435\u0451, \u0437\u0430\u0442\u0435\u043c \u043f\u0438\u0448\u0438\u0442\u0435!<\/p>\n","parent":null,"link":"http:\/\/cerkovnsk.chu\/new\/2015\/04\/30\/%d0%bf%d1%80%d0%b8%d0%b2%d0%b5%d1%82-%d0%bc%d0%b8%d1%80\/","date":"2015-04-30T13:28:26","modified":"2015-04-30T13:28:26","format":"standard","slug":"%d0%bf%d1%80%d0%b8%d0%b2%d0%b5%d1%82-%d0%bc%d0%b8%d1%80","guid":"http:\/\/cerkovnsk.chu\/new\/?p=1","excerpt":"<p class=\"post-excerpt\">\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 WordPress. \u042d\u0442\u043e \u0432\u0430\u0448\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c. \u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0435\u0451, \u0437\u0430\u0442\u0435\u043c \u043f\u0438\u0448\u0438\u0442\u0435!<\/p>\n","menu_order":0,"comment_status":"open","ping_status":"open","sticky":false,"date_tz":"Etc\/GMT+3","date_gmt":"2015-04-30T10:28:26","modified_tz":"Etc\/GMT+3","modified_gmt":"2015-04-30T10:28:26","meta":{"links":{"self":"http:\/\/cerkovnsk.chu\/new\/wp-json\/posts\/1","author":"http:\/\/cerkovnsk.chu\/new\/wp-json\/users\/1","collection":"http:\/\/cerkovnsk.chu\/new\/wp-json\/posts","replies":"http:\/\/cerkovnsk.chu\/new\/wp-json\/posts\/1\/comments","version-history":"http:\/\/cerkovnsk.chu\/new\/wp-json\/posts\/1\/revisions"}},"featured_image":null,"terms":{"category":[{"ID":1,"name":"\u0411\u0435\u0437 \u0440\u0443\u0431\u0440\u0438\u043a\u0438","slug":"%d0%b1%d0%b5%d0%b7-%d1%80%d1%83%d0%b1%d1%80%d0%b8%d0%ba%d0%b8","description":"","taxonomy":"category","parent":null,"count":1,"link":"http:\/\/cerkovnsk.chu\/new\/category\/%d0%b1%d0%b5%d0%b7-%d1%80%d1%83%d0%b1%d1%80%d0%b8%d0%ba%d0%b8\/","meta":{"links":{"collection":"http:\/\/cerkovnsk.chu\/new\/wp-json\/taxonomies\/category\/terms","self":"http:\/\/cerkovnsk.chu\/new\/wp-json\/taxonomies\/category\/terms\/1"}}}]}}]
@rmccue
Copy link
Member

rmccue commented Jun 12, 2015

This is only possible in PHP since PHP 5.4 (JSON_UNESCAPED_UNICODE), and we need to support PHP 5.2, so we can't do this right now.

This might be something that could be shimmed in to WP's wp_json_encode compatibility layer, so I'd suggest filing a ticket over on core WP Trac.

Thanks for filing the bug!

@rmccue rmccue closed this as completed Jun 12, 2015
@stioann
Copy link

stioann commented Apr 29, 2016

Update.

What is about Cyrillic characters in rest api answer? Still get -- "name":"\u0410\u0433\u0435\u043d\u0442\u044b","slug":"agents". That ugly UTF encode. Is there any hack way to resolve this problem?

P.S. What about this kind of solution: preg_replace_callback('/\\\u([01-9a-fA-F]{4})/', 'prepareUTF8', json_encode($array)) ?

P.P.S. Or maybe there is some way to put this code somewhere inside the plugin files

function json_encode_($string) {

  $arrayUtf = array('\u0410', '\u0430', '\u0411', '\u0431', '\u0412', '\u0432', '\u0413', '\u0433', '\u0414', '\u0434', '\u0415', '\u0435', '\u0401', '\u0451', '\u0416', '\u0436', '\u0417', '\u0437', '\u0418', '\u0438', '\u0419', '\u0439', '\u041a', '\u043a', '\u041b', '\u043b', '\u041c', '\u043c', '\u041d', '\u043d', '\u041e', '\u043e', '\u041f', '\u043f', '\u0420', '\u0440', '\u0421', '\u0441', '\u0422', '\u0442', '\u0423', '\u0443', '\u0424', '\u0444', '\u0425', '\u0445', '\u0426', '\u0446', '\u0427', '\u0447', '\u0428', '\u0448', '\u0429', '\u0449', '\u042a', '\u044a', '\u042b', '\u044b', '\u042c', '\u044c', '\u042d', '\u044d', '\u042e', '\u044e', '\u042f', '\u044f');

  $arrayCyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш',  'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я');

  return str_replace($arrayUtf,$arrayCyr,json_encode($string));
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants