📄 locale.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>Locale</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><blockquote><center><h2><a name = "tag_005"> </a>Locale</h2></center><xref type="1" name="locale"></xref><h3><a name = "tag_005_001"> </a>General</h3><xref type="2" name="locgen"></xref>A<i>locale</i>is the definition of the subset of a user's environment that dependson language and cultural conventions.It is made up from one or more categories.Each category is identified by its name and controls specific aspectsof the behaviour of components of the system.Category names correspond to the following environment variable names:<dl compact><dt><i>LC_CTYPE</i><dd>Character classification and case conversion.<dt><i>LC_COLLATE</i><dd>Collation order.<dt><i>LC_TIME</i><dd>Date and time formats.<dt><i>LC_NUMERIC</i><dd>Numeric, non-monetary formatting.<dt><i>LC_MONETARY</i><dd>Monetary formatting.<dt><i>LC_MESSAGES</i><dd>Formats of informative and diagnostic messagesand interactive responses.</dl><p>The standard utilities in the <b>XCU</b> specificationbase their behaviouron the current locale, as defined in the<b>ENVIRONMENT VARIABLES</b>section for each utility.The behaviour of some of the C-languagefunctions defined in the <b>XSH</b> specification will also be modified based on thecurrent locale, as defined by the last call to<i><a href="../xsh/setlocale.html">setlocale()</a></i>.<p>Locales other than those supplied by the implementation can becreated by the application via the<i><a href="../xcu/localedef.html">localedef</a></i>utility, if it is provided;see the <b>XCU</b> specification.This capability is supported on all systems where the{POSIX2_LOCALEDEF}or{XOPEN_XCU_VERSION}options are supported; see the <b>XSH</b> specification<i><a href="../xsh/unistd.h.html"><unistd.h></a></i>.Even if<i><a href="../xcu/localedef.html">localedef</a></i>is not provided, all implementations conforming to the <b>XSH</b> specificationprovide one or more locales that behave as described in this chapter. The input to the utility is described in<xref href=locldefn><a href="#tag_005_003">Locale Definition</a></xref>.The value that is used to specify a locale when using environmentvariables will be the string specified as the<i>name</i>operand to the<i><a href="../xcu/localedef.html">localedef</a></i>utility when the locale was created.The stringsCandPOSIXare reserved as identifiers for the POSIX locale (see<xref href=posixloc><a href="#tag_005_002">POSIX Locale</a></xref>).When the value of a locale environment variable begins with a slash(/),it is interpreted as the pathname of the locale definition;the type of file (regular, directory, and so forth) used to storethe locale definition is implementation-dependent.If the valuedoes not begin with a slash,the mechanism used to locate the localeis implementation-dependent.<p>If different character sets are used by the locale categories, theresults achieved by an application utilising these categories are undefined.Likewise, if different codesets are used for the databeing processed by interfaces whose behaviour is dependent on thecurrent locale, or the codeset is different from the codesetassumed when the locale was created, the result is also undefined.<p>Applications can select the desired locale by invoking the<i><a href="../xsh/setlocale.html">setlocale()</a></i>function (or equivalent) with the appropriate value.If the function is invoked with an empty string,such as:<code><pre>setlocale(LC_ALL, "");</code></pre>the value of thecorresponding environment variable is used.If the environment variable is unset or is set to the empty string,the implementation sets the appropriate environment as defined in<xref href=envvar><a href="envvar.html#tag_002">Environment Variables</a></xref>.<h3><a name = "tag_005_002"> </a>POSIX Locale</h3><xref type="2" name="posixloc"></xref>All systems provide a<i>POSIX locale</i>,also known as the C locale.The behaviour of standard utilitiesand functions in the POSIX localeis as if the locale was defined via the<i><a href="../xcu/localedef.html">localedef</a></i>utility with input data from the POSIX locale tables in<xref href=locldefn><a href="#tag_005_003">Locale Definition</a></xref>.<p>The tables in<xref href=locldefn><a href="#tag_005_003">Locale Definition</a></xref>describe the characteristics and behaviour of thePOSIX locale for data consisting entirely of characters fromthe portable character setand the control character set.For other characters,the behaviour is unspecified.For C-language programs,the POSIX locale is the default locale when the<i><a href="../xsh/setlocale.html">setlocale()</a></i>function is not called.<p>The POSIX locale can be specified by assigning to the appropriateenvironment variables the valuesCorPOSIX.<p>All implementations define a locale as the defaultlocale, to be invoked when no environmentvariables are set, or set to the empty string.This default locale can be the POSIX localeor any other, implementation-dependent locale.Some implementations may provide facilities forlocal installation administrators to set the defaultlocale, customising it for each location.This specification set does not require such a facility.<h3><a name = "tag_005_003"> </a>Locale Definition</h3><xref type="2" name="locldefn"></xref>Locales can be described with the file format presented in this section.The file format is that accepted by the<i><a href="../xcu/localedef.html">localedef</a></i>utility.For the purposes of this section, the file is referred to as thebut no locales are affected by this file unlessit is processed by<i><a href="../xcu/localedef.html">localedef</a></i>or some similar mechanism.Any requirements in this section imposed upon the utilityapply to<i><a href="../xcu/localedef.html">localedef</a></i>or to any other similar utility used to install locale informationusing the locale definition file format described here.<p>The locale definition file must contain one or more locale category sourcedefinitions, and must not contain more than one definition for thesame locale category.If the file contains source definitions for more than one category,implementation-dependent categories,if present, must appear after thecategories defined by<xref href=locgen><a href="#tag_005_001">General</a></xref>.A category source definition must contain either the definition ofa category or a<b>copy</b>directive.For a description of the<b>copy</b>directive, see<i><a href="../xcu/localedef.html">localedef</a></i>.In the event that some of the information for a locale category,as specified in this specification, is missing from the locale sourcedefinition, the behaviour of that category, if it is referenced,is unspecified.<p>A category source definition consists of a category header,a category body and a category trailer.A category header consists of the character stringnaming of the category, beginning with the characters LC_.The category trailer consists of the string END,followed by one or more blank charactersand the string used in the corresponding category header.<p>The category body consists of one or more lines of text.Each line contains an identifier, optionally followed byone or more operands.Identifiers are either keywords, identifying a particular localeelement, or collating elements.In addition to the keywords defined in this specification, the source cancontain implementation-dependent keywords.Each keyword within a locale must have a unique name(that is, two categories cannot have a commonly-named keyword);no keyword can start with the characters LC_.Identifiers must be separated from the operands by one or moreblank characters.<p>Operands must be characters, collating elementsor strings of characters.Strings must be enclosed in double-quotes.Literal double-quotes within strings must be preceded by the<<i>escape character</i>>,described below.When a keyword is followedby more than one operand, the operands must be separatedby semicolons;blank charactersare allowed both before and after a semicolon.<p>The first category header in the file can be preceded bya line modifying the comment character.It has the following format, starting in column 1:<pre><dl compact><dt> <dd><tt>"comment_char %c\n"</tt>, <<i>comment character</i>></dl></pre><p>The comment character defaults to the number sign(#).Blank lines and lines containing the<<i>comment character</i>>in the first position are ignored.<p>The first category header in the file can be preceded bya line modifying the escape character to be used in the file.It has the following format, starting in column 1:<pre><dl compact><dt> <dd><tt>"escape_char %c\n"</tt>, <<i>escape character</i>></dl></pre><p>The escape character defaults to backslash,which is the character used in all examples shown in this specification.<p>A line can be continued by placing an escape characteras the last character on the line;this continuation character will be discarded from the input.Although the implementation need not acceptany one portion of a continued linewith a length exceeding{LINE_MAX}bytes, it places no limits on theaccumulated length of the continued line.Comment lines cannot be continued on a subsequent lineusing an escapednewline character.<p>Individual characters, characters in strings, and collatingelements must be represented using symbolic names, as defined below.In addition, characters can be represented using thecharacters themselves or as octal, hexadecimal or decimal constants.When non-symbolic notation is used, the resultantlocale definitions will in many cases not be portable between systems.The left angle bracket(<)is a reserved symbol, denoting the start of a symbolic name;when used torepresent itself it must be preceded by the escape character.The following rules apply to character representation:<ol><p><li>A character can be represented via a symbolic name, enclosedwithin angle brackets "<" and ">".The symbolic name, includingthe angle brackets, must exactly match a symbolic namedefined in the charmap file specified via the<i><a href="../xcu/localedef.html">localedef</a></i><b>-f</b>option, and will be replaced bya character value determined from the value associated withthe symbolic name in the charmap file.The use of a symbolic name not found in the charmapfile constitutes an error, unless the category isLC_CTYPE or LC_COLLATE,in which case it constitutes a warning condition (see<i><a href="../xcu/localedef.html">localedef</a></i>for a description of action resulting from errors and warnings).The specification of a symbolic name in a<b>collating-element</b>or<b>collating-symbol</b>section that duplicates a symbolic namein the charmap file (if present) is an error.Use of the escape character or a right angle bracket withina symbolic name is invalid unlessthe character is preceded by the escape character.<p><b>Example</b>:<code><pre><c>;<c-cedilla> "<M><a><y>"</code></pre><p><li>A character can be represented by the character itself, inwhich case the value of the character is implementation-dependent.Within a string, the double-quote character, the escapecharacter and the right angle bracket character must beescaped (preceded by the escape character) to be interpretedas the character itself.Outside strings, the characters:<code><pre>, ; < > <i>escape_char</i></code></pre>must be escaped to be interpreted as the character itself.<p><b>Example</b>:<code><pre>c ß "May"</code></pre><p><li>A character can be represented as an octal constant.An octal constant is specified asthe escape characterfollowed by two or more octal digits.Each constant represents a byte value.Multi-byte values can be represented by concatenated constantsspecified in byte order withthe last constant specifying the least significant byte of the character.<p><b>Example</b>:<code><pre>\143;\347;\143\150 "\115\141\171"</code></pre><p><li>A character can be represented as a hexadecimal constant.A hexadecimal constant is specified asthe escape character followed by anxfollowed by two or more hexadecimal digits.Each constant represents a byte value.Multi-byte values can be represented by concatenated constantsspecified in byte order withthe last constant specifying the least significant byte of the character.<p><b>Example</b>:<code><pre>\x63;\xe7;\x63\x68 "\x4d\x61\x79"</code></pre><p><li>A character can be represented as a decimal constant.A decimal constantis specified as the escape character followed by adfollowed by two or more decimal digits.Each constant represents a byte value.Multi-byte values can be representedby concatenated constantsspecified in byte order withthe last constant specifying the least significant byte of the character.<p><b>Example</b>:<code><pre>\d99;\d231;\d99\d104 "\d77\d97\d121"</code></pre><p></ol><p>Implementations may accept single-digit octal,decimal or hexadecimal constants following the escape character.Only characters existing in the character set for whichthe locale definition is created can be specified,whether using symbolic names, the characters themselves,or octal, decimal or hexadecimal constants.If a charmap file is present, only characters definedin the charmap can be specifiedusing octal, decimal or hexadecimal constants.Symbolic names not present in thecharmap file can be specified and will be ignored, asspecified under item 1 above.<br><h4><a name = "tag_005_003_001"> </a>LC_CTYPE</h4><xref type="3" name="lc_ctype"></xref>The LC_CTYPE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -