Use multiple languages with "formula"

I want to use characters in multiple languages in "formula".
For example, I want to use Japanese, Chinese, and Korean, but if I use them at the same time, an error occurs.
If "locale" is specified as "Japanese", Japanese will not cause an error even if it is "formula", but Chinese and Korean will cause an error.

If "locale" is specified as "Chinese", Japanese and Chinese will not cause an error even if "formula", but Korean will cause an error.

How can I use characters from multiple languages in "formula" at the same time?

The code used is shown below.

Sys.setlocale(locale="Japanese")
as.formula("y ~ 测试") #Chinese
as.formula("y ~ テスト") #Japanese
as.formula('y ~ 테스트') #Korean

Sys.setlocale(locale="Chinese")
as.formula("y ~ 测试") #Chinese
as.formula("y ~ テスト") #Japanese
as.formula('y ~ 테스트') #Korean

The execution result is shown below.

> Sys.setlocale(locale="Japanese")
[1] "LC_COLLATE=Japanese_Japan.932;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=Japanese_Japan.932;LC_NUMERIC=C;LC_TIME=Japanese_Japan.932"
> as.formula("y ~ 测试") #Chinese
Error in str2lang(x) : <text>:1:5: unexpected '<'
1: y ~ <
        ^
> as.formula("y ~ テスト") #Japanese
y ~ テスト
> as.formula('y ~ 테스트') #Korean
Error in str2lang(x) : <text>:1:5: unexpected '<'
1: y ~ <
        ^
> 
> Sys.setlocale(locale="Chinese")
[1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese (Simplified)_China.936;LC_MONETARY=Chinese (Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936"
> as.formula("y ~ 测试") #Chinese
y ~ 测试
> as.formula("y ~ テスト") #Japanese
y ~ テスト
> as.formula('y ~ 테스트') #Korean
Error in str2lang(x) : <text>:1:5: unexpected '<'
1: y ~ <
        ^

You can use a different locale for each command by wrapin them into withr::with_envvar() e. g.

withr::with_envvar(c("LANG" = "Japanese"), code = {as.formula("y ~ テスト")})

Thank you!
I am very grateful for your answer.The method you have proposed will solve some of the problems.

Is it possible to use characters from multiple languages in "formula" at exactly the same time?
In other words, is it possible to use characters from multiple languages at the same time in one "formula" as in the example below?

as.formula("y ~ 测试+テスト+테스트") #Chinese+Japanese+Korean

I don't know enough about localizations and specially about Asian languages, but you would need a language configuration with a broad enough character set that do not superimpose (same unicode for different character representations) and I don't know if that is even possible with those three languages.

It wouldn't be simpler to just translate all of them into one language? Content addressed to people that can read all those three languages seems to much of a nich content to me.

Thank you for your reply.

Unfortunately, it seems difficult to use "formula" in multiple Asian languages at the same time.

If I use "formula" on my own, I think translation is the most appropriate option.
But in the end, I want to create a shiny appliction for multiple Asian languages.
So I would like to use withr :: with_envvar () on the shiny application to create a language selection option.

Thank you for all the advice. I am very grateful.

There are better ways of Internazionalizing your application, take a look at this article

This is fantastic. Thank you for introducing me.
I've created shiny applications for multiple languages, and it seems easier than ever to create them.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.