@@ -64,21 +64,27 @@ check_type <- function(x, type){
64
64
65
65
# ' @title Get the language and location of a system locale
66
66
# '
67
- # ' @description OS-flexible approach to determining the system locale with
68
- # ' respect to language and location.
69
- # '
70
- # ' @param category \code{character} string of the locale environmental
71
- # ' variable to use, passed directly to \code{\link[base]{Sys.getlocale}}.
67
+ # ' @description OS-flexible approach to determining the system locale with
68
+ # ' respect to language and location.
69
+ # '
70
+ # ' @param category \code{character} string of the locale environmental variable
71
+ # ' to use, passed directly to \code{\link[base]{Sys.getlocale}}.
72
+ # '
73
+ # ' @param locale_asis \code{boolean} for returning \emph{language} and
74
+ # ' \emph{location} from \link[base]{Sys.getlocale} as it is. Defult to
75
+ # ' FALSE.
76
+ # '
77
+ # ' @return \code{character} vector with elements \code{"language"} and
78
+ # ' \code{"location"}.
79
+ # '
80
+ # ' @importFrom countrycode countrycode
72
81
# '
73
- # ' @return \code{character} vector with elements \code{"language"} and
74
- # ' \code{"location"}.
75
- # '
76
82
# ' @examples
77
83
# ' get_locale()
78
84
# '
79
- # ' @export
80
- # '
81
- get_locale <- function (category = " LC_TIME" ){
85
+ # ' @export
86
+ # '
87
+ get_locale <- function (category = " LC_TIME" , locale_asis = FALSE ){
82
88
ismac <- Sys.info()[" sysname" ] == " Darwin"
83
89
issolaris <- Sys.info()[" sysname" ] == " SunOS"
84
90
splitchar <- ifelse(ismac | issolaris , " /" , " ;" )
@@ -88,8 +94,42 @@ get_locale <- function(category = "LC_TIME"){
88
94
locale <- strsplit(locale , " _" )[[1 ]]
89
95
locale <- setNames(locale , c(" language" , " location" ))
90
96
locale [[" location" ]] <- sub(" \\ ..*" , " " , locale [[" location" ]])
91
- locale
92
- }
93
-
94
-
97
+
98
+ language_codes <- c(' af' , ' sq' , ' ar' , ' hy' , ' az' , ' eu' , ' be' , ' bn' , ' bs' ,
99
+ ' bg' , ' ca' , ' ceb' , ' zh-CN' , ' zh-TW' , ' hr' , ' cs' , ' da' ,
100
+ ' nl' , ' en' , ' eo' , ' et' , ' tl' , ' fi' , ' fr' , ' gl' , ' ka' ,
101
+ ' de' , ' el' , ' gu' , ' ht' , ' ha' , ' iw' , ' hi' , ' hmn' , ' hu' ,
102
+ ' is' , ' ig' , ' id' , ' ga' , ' it' , ' ja' , ' jw' , ' kn' , ' km' ,
103
+ ' ko' , ' lo' , ' la' , ' lv' , ' lt' , ' mk' , ' ms' , ' mt' , ' mi' ,
104
+ ' mr' , ' mn' , ' ne' , ' no' , ' fa' , ' pl' , ' pt' , ' pa' , ' ro' ,
105
+ ' ru' , ' sr' , ' sk' , ' sl' , ' so' , ' es' , ' sw' , ' sv' , ' ta' ,
106
+ ' te' , ' th' , ' tr' , ' uk' , ' ur' , ' vi' , ' cy' , ' yi' , ' yo' ,
107
+ ' zu' )
108
+ language_names <- c(' Afrikaans' , ' Albanian' , ' Arabic' , ' Armenian' ,
109
+ ' Azerbaijani' , ' Basque' , ' Belarusian' , ' Bengali' ,
110
+ ' Bosnian' , ' Bulgarian' , ' Catalan' , ' Cebuano' ,
111
+ ' Chinese_Simplified' , ' Chinese_Traditional' ,
112
+ ' Croatian' , ' Czech' , ' Danish' , ' Dutch' , ' English' ,
113
+ ' Esperanto' , ' Estonian' , ' Filipino' , ' Finnish' ,
114
+ ' French' , ' Galician' , ' Georgian' , ' German' , ' Greek' ,
115
+ ' Gujarati' , ' Haitian_Creole' , ' Hausa' , ' Hebrew' ,
116
+ ' Hindi' , ' Hmong' , ' Hungarian' , ' Icelandic' , ' Igbo' ,
117
+ ' Indonesian' , ' Irish' , ' Italian' , ' Japanese' ,
118
+ ' Javanese' , ' Kannada' , ' Khmer' , ' Korean' , ' Lao' ,
119
+ ' Latin' , ' Latvian' , ' Lithuanian' , ' Macedonian' ,
120
+ ' Malay' , ' Maltese' , ' Maori' , ' Marathi' , ' Mongolian' ,
121
+ ' Nepali' , ' Norwegian' , ' Persian' , ' Polish' ,
122
+ ' Portuguese' , ' Punjabi' , ' Romanian' , ' Russian' ,
123
+ ' Serbian' , ' Slovak' , ' Slovenian' , ' Somali' , ' Spanish' ,
124
+ ' Swahili' , ' Swedish' , ' Tamil' , ' Telugu' , ' Thai' ,
125
+ ' Turkish' , ' Ukrainian' , ' Urdu' , ' Vietnamese' , ' Welsh' ,
126
+ ' Yiddish' , ' Yoruba' , ' Zulu' )
127
+ names(language_codes ) <- language_names
95
128
129
+ if (! locale_asis && (ismac | issolaris )) {
130
+ locale [" language" ] <- names(which(language_codes == locale [" language" ]))
131
+ locale [" location" ] <- countrycode(locale [" location" ],
132
+ " eurostat" , " un.name.en" )
133
+ }
134
+ return (locale )
135
+ }
0 commit comments