Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese characters are not supported #296

Closed
shangfr opened this issue Aug 17, 2018 · 5 comments
Closed

Chinese characters are not supported #296

shangfr opened this issue Aug 17, 2018 · 5 comments
Labels
effort: low < 1 day of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code

Comments

@shangfr
Copy link

shangfr commented Aug 17, 2018

Is there any way to set the character set so that the plumber can support Chinese characters?
谢谢!

@schloerke schloerke added type: bug Maintainers have validated that it is a real bug in the project code effort: low < 1 day of work priority: medium Could be fixed before next release labels Sep 12, 2018
@schloerke
Copy link
Collaborator

@shangfr Do you have a small example plumber file? This way I can reproduce / fix the error you're seeing.

Thank you in advance!

@shangfr
Copy link
Author

shangfr commented Sep 26, 2018

@schloerke My plumber file was written in utf8,but the plumb function default encoding is ANSI , it should be better to specify encoding. Such as : plumb("plumber.R", encoding = "UTF-8")

plumber.R

#' Echo the parameter that was sent in
#' @param msg The message to echo back.
#' @param msgCN The Chinese message to echo back.
#' @get /echo
function(msg="",msgCN=""){
list(msg = paste0("The message is: ", msg, "---","中文消息是: ",msgCN))
}

$ curl "http://localhost:8000/echo?msg=hello&msgCN=你好"
Now output : {"The message is: hello---涓枃娑堟伅鏄? 浣犲ソ"}
Correct output : {"The message is: hello---中文消息是: 你好"}

@shangfr shangfr closed this as completed Sep 26, 2018
@shangfr shangfr reopened this Sep 26, 2018
@shrektan
Copy link
Contributor

shrektan commented Oct 5, 2018

Note, this is only reproducible on Windows because the default encoding is not UTF-8. (Moreover, it may require a windows machine using Simplified Chinese. Replacing the Chinese by Latin-1 and it may be reproducible on any Windows machine.)

There're actually two issues here:

  1. The source file should be parsed as UTF-8 by default as it's in shiny.
  2. The function parameter should be marked as UTF-8 for characters.

A hotfix

@shangfr you can use this as a hotfix for now.

#' @get /echo2
function(msg="",msgCN=""){
  Encoding(msgCN) <- "UTF-8" # by marking it explicitly it will work as an adhoc solution
  list(msg = paste0("The message is: ", msg, "---","中文消息是: ",msgCN))
}

@shrektan
Copy link
Contributor

shrektan commented Oct 5, 2018

@shangfr It should have been fixed via the PR #312 and #314. You can try after the two PRs being merged. 😄

@shangfr
Copy link
Author

shangfr commented Oct 10, 2018

Thank you. I appreciate your help. Thanks. @shrektan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: low < 1 day of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code
Projects
None yet
Development

No branches or pull requests

3 participants