Rev 81771 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/locales.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2023 R Core Team% Distributed under GPL 2 or later\name{locales}\title{Query or Set Aspects of the Locale}\alias{locales}\alias{Sys.getlocale}\alias{Sys.setlocale}\alias{.LC.categories}\alias{LC_ALL}\alias{LC_COLLATE}\alias{LC_CTYPE}\alias{LC_MONETARY}\alias{LC_NUMERIC}\alias{LC_TIME}%% Next 3 were only 'ifdef unix':\alias{LC_MESSAGES}\alias{LC_PAPER}\alias{LC_MEASUREMENT}\description{Get details of or set aspects of the locale for the \R process.}\usage{Sys.getlocale (category = "LC_ALL")Sys.setlocale (category = "LC_ALL", locale = "").LC.categories}\arguments{\item{category}{character string. The following categories shouldalways be supported: \code{"LC_ALL"}, \code{"LC_COLLATE"},\code{"LC_CTYPE"}, \code{"LC_MONETARY"}, \code{"LC_NUMERIC"} and\code{"LC_TIME"}. Some systems (not Windows) will also support\code{"LC_MESSAGES"}, \code{"LC_PAPER"} and \code{"LC_MEASUREMENT"}.These category names are available in \code{.LC.categories}; even whennot supported, \code{Sys.getlocale(.)} will return \code{""}, e.g., forthe \code{"LC_PAPER"} example on Windows.}\item{locale}{character string. A valid locale name on the system inuse. Normally \code{""} (the default) will pick up the defaultlocale for the system.}}\details{The locale describes aspects of the internationalization of a program.Initially most aspects of the locale of \R are set to \code{"C"}(which is the default for the C language and reflects North-Americanusage -- also known as \code{"POSIX"}). \R sets \code{"LC_CTYPE"} and\code{"LC_COLLATE"}, which allow the use of a different character setand alphabetic comparisons in that character set (including the use of\code{\link{sort}}), \code{"LC_MONETARY"} (for use by\code{\link{Sys.localeconv}}) and \code{"LC_TIME"} may affect thebehaviour of \code{\link{as.POSIXlt}} and \code{\link{strptime}} andfunctions which use them (but not \code{\link{date}}).The first seven categories described here are those specified byPOSIX. \code{"LC_MESSAGES"} will be \code{"C"} on systems that do notsupport message translation, and is not supported on Windows, where you\emph{must} use the \env{LANGUAGE} environment variable for messagetranslation, see below. Tryingto use an unsupported category is an error for \code{Sys.setlocale}.Note that setting category \code{"LC_ALL"} sets only categories\code{"LC_COLLATE"}, \code{"LC_CTYPE"}, \code{"LC_MONETARY"} and\code{"LC_TIME"}.Attempts to set an invalid locale are ignored. There may or may notbe a warning, depending on the OS.Attempts to change the character set (by\code{Sys.setlocale("LC_CTYPE", )}, if that implies a differentcharacter set) during a session may not work and are likely to lead tosome confusion.Note that the \env{LANGUAGE} environment variable has precedence over\code{"LC_MESSAGES"} in selecting the language for message translationon most \R platforms.On platforms where ICU is used for collation the locale used forcollation can be reset by \code{\link{icuSetCollate}}. Except onWindows, the initial setting is taken from the \code{"LC_COLLATE"}category, and it is reset when this is changed by a call to\code{Sys.setlocale}.}\value{A character string of length one describing the locale in use (aftersetting for \code{Sys.setlocale}), or an empty character string if thecurrent locale settings are invalid or \code{NULL} if localeinformation is unavailable.For \code{category = "LC_ALL"} the details of the string aresystem-specific: it might be a single locale name or a set of localenames separated by \code{"/"} (macOS) or \code{";"}(Windows, Linux). For portability, it is best to query categoriesindividually: it is not necessarily the case that the result of\code{foo <- Sys.getlocale()} can be used in\code{Sys.setlocale("LC_ALL", locale = foo)}.}\section{Available locales}{On most Unix-alikes the POSIX shell command \command{locale -a} willlist the \sQuote{available public} locales. What that means isplatform-dependent. On recent Linuxen this may mean \sQuote{availableto be installed} as on some RPM-based systems the locale data is inseparate RPMs. On Debian/Ubuntu the set of available locales ismanaged by OS-specific facilities such as \command{locale-gen} and\command{locale -a} lists those currently enabled.For Windows, Microsoft moves its documentation frequently so a Websearch is the best way to find current information. From \R 4.2, UCRTlocale names should be used. The character set should match thesystem/ANSI codepage (\code{l10n_info()$codepage} be the same as\code{l10n_info()$system.codepage}). Setting it to any other valueresults in a warning and may cause encoding problems. As from \R 4.2on recent Windows the system codepage is 65001 and one should alwaysuse locale names ending with \code{".UTF-8"} (except for \code{"C"}and \code{""}), otherwise Windows may add a different character set.}% assume this just affects strtod/atof, scanf/printf and friends,% as seems to be the case in glibc.\section{Warning}{Setting \code{"LC_NUMERIC"} to any value other than \code{"C"} maycause \R to function anomalously, so gives a warning. Inputconversions in \R itself are unaffected, but the reading and writingof ASCII \code{\link{save}} files will be, as may packages which dotheir own input/output.Setting it temporarily on a Unix-alike to produce graphical or textoutput may work well enough, but \code{\link{options}(OutDec)} isoften preferable.Almost all the output routines used by \R itself under Windows ignorethe setting of \code{"LC_NUMERIC"} since they make use of the Triolibrary which is not internationalized.}\note{Changing the values of locale categories whilst \R is running oughtto be noticed by the OS services, and usually is but exceptions havebeen seen (usually in collation services).Do not use the value of \code{Sys.getlocale("LC_CTYPE")} to attempt tofind the character set -- for example UTF-8 locales can have suffix\samp{.UTF-8} or \samp{.utf8} (more common on Linux than \samp{UTF-8})or none (as on macOS) and Latin-9 locales can have suffix\samp{ISO8859-15}, \samp{iso885915}, \samp{iso885915@euro} or\samp{ISO8859-15@euro}. Use \code{\link{l10n_info}} instead.}\seealso{\code{\link{strptime}} for uses of \code{category = "LC_TIME"}.\code{\link{Sys.localeconv}} for details of numerical and monetaryrepresentations.\code{\link{l10n_info}} gives some summary facts about the locale andits encoding (including if it is UTF-8).The \sQuote{R Installation and Administration} manual for backgroundon locales and how to find out locale names on your system.}\examples{Sys.getlocale()## Date-time related :Sys.getlocale("LC_TIME") -> olcTthen <- as.POSIXlt("2001-01-01 01:01:01", tz = "UTC+1")\dontrun{c(m = months(then), wd = weekdays(then)) # locale specificSys.setlocale("LC_TIME", "de") # Solaris: details are OS-dependentSys.setlocale("LC_TIME", "de_DE") # Many Unix-alikesSys.setlocale("LC_TIME", "de_DE.UTF-8") # Linux, macOS, other Unix-alikesSys.setlocale("LC_TIME", "de_DE.utf8") # some Linux versionsSys.setlocale("LC_TIME", "German.UTF-8") # WindowsSys.getlocale("LC_TIME") # the last one successfully set abovec(m = months(then), wd = weekdays(then)) # in C_TIME locale 'cT' ; typically German}Sys.setlocale("LC_TIME", "C")c(m = months(then), wd = weekdays(then)) # "standard" (still platform specific ?)Sys.setlocale("LC_TIME", olcT) # reset to previous## Other localesSys.getlocale("LC_PAPER") # may or may not be set.LC.categories # of length 9 on all platforms\dontrun{Sys.setlocale("LC_COLLATE", "C") # turn off locale-specific sorting,# usually (but not on all platforms)Sys.setenv("LANGUAGE" = "es") # set the language for error/warning messages}\donttest{## some nice formatting; should work on most platforms:sys <- Sys.info()[["sysname"]]sep <- switch(sys,"Darwin"=, "SunOS" = "/","Linux" =, "Windows" = ";")sg <- matrix(unlist(strsplit(strsplit(Sys.getlocale(), sep)[[1]], "=")), nrow=2)str(sloc <- setNames(sg[2,], sg[1,]))print.Dlist(sloc) # nicely readable}}\keyword{utilities}