1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 18:06:12 +01:00

get_locale improvement

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-11-12 15:07:43 +01:00
parent 6b0f4ffbd4
commit 5cb8f3cf72

View File

@ -31,19 +31,23 @@ get_locale <- function() {
} }
lang <- Sys.getlocale("LC_COLLATE") lang <- Sys.getlocale("LC_COLLATE")
# grepl with case = FALSE is faster than like # grepl with case = FALSE is faster than like
if (grepl("(English|en_)", lang, ignore.case = FALSE)) { if (grepl("^(English|en_|EN_)", lang, ignore.case = FALSE)) {
# as first option to optimise speed
"en" "en"
} else if (grepl("(German|Deutsch|de_)", lang, ignore.case = FALSE)) { } else if (grepl("^(German|Deutsch|de_|DE_)", lang, ignore.case = FALSE)) {
"de" "de"
} else if (grepl("(Dutch|Nederlands|nl_)", lang, ignore.case = FALSE)) { } else if (grepl("^(Dutch|Nederlands|nl_|NL_)", lang, ignore.case = FALSE)) {
"nl" "nl"
} else if (grepl("(Spanish|Espa.ol|es_)", lang, ignore.case = FALSE)) { } else if (grepl("^(Spanish|Espa.ol|es_|ES_)", lang, ignore.case = FALSE)) {
"es" "es"
} else if (grepl("(Italian|Italiano|it_)", lang, ignore.case = FALSE)) { } else if (grepl("^(Italian|Italiano|it_|IT_)", lang, ignore.case = FALSE)) {
"it" "it"
} else if (grepl("(French|Fran.ais|fr_)", lang, ignore.case = FALSE)) { } else if (grepl("^(French|Fran.ais|fr_|FR_)", lang, ignore.case = FALSE)) {
"fr" "fr"
} else if (grepl("(Portuguese|Portugu.s|pt_)", lang, ignore.case = FALSE)) { } else if (grepl("^(Portuguese|Portugu.s|pt_|PT_)", lang, ignore.case = FALSE)) {
"pt" "pt"
} else {
# other language, set to English
"en"
} }
} }