AMR/R/get_locale.R

54 lines
2.7 KiB
R
Raw Normal View History

2018-11-05 13:20:32 +01:00
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Get language for AMR
#'
#' Determines the system language to be used for language-dependent output of AMR functions, like \code{\link{mo_gramstain}} and \code{\link{mo_type}}.
#' @details The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
#' @section Supported languages:
#' Supported languages are \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish), \code{"it"} (Italian), \code{"fr"} (French), and \code{"pt"} (Portuguese).
#' @export
get_locale <- function() {
if (!is.null(getOption("AMR_locale"))) {
if (getOption("AMR_locale") %in% c("en", "de", "nl", "es", "it", "fr", "pt")) {
return(getOption("AMR_locale"))
}
}
lang <- Sys.getlocale("LC_COLLATE")
# grepl with case = FALSE is faster than like
2018-11-12 15:07:43 +01:00
if (grepl("^(English|en_|EN_)", lang, ignore.case = FALSE)) {
# as first option to optimise speed
2018-11-05 13:20:32 +01:00
"en"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(German|Deutsch|de_|DE_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"de"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(Dutch|Nederlands|nl_|NL_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"nl"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(Spanish|Espa.ol|es_|ES_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"es"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(Italian|Italiano|it_|IT_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"it"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(French|Fran.ais|fr_|FR_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"fr"
2018-11-12 15:07:43 +01:00
} else if (grepl("^(Portuguese|Portugu.s|pt_|PT_)", lang, ignore.case = FALSE)) {
2018-11-05 13:20:32 +01:00
"pt"
2018-11-12 15:07:43 +01:00
} else {
2018-11-15 12:42:35 +01:00
# other language -> set to English
2018-11-12 15:07:43 +01:00
"en"
2018-11-05 13:20:32 +01:00
}
}