1% File src/library/utils/man/localeToCharset.Rd
2% Part of the R package, https://www.R-project.org
3% Copyright 1995-2009 R Core Team
4% Distributed under GPL 2 or later
5
6\name{localeToCharset}
7\alias{localeToCharset}
8\title{
9  Select a Suitable Encoding Name from a Locale Name
10}
11\description{
12  This functions aims to find a suitable coding for the locale named, by
13  default the current locale, and if it is a UTF-8 locale a suitable
14  single-byte encoding.
15}
16\usage{
17localeToCharset(locale = Sys.getlocale("LC_CTYPE"))
18}
19\arguments{
20  \item{locale}{character string naming a locale.}
21}
22\details{
23  The operation differs by OS.
24  \describe{
25    \item{On Windows,}{a locale is specified like \code{"English_United Kingdom.1252"}.
26  The final component gives the codepage, and this defines the encoding.
27    }
28    \item{On Unix-alikes:}{
29  Locale names are normally like \code{es_MX.iso88591}.  If final
30  component indicates an encoding and it is not \code{utf8} we just need
31  to look up the equivalent encoding name.  Otherwise, the language
32  (here \code{es}) is used to choose a primary or fallback encoding.
33    }
34  }
35  In the \code{C} locale the answer will be \code{"ASCII"}.
36}
37\value{
38  A character vector naming an encoding and possibly a fallback
39  single-encoding,  \code{NA} if unknown.
40}
41\note{
42  The encoding names are those used by \code{libiconv}, and ought also
43  to work with \code{glibc} but maybe not with commercial Unixen.
44}
45\seealso{
46  \code{\link{Sys.getlocale}}, \code{\link{iconv}}.
47}
48\examples{
49localeToCharset()
50}
51\keyword{ utilities }
52