📄 setlocale.3
字号:
.TH setlocale 3.SH Name setlocale \- set localization for internationalized program.SH Syntax .B #include <locale.h>.PP.B char *setlocale (\fIcategory\fP, \fIlocale\fP).br.B int category;.br.B char *locale;.SH Description .NXR "setlocale subroutine"The.PN setlocalefunction changes or queries the run-time environment of the program.The function can affect the settings of language, territory, and codeset in the program's environment. .PPIn the .I categoryargument, you specify what part of the run-time environment you want toaffect. Possible values for.I categoryare shown in the following table:.PP.TS tab(@);lfHBp-1v-1 lfHBp-1v-1 lfHBp-1v-1lfHBp-1v-1 lfHBp-1v-1 lfHBp-1v-1lp-1v-1 lp-1v-1 lp-1v-1 ._.sp 4p@Effect of Specifying@Environment Variable \fIcategory\fP@the Value@Affected.sp 4p_.sp 4pLC_ALL@T{Sets or queries entire environmentT}@LANGLC_COLLATE@T{Changes or queries collation sequencesT}@LC_COLLATELC_CTYPE@T{Changes or queries character classificationT}@LC_CTYPELC_NUMERIC@T{Changes or queries number format informationT}@LC_NUMERICLC_TIME@T{Changes or queries time conversion parametersT}@LC_TIMELC_MONETARY@T{Changes or queries monetary informationT}@LC_MONETARY.sp 4p_.TE.PPYou change only one part of the program'slocale in a single call to.PN setlocale ,unless you use the category.PN LC_ALL ..PPThe .I localeargument is a pointer to a character stringcontaining the required setting of .I category in the following format:.EXlanguage[_territory[.codeset]][@modifier].EEYou use .I languageto specify the native language you want in theprogram environment. You can specify what dialect of the native languageyou want in .I _territory, and the codeset to be used in .I codeset.For example, the following string specifies the French native language, as spoken inFrance (as opposed to Switzerland), and the Digital MultinationalCharacter Set:.EX 0LANG = FRE_FR.MCS.EEYou use .I @modifierto select a specific instanceof an environment setting within a single category. For example, youcould use .I @modifierto select dictionary sorting of data, asopposed to telephone directory sorting. You can use .I @modifierfor allcategories, except .PN LC_ALL ..PPThe following preset values of .I localeare defined for all the settings of \fIcategory\fR:.IP \fB"C"\fP 10Specifies setting the locale to the minimum Clanguage environment, as specified by the ANSI standard for the Clanguage. (Draft ANSI X3.159) .IP \fB""\fP 10Specifies using the environment variable correspondingto \fIcategory\fR to set the locale.If the appropriate environment variable is not set, the .PN LANGenvironment variable is used. If .PN LANGis not set, .PN setlocalereturns an error..IP \fBNULL\fP 10Queries the current international environment and returns currentlocale setting. You can use the string .PN setlocale returns only as input to a subsequent.PN setlocalecall; in particular, the string cannot be printed for category.PN LC_ALL .The string.PN setlocalereturns is a pointer to static data area that might be written over..\".NT.\"When a C program is compiled the.\.PN \-li.\"option must be used to include the internationalization library, for.\"example:.\".sp.\"\f(CWcc \-o prog prog.c \-li\fR.\".NE.SS International Environment.IP INTLINFO 15The INTLINFO environment variable specifies the directory to search forlanguage databases. The default is to search the .PN /usr/lib/intlndirectory..SH Examples The following calls to the.PN setlocalefunction set the environment to the French language and thenmodify the collating sequence to German dictionary collation:.EXsetlocale (LC_ALL, "FRE_FR.MCS");setlocale (LC_COLLATE, "GER_DE.MCS@dict");.EEYou can use the.PN setlocalefunction to bind the specific language requirements of a userto the program as follows:.EXstatus = setlocale (LC_ALL, "");.EEFor this example to work properly, the user of the internationalprogram sets the LANG variable before running the program. Once LANGis set and the program runs, this call causes.PN setlocaleto use the definition of LANG to set the current locale. Youshould test the value of .PN statusafter the call completes to be sure no errors occur..SH Return Values If you pass valid setting for .I category and .IR locale ,other than NULL,.PN setlocalechanges the current locale and returns the string associated with thatlocale..PPIf .I localeis NULL,.PN setlocalereturns the string associated with .I categoryfor the current .I locale.The current.I localeis unchanged. The string.PN setlocalereturns may not be in a printable format..PPIf either the .I categoryor .I localeargument is invalid, .PN setlocale returns.PN NULL .The .PN setlocalefunction does not modify the locale if any part of the call is invalid..PPThe.PN setlocalefunction stores its return values in a data area that may be writtenover. You should move the return value to another location if you wantto use it in your program..SH See Also ic(1int), nl_langinfo(3int), printf(3int), environ(5int), lang(5int).br.I Guide to Developing International Software
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -