• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 国际化(I18n)<a name="ZH-CN_TOPIC_0000001209575571"></a>
2
3>![](../../public_sys-resources/icon-note.gif) **说明:**
4>从 API Version 7 开始支持。
5
6## 导入模块<a name="zh-cn_topic_0000001163490118_s56d19203690d4782bfc74069abb6bd71"></a>
7
8```
9import i18n from '@ohos.i18n';
10```
11
12## 权限<a name="zh-cn_topic_0000001163490118_section11257113618419"></a>
13
1415
16## i18n.getDisplayLanguage<a name="zh-cn_topic_0000001163490118_section4734636131914"></a>
17
18getDisplayLanguage\(language: string, locale: string, sentenceCase?: boolean\): string
19
20获取指定语言的本地化显示文本。
21
22-   参数:
23
24    <a name="zh-cn_topic_0000001163490118_table8262171319013"></a>
25    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row726281313010"><th class="cellrowborder" valign="top" width="14.92%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001163490118_p426217131016"><a name="zh-cn_topic_0000001163490118_p426217131016"></a><a name="zh-cn_topic_0000001163490118_p426217131016"></a>参数名</p>
26    </th>
27    <th class="cellrowborder" valign="top" width="11.5%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001163490118_p42622131804"><a name="zh-cn_topic_0000001163490118_p42622131804"></a><a name="zh-cn_topic_0000001163490118_p42622131804"></a>类型</p>
28    </th>
29    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p id="zh-cn_topic_0000001163490118_p208801115312"><a name="zh-cn_topic_0000001163490118_p208801115312"></a><a name="zh-cn_topic_0000001163490118_p208801115312"></a>必填</p>
30    </th>
31    <th class="cellrowborder" valign="top" width="66.06%" id="mcps1.1.5.1.4"><p id="zh-cn_topic_0000001163490118_p926251313010"><a name="zh-cn_topic_0000001163490118_p926251313010"></a><a name="zh-cn_topic_0000001163490118_p926251313010"></a>说明</p>
32    </th>
33    </tr>
34    </thead>
35    <tbody><tr id="zh-cn_topic_0000001163490118_row42621713304"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p0262813102"><a name="zh-cn_topic_0000001163490118_p0262813102"></a><a name="zh-cn_topic_0000001163490118_p0262813102"></a>language</p>
36    </td>
37    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p1926261314016"><a name="zh-cn_topic_0000001163490118_p1926261314016"></a><a name="zh-cn_topic_0000001163490118_p1926261314016"></a>string</p>
38    </td>
39    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p088011110311"><a name="zh-cn_topic_0000001163490118_p088011110311"></a><a name="zh-cn_topic_0000001163490118_p088011110311"></a>是</p>
40    </td>
41    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p152627133014"><a name="zh-cn_topic_0000001163490118_p152627133014"></a><a name="zh-cn_topic_0000001163490118_p152627133014"></a><span>指定语言</span></p>
42    </td>
43    </tr>
44    <tr id="zh-cn_topic_0000001163490118_row15880755501"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p1348011161519"><a name="zh-cn_topic_0000001163490118_p1348011161519"></a><a name="zh-cn_topic_0000001163490118_p1348011161519"></a>locale</p>
45    </td>
46    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p68801855808"><a name="zh-cn_topic_0000001163490118_p68801855808"></a><a name="zh-cn_topic_0000001163490118_p68801855808"></a>string</p>
47    </td>
48    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p1188014118315"><a name="zh-cn_topic_0000001163490118_p1188014118315"></a><a name="zh-cn_topic_0000001163490118_p1188014118315"></a>是</p>
49    </td>
50    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p78803551506"><a name="zh-cn_topic_0000001163490118_p78803551506"></a><a name="zh-cn_topic_0000001163490118_p78803551506"></a>显示指定语言的区域ID</p>
51    </td>
52    </tr>
53    <tr id="zh-cn_topic_0000001163490118_row109041353904"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p199055531001"><a name="zh-cn_topic_0000001163490118_p199055531001"></a><a name="zh-cn_topic_0000001163490118_p199055531001"></a>sentenceCase</p>
54    </td>
55    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p59058531015"><a name="zh-cn_topic_0000001163490118_p59058531015"></a><a name="zh-cn_topic_0000001163490118_p59058531015"></a>boolean</p>
56    </td>
57    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p1888021103111"><a name="zh-cn_topic_0000001163490118_p1888021103111"></a><a name="zh-cn_topic_0000001163490118_p1888021103111"></a>否</p>
58    </td>
59    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p199051053209"><a name="zh-cn_topic_0000001163490118_p199051053209"></a><a name="zh-cn_topic_0000001163490118_p199051053209"></a>本地化显示文本是否要首字母大写</p>
60    </td>
61    </tr>
62    </tbody>
63    </table>
64
65-   返回值:
66
67    <a name="zh-cn_topic_0000001163490118_table0483117706"></a>
68    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row6483417306"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001163490118_p7483617903"><a name="zh-cn_topic_0000001163490118_p7483617903"></a><a name="zh-cn_topic_0000001163490118_p7483617903"></a>类型</p>
69    </th>
70    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001163490118_p14835171705"><a name="zh-cn_topic_0000001163490118_p14835171705"></a><a name="zh-cn_topic_0000001163490118_p14835171705"></a>说明</p>
71    </th>
72    </tr>
73    </thead>
74    <tbody><tr id="zh-cn_topic_0000001163490118_row8483111717020"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001163490118_p1248320178013"><a name="zh-cn_topic_0000001163490118_p1248320178013"></a><a name="zh-cn_topic_0000001163490118_p1248320178013"></a>string</p>
75    </td>
76    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001163490118_p24836172000"><a name="zh-cn_topic_0000001163490118_p24836172000"></a><a name="zh-cn_topic_0000001163490118_p24836172000"></a><span>指定语言的本地化显示文本</span></p>
77    </td>
78    </tr>
79    </tbody>
80    </table>
81
82-   示例:
83
84    ```
85    i18n.getDisplayLanguage("zh", "en-GB", true);
86    i18n.getDisplayLanguage("zh", "en-GB");
87    ```
88
89
90## i18n.getDisplayCountry<a name="zh-cn_topic_0000001163490118_section156643561735"></a>
91
92getDisplayCountry\(country: string, locale: string, sentenceCase?: boolean\): string
93
94获取指定国家的本地化显示文本。
95
96-   参数:
97
98    <a name="zh-cn_topic_0000001163490118_table566415619320"></a>
99    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row86656561632"><th class="cellrowborder" valign="top" width="14.92%" id="mcps1.1.5.1.1"><p id="zh-cn_topic_0000001163490118_p366595612316"><a name="zh-cn_topic_0000001163490118_p366595612316"></a><a name="zh-cn_topic_0000001163490118_p366595612316"></a>参数名</p>
100    </th>
101    <th class="cellrowborder" valign="top" width="11.5%" id="mcps1.1.5.1.2"><p id="zh-cn_topic_0000001163490118_p766513561836"><a name="zh-cn_topic_0000001163490118_p766513561836"></a><a name="zh-cn_topic_0000001163490118_p766513561836"></a>类型</p>
102    </th>
103    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p id="zh-cn_topic_0000001163490118_p5380185513302"><a name="zh-cn_topic_0000001163490118_p5380185513302"></a><a name="zh-cn_topic_0000001163490118_p5380185513302"></a>必填</p>
104    </th>
105    <th class="cellrowborder" valign="top" width="66.06%" id="mcps1.1.5.1.4"><p id="zh-cn_topic_0000001163490118_p466585612312"><a name="zh-cn_topic_0000001163490118_p466585612312"></a><a name="zh-cn_topic_0000001163490118_p466585612312"></a>说明</p>
106    </th>
107    </tr>
108    </thead>
109    <tbody><tr id="zh-cn_topic_0000001163490118_row196651356536"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p1666515564316"><a name="zh-cn_topic_0000001163490118_p1666515564316"></a><a name="zh-cn_topic_0000001163490118_p1666515564316"></a>country</p>
110    </td>
111    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p19665135612319"><a name="zh-cn_topic_0000001163490118_p19665135612319"></a><a name="zh-cn_topic_0000001163490118_p19665135612319"></a>string</p>
112    </td>
113    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p13380155519303"><a name="zh-cn_topic_0000001163490118_p13380155519303"></a><a name="zh-cn_topic_0000001163490118_p13380155519303"></a>是</p>
114    </td>
115    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p15665205611310"><a name="zh-cn_topic_0000001163490118_p15665205611310"></a><a name="zh-cn_topic_0000001163490118_p15665205611310"></a><span>指定</span>国家</p>
116    </td>
117    </tr>
118    <tr id="zh-cn_topic_0000001163490118_row1766595615310"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p16651156431"><a name="zh-cn_topic_0000001163490118_p16651156431"></a><a name="zh-cn_topic_0000001163490118_p16651156431"></a>locale</p>
119    </td>
120    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p6665656936"><a name="zh-cn_topic_0000001163490118_p6665656936"></a><a name="zh-cn_topic_0000001163490118_p6665656936"></a>string</p>
121    </td>
122    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p638045563019"><a name="zh-cn_topic_0000001163490118_p638045563019"></a><a name="zh-cn_topic_0000001163490118_p638045563019"></a>是</p>
123    </td>
124    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p18665456932"><a name="zh-cn_topic_0000001163490118_p18665456932"></a><a name="zh-cn_topic_0000001163490118_p18665456932"></a>显示指定国家的区域ID</p>
125    </td>
126    </tr>
127    <tr id="zh-cn_topic_0000001163490118_row186658561436"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="zh-cn_topic_0000001163490118_p146650564311"><a name="zh-cn_topic_0000001163490118_p146650564311"></a><a name="zh-cn_topic_0000001163490118_p146650564311"></a>sentenceCase</p>
128    </td>
129    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="zh-cn_topic_0000001163490118_p466510566311"><a name="zh-cn_topic_0000001163490118_p466510566311"></a><a name="zh-cn_topic_0000001163490118_p466510566311"></a>boolean</p>
130    </td>
131    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="zh-cn_topic_0000001163490118_p143800551304"><a name="zh-cn_topic_0000001163490118_p143800551304"></a><a name="zh-cn_topic_0000001163490118_p143800551304"></a>否</p>
132    </td>
133    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="zh-cn_topic_0000001163490118_p13665145612315"><a name="zh-cn_topic_0000001163490118_p13665145612315"></a><a name="zh-cn_topic_0000001163490118_p13665145612315"></a>本地化显示文本是否要首字母大写</p>
134    </td>
135    </tr>
136    </tbody>
137    </table>
138
139-   返回值:
140
141    <a name="zh-cn_topic_0000001163490118_table14665145616317"></a>
142    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row46651556932"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001163490118_p366535611320"><a name="zh-cn_topic_0000001163490118_p366535611320"></a><a name="zh-cn_topic_0000001163490118_p366535611320"></a>类型</p>
143    </th>
144    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001163490118_p066512561431"><a name="zh-cn_topic_0000001163490118_p066512561431"></a><a name="zh-cn_topic_0000001163490118_p066512561431"></a>说明</p>
145    </th>
146    </tr>
147    </thead>
148    <tbody><tr id="zh-cn_topic_0000001163490118_row4665115614318"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001163490118_p1766615561337"><a name="zh-cn_topic_0000001163490118_p1766615561337"></a><a name="zh-cn_topic_0000001163490118_p1766615561337"></a>string</p>
149    </td>
150    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001163490118_p18666185614320"><a name="zh-cn_topic_0000001163490118_p18666185614320"></a><a name="zh-cn_topic_0000001163490118_p18666185614320"></a><span>指定国家的本地化显示文本</span></p>
151    </td>
152    </tr>
153    </tbody>
154    </table>
155
156-   示例:
157
158    ```
159    i18n.getDisplayCountry("zh-CN", "en-GB", true);
160    i18n.getDisplayCountry("zh-CN", "en-GB");
161    ```
162
163
164## i18n.getSystemLanugage<a name="zh-cn_topic_0000001163490118_section25111622174311"></a>
165
166getSystemLanguage\(\): string
167
168获取系统语言。
169
170-   返回值:
171
172    <a name="zh-cn_topic_0000001163490118_table10512322154313"></a>
173    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row35125225432"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001163490118_p251212225435"><a name="zh-cn_topic_0000001163490118_p251212225435"></a><a name="zh-cn_topic_0000001163490118_p251212225435"></a>类型</p>
174    </th>
175    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001163490118_p10512132211433"><a name="zh-cn_topic_0000001163490118_p10512132211433"></a><a name="zh-cn_topic_0000001163490118_p10512132211433"></a>说明</p>
176    </th>
177    </tr>
178    </thead>
179    <tbody><tr id="zh-cn_topic_0000001163490118_row451262234310"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001163490118_p155122222439"><a name="zh-cn_topic_0000001163490118_p155122222439"></a><a name="zh-cn_topic_0000001163490118_p155122222439"></a>string</p>
180    </td>
181    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001163490118_p651218222432"><a name="zh-cn_topic_0000001163490118_p651218222432"></a><a name="zh-cn_topic_0000001163490118_p651218222432"></a><span>系统语言ID</span></p>
182    </td>
183    </tr>
184    </tbody>
185    </table>
186
187-   示例:
188
189    ```
190    i18n.getSystemLanguage();
191    ```
192
193
194## i18n.getSystemRegion<a name="zh-cn_topic_0000001163490118_section65121922114312"></a>
195
196getSystemRegion\(\): string
197
198获取系统地区。
199
200-   返回值:
201
202    <a name="zh-cn_topic_0000001163490118_table145141228431"></a>
203    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row85141522184310"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001163490118_p75141722184315"><a name="zh-cn_topic_0000001163490118_p75141722184315"></a><a name="zh-cn_topic_0000001163490118_p75141722184315"></a>类型</p>
204    </th>
205    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001163490118_p651482224315"><a name="zh-cn_topic_0000001163490118_p651482224315"></a><a name="zh-cn_topic_0000001163490118_p651482224315"></a>说明</p>
206    </th>
207    </tr>
208    </thead>
209    <tbody><tr id="zh-cn_topic_0000001163490118_row1051442244317"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001163490118_p7514222164318"><a name="zh-cn_topic_0000001163490118_p7514222164318"></a><a name="zh-cn_topic_0000001163490118_p7514222164318"></a>string</p>
210    </td>
211    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001163490118_p11514522104314"><a name="zh-cn_topic_0000001163490118_p11514522104314"></a><a name="zh-cn_topic_0000001163490118_p11514522104314"></a>系统地区ID</p>
212    </td>
213    </tr>
214    </tbody>
215    </table>
216
217-   示例:
218
219    ```
220    i18n.getSystemRegion();
221    ```
222
223
224## i18n.getSystemLocale<a name="zh-cn_topic_0000001163490118_section10514122204316"></a>
225
226getSystemLocale\(\): string
227
228获取系统区域。
229
230-   返回值:
231
232    <a name="zh-cn_topic_0000001163490118_table11515122294317"></a>
233    <table><thead align="left"><tr id="zh-cn_topic_0000001163490118_row15515422144313"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="zh-cn_topic_0000001163490118_p205151722194316"><a name="zh-cn_topic_0000001163490118_p205151722194316"></a><a name="zh-cn_topic_0000001163490118_p205151722194316"></a>类型</p>
234    </th>
235    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="zh-cn_topic_0000001163490118_p12515132211434"><a name="zh-cn_topic_0000001163490118_p12515132211434"></a><a name="zh-cn_topic_0000001163490118_p12515132211434"></a>说明</p>
236    </th>
237    </tr>
238    </thead>
239    <tbody><tr id="zh-cn_topic_0000001163490118_row551612214432"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="zh-cn_topic_0000001163490118_p8516142217436"><a name="zh-cn_topic_0000001163490118_p8516142217436"></a><a name="zh-cn_topic_0000001163490118_p8516142217436"></a>string</p>
240    </td>
241    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="zh-cn_topic_0000001163490118_p45163224436"><a name="zh-cn_topic_0000001163490118_p45163224436"></a><a name="zh-cn_topic_0000001163490118_p45163224436"></a>系统区域ID</p>
242    </td>
243    </tr>
244    </tbody>
245    </table>
246
247-   示例:
248
249    ```
250    i18n.getSystemLocale();
251    ```
252
253
254