Skip to content

attempt to add test of Chinese error message#4524

Merged
mattdowle merged 17 commits intomasterfrom
chinese_test
Jun 5, 2020
Merged

attempt to add test of Chinese error message#4524
mattdowle merged 17 commits intomasterfrom
chinese_test

Conversation

@mattdowle
Copy link
Copy Markdown
Member

For #4402, follow up to #4523

@mattdowle mattdowle added this to the 1.12.9 milestone Jun 4, 2020
Comment thread inst/tests/tests.Rraw Outdated
@mattdowle
Copy link
Copy Markdown
Member Author

@shrektan Thanks for testing master and I understand it doesn't work. Just so we can get a test going, do you know how to get R on Windows to produce Chinese? I've tried all kinds of variations of the LANG and LANGUAGE in this PR and none of them seem to generate any Chinese at all. Is it the wrong string, the wrong environment variable? Maybe R on Windows must be set to a different language on startup and can't be done at runtime like this?

@shrektan
Copy link
Copy Markdown
Member

shrektan commented Jun 4, 2020

Thanks for all your efforts. Frankly speaking, I don't really know and I'm not sure if it's possible without the Windows' language being set up to Chinese.

But I will try to find a way (hopefully) this day later when I get back home, where I can set up a Windows machine with English locale to mimic what's happening in the CI.

@mattdowle
Copy link
Copy Markdown
Member Author

mattdowle commented Jun 4, 2020

https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Localization-of-messages contains (bold mine) :

It is usually possible to change the language once R is running via (not Windows) Sys.setlocale("LC_MESSAGES", "new_locale"), or by setting an environment variable such as LANGUAGE

and in https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Testing-a-Unix_002dalike-Installation at the end is :

Note that the results may depend on the language set for times and messages: for maximal similarity to reference results you may want to try setting (before starting the R session)
LANGUAGE=en
and use a UTF-8 or Latin-1 locale.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 4, 2020

Codecov Report

Merging #4524 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4524   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          72       73    +1     
  Lines       13971    14027   +56     
=======================================
+ Hits        13916    13972   +56     
  Misses         55       55           
Impacted Files Coverage Δ
src/init.c 100.00% <ø> (ø)
src/snprintf.c 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2063ed7...636843f. Read the comment docs.

@mattdowle
Copy link
Copy Markdown
Member Author

Still no Chinese present in main.Rout. Sigh.
This artile mentioned chs and simplified-chinese but R, on AppVeyor at least, still remains English.
https://withr.github.io/configure-character-encoding-for-r-under-linux-and-windows/

@shrektan
Copy link
Copy Markdown
Member

shrektan commented Jun 4, 2020

@mattdowle @MichaelChirico The below code works on my PC (Windows 10, English Language, with Chinese Language installed).

x <- list(
  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"
)
for (i in seq_along(x)) {
  Sys.setlocale(names(x)[[i]], x[[i]])
}
Sys.setenv('LANGUAGE' = 'zh_CN')

After executing the above code, library(data.table) will start to display the Chinese message.

image

@shrektan
Copy link
Copy Markdown
Member

shrektan commented Jun 4, 2020

Looks this approach works. The "main.Rout.fail" prints the expected Chinese message before it gets segfault.

image

@mattdowle
Copy link
Copy Markdown
Member Author

Oh wow! You did it! Not only Chinese but it reproduces the crash too ... awesome!

For future reference, this is what I see in AppVeyor web display; i.e., not Chinese but definitely not ascii, so the translation is kicking in and this is just a web-display issue of the output in AppVeyor that we can ignore for this purpose.
image

@mattdowle
Copy link
Copy Markdown
Member Author

Will merge shortly so that @shrektan can test master to see if it works now please. If it does work now, we can go through and tidy/review in a follow up. If it still doesn't work then we can throw this wrapper away. Although it's a bit hairy, at least it's contained in one file and not too long. And being plain C99, we can be confident it should work on all Windows machines, old and new, MinGW, MSVC, etc.

@MichaelChirico
Copy link
Copy Markdown
Member

Regardless of the outcome, thanks for the herculean effort to support this! Awesome stuff.

@mattdowle mattdowle merged commit 3436568 into master Jun 5, 2020
@mattdowle
Copy link
Copy Markdown
Member Author

@MichaelChirico yes very good point. %1$ might match to the 2nd character of %%1$ which wouldn't be correct. Ok will fix that and add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

translation issues/PRs related to message translation projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants