Is there any way to set the character set so that the plumber can support Chinese characters?
谢谢!
@shangfr Do you have a small example plumber file? This way I can reproduce / fix the error you're seeing.
Thank you in advance!
@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")
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---中文消息是: 你好"}
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:
UTF-8
by default as it's in shiny.@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))
}
@shangfr It should have been fixed via the PR #312 and #314. You can try after the two PRs being merged. 😄
Thank you. I appreciate your help. Thanks. @shrektan