Using weekdays with any locale under Windows

前端 未结 2 1049
盖世英雄少女心
盖世英雄少女心 2021-01-04 19:34

I\'m trying to get the day of the week, and have it work consistently in any locale. In locales with Latin alphabets, everything is fine.

Sys.getlocale()
##         


        
2条回答
  •  被撕碎了的回忆
    2021-01-04 20:23

    The system of naming locales is OS-specific. I recommend you to read the locales from R Installation and Administration manual for a complete explanation.

    under windows :

    The list of supported language is listed MSDN Language Strings. And surprisingly there is not Arabic language there. The "Language string" column contains the legal input for setting locale in R and even in the list contry /regions strings there no country spoken arabic there.

    Of course you can change your locale global settings( panel setting --> region --> ..) but this will change it globally and it is not sure to get the right output without encoding problem.

    under linux(ubuntu in my case):

    Arabic is generally not supported by default, but is easy to set it using locale.

     locale -a                     ## to list all already supported language
     sudo locale-gen ar_QA.UTF-8   ## install it in case does not exist
    

    under RStudio now :

     Sys.setlocale('LC_TIME','ar_QA.UTF-8')
    [1] "ar_QA.UTF-8"
    
    > format(Sys.Date(),'%A')
    [1] "الثلاثاء
    

    Note also that under R console the printing is not as pretty as in R studio because it is written from left to right not from right to left.

提交回复
热议问题