js-apis-i18n.md 12.6 KB
Newer Older
Z
zengyawen 已提交
1
# 国际化(I18n)<a name="ZH-CN_TOPIC_0000001163490118"></a>
Z
zengyawen 已提交
2 3 4 5

>![](../../public_sys-resources/icon-note.gif) **说明:** 
>从 API Version 7 开始支持。

Z
zengyawen 已提交
6
## 导入模块<a name="s56d19203690d4782bfc74069abb6bd71"></a>
Z
zengyawen 已提交
7 8 9 10 11

```
import i18n from '@ohos.i18n';
```

Z
zengyawen 已提交
12
## 权限<a name="section11257113618419"></a>
Z
zengyawen 已提交
13 14 15



Z
zengyawen 已提交
16
## i18n.getDisplayLanguage<a name="section4734636131914"></a>
Z
zengyawen 已提交
17 18 19 20 21 22 23

getDisplayLanguage\(language: string, locale: string, sentenceCase?: boolean\): string

获取指定语言的本地化显示文本。

-   参数:

Z
zengyawen 已提交
24 25
    <a name="table8262171319013"></a>
    <table><thead align="left"><tr id="row726281313010"><th class="cellrowborder" valign="top" width="14.92%" id="mcps1.1.5.1.1"><p id="p426217131016"><a name="p426217131016"></a><a name="p426217131016"></a>参数名</p>
Z
zengyawen 已提交
26
    </th>
Z
zengyawen 已提交
27
    <th class="cellrowborder" valign="top" width="11.5%" id="mcps1.1.5.1.2"><p id="p42622131804"><a name="p42622131804"></a><a name="p42622131804"></a>类型</p>
Z
zengyawen 已提交
28
    </th>
Z
zengyawen 已提交
29
    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p id="p208801115312"><a name="p208801115312"></a><a name="p208801115312"></a>必填</p>
Z
zengyawen 已提交
30
    </th>
Z
zengyawen 已提交
31
    <th class="cellrowborder" valign="top" width="66.06%" id="mcps1.1.5.1.4"><p id="p926251313010"><a name="p926251313010"></a><a name="p926251313010"></a>说明</p>
Z
zengyawen 已提交
32 33 34
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
35
    <tbody><tr id="row42621713304"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p0262813102"><a name="p0262813102"></a><a name="p0262813102"></a>language</p>
Z
zengyawen 已提交
36
    </td>
Z
zengyawen 已提交
37
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p1926261314016"><a name="p1926261314016"></a><a name="p1926261314016"></a>string</p>
Z
zengyawen 已提交
38
    </td>
Z
zengyawen 已提交
39
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p088011110311"><a name="p088011110311"></a><a name="p088011110311"></a>是</p>
Z
zengyawen 已提交
40
    </td>
Z
zengyawen 已提交
41
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p152627133014"><a name="p152627133014"></a><a name="p152627133014"></a><span>指定语言</span></p>
Z
zengyawen 已提交
42 43
    </td>
    </tr>
Z
zengyawen 已提交
44
    <tr id="row15880755501"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p1348011161519"><a name="p1348011161519"></a><a name="p1348011161519"></a>locale</p>
Z
zengyawen 已提交
45
    </td>
Z
zengyawen 已提交
46
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p68801855808"><a name="p68801855808"></a><a name="p68801855808"></a>string</p>
Z
zengyawen 已提交
47
    </td>
Z
zengyawen 已提交
48
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p1188014118315"><a name="p1188014118315"></a><a name="p1188014118315"></a>是</p>
Z
zengyawen 已提交
49
    </td>
Z
zengyawen 已提交
50
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p78803551506"><a name="p78803551506"></a><a name="p78803551506"></a>显示指定语言的区域ID</p>
Z
zengyawen 已提交
51 52
    </td>
    </tr>
Z
zengyawen 已提交
53
    <tr id="row109041353904"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p199055531001"><a name="p199055531001"></a><a name="p199055531001"></a>sentenceCase</p>
Z
zengyawen 已提交
54
    </td>
Z
zengyawen 已提交
55
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p59058531015"><a name="p59058531015"></a><a name="p59058531015"></a>boolean</p>
Z
zengyawen 已提交
56
    </td>
Z
zengyawen 已提交
57
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p1888021103111"><a name="p1888021103111"></a><a name="p1888021103111"></a>否</p>
Z
zengyawen 已提交
58
    </td>
Z
zengyawen 已提交
59
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p199051053209"><a name="p199051053209"></a><a name="p199051053209"></a>本地化显示文本是否要首字母大写</p>
Z
zengyawen 已提交
60 61 62 63 64 65 66
    </td>
    </tr>
    </tbody>
    </table>

-   返回值:

Z
zengyawen 已提交
67 68
    <a name="table0483117706"></a>
    <table><thead align="left"><tr id="row6483417306"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="p7483617903"><a name="p7483617903"></a><a name="p7483617903"></a>类型</p>
Z
zengyawen 已提交
69
    </th>
Z
zengyawen 已提交
70
    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="p14835171705"><a name="p14835171705"></a><a name="p14835171705"></a>说明</p>
Z
zengyawen 已提交
71 72 73
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
74
    <tbody><tr id="row8483111717020"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="p1248320178013"><a name="p1248320178013"></a><a name="p1248320178013"></a>string</p>
Z
zengyawen 已提交
75
    </td>
Z
zengyawen 已提交
76
    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="p24836172000"><a name="p24836172000"></a><a name="p24836172000"></a><span>指定语言的本地化显示文本</span></p>
Z
zengyawen 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89
    </td>
    </tr>
    </tbody>
    </table>

-   示例:

    ```
    i18n.getDisplayLanguage("zh", "en-GB", true);
    i18n.getDisplayLanguage("zh", "en-GB");
    ```


Z
zengyawen 已提交
90
## i18n.getDisplayCountry<a name="section156643561735"></a>
Z
zengyawen 已提交
91 92 93 94 95 96 97

getDisplayCountry\(country: string, locale: string, sentenceCase?: boolean\): string

获取指定国家的本地化显示文本。

-   参数:

Z
zengyawen 已提交
98 99
    <a name="table566415619320"></a>
    <table><thead align="left"><tr id="row86656561632"><th class="cellrowborder" valign="top" width="14.92%" id="mcps1.1.5.1.1"><p id="p366595612316"><a name="p366595612316"></a><a name="p366595612316"></a>参数名</p>
Z
zengyawen 已提交
100
    </th>
Z
zengyawen 已提交
101
    <th class="cellrowborder" valign="top" width="11.5%" id="mcps1.1.5.1.2"><p id="p766513561836"><a name="p766513561836"></a><a name="p766513561836"></a>类型</p>
Z
zengyawen 已提交
102
    </th>
Z
zengyawen 已提交
103
    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p id="p5380185513302"><a name="p5380185513302"></a><a name="p5380185513302"></a>必填</p>
Z
zengyawen 已提交
104
    </th>
Z
zengyawen 已提交
105
    <th class="cellrowborder" valign="top" width="66.06%" id="mcps1.1.5.1.4"><p id="p466585612312"><a name="p466585612312"></a><a name="p466585612312"></a>说明</p>
Z
zengyawen 已提交
106 107 108
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
109
    <tbody><tr id="row196651356536"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p1666515564316"><a name="p1666515564316"></a><a name="p1666515564316"></a>country</p>
Z
zengyawen 已提交
110
    </td>
Z
zengyawen 已提交
111
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p19665135612319"><a name="p19665135612319"></a><a name="p19665135612319"></a>string</p>
Z
zengyawen 已提交
112
    </td>
Z
zengyawen 已提交
113
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p13380155519303"><a name="p13380155519303"></a><a name="p13380155519303"></a>是</p>
Z
zengyawen 已提交
114
    </td>
Z
zengyawen 已提交
115
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p15665205611310"><a name="p15665205611310"></a><a name="p15665205611310"></a><span>指定</span>国家</p>
Z
zengyawen 已提交
116 117
    </td>
    </tr>
Z
zengyawen 已提交
118
    <tr id="row1766595615310"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p16651156431"><a name="p16651156431"></a><a name="p16651156431"></a>locale</p>
Z
zengyawen 已提交
119
    </td>
Z
zengyawen 已提交
120
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p6665656936"><a name="p6665656936"></a><a name="p6665656936"></a>string</p>
Z
zengyawen 已提交
121
    </td>
Z
zengyawen 已提交
122
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p638045563019"><a name="p638045563019"></a><a name="p638045563019"></a>是</p>
Z
zengyawen 已提交
123
    </td>
Z
zengyawen 已提交
124
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p18665456932"><a name="p18665456932"></a><a name="p18665456932"></a>显示指定国家的区域ID</p>
Z
zengyawen 已提交
125 126
    </td>
    </tr>
Z
zengyawen 已提交
127
    <tr id="row186658561436"><td class="cellrowborder" valign="top" width="14.92%" headers="mcps1.1.5.1.1 "><p id="p146650564311"><a name="p146650564311"></a><a name="p146650564311"></a>sentenceCase</p>
Z
zengyawen 已提交
128
    </td>
Z
zengyawen 已提交
129
    <td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.1.5.1.2 "><p id="p466510566311"><a name="p466510566311"></a><a name="p466510566311"></a>boolean</p>
Z
zengyawen 已提交
130
    </td>
Z
zengyawen 已提交
131
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p id="p143800551304"><a name="p143800551304"></a><a name="p143800551304"></a>否</p>
Z
zengyawen 已提交
132
    </td>
Z
zengyawen 已提交
133
    <td class="cellrowborder" valign="top" width="66.06%" headers="mcps1.1.5.1.4 "><p id="p13665145612315"><a name="p13665145612315"></a><a name="p13665145612315"></a>本地化显示文本是否要首字母大写</p>
Z
zengyawen 已提交
134 135 136 137 138 139 140
    </td>
    </tr>
    </tbody>
    </table>

-   返回值:

Z
zengyawen 已提交
141 142
    <a name="table14665145616317"></a>
    <table><thead align="left"><tr id="row46651556932"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="p366535611320"><a name="p366535611320"></a><a name="p366535611320"></a>类型</p>
Z
zengyawen 已提交
143
    </th>
Z
zengyawen 已提交
144
    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="p066512561431"><a name="p066512561431"></a><a name="p066512561431"></a>说明</p>
Z
zengyawen 已提交
145 146 147
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
148
    <tbody><tr id="row4665115614318"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="p1766615561337"><a name="p1766615561337"></a><a name="p1766615561337"></a>string</p>
Z
zengyawen 已提交
149
    </td>
Z
zengyawen 已提交
150
    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="p18666185614320"><a name="p18666185614320"></a><a name="p18666185614320"></a><span>指定国家的本地化显示文本</span></p>
Z
zengyawen 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163
    </td>
    </tr>
    </tbody>
    </table>

-   示例:

    ```
    i18n.getDisplayCountry("zh-CN", "en-GB", true);
    i18n.getDisplayCountry("zh-CN", "en-GB");
    ```


164
## i18n.getSystemLanguage<a name="section25111622174311"></a>
Z
zengyawen 已提交
165 166 167 168 169 170 171

getSystemLanguage\(\): string

获取系统语言。

-   返回值:

Z
zengyawen 已提交
172 173
    <a name="table10512322154313"></a>
    <table><thead align="left"><tr id="row35125225432"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="p251212225435"><a name="p251212225435"></a><a name="p251212225435"></a>类型</p>
Z
zengyawen 已提交
174
    </th>
Z
zengyawen 已提交
175
    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="p10512132211433"><a name="p10512132211433"></a><a name="p10512132211433"></a>说明</p>
Z
zengyawen 已提交
176 177 178
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
179
    <tbody><tr id="row451262234310"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="p155122222439"><a name="p155122222439"></a><a name="p155122222439"></a>string</p>
Z
zengyawen 已提交
180
    </td>
Z
zengyawen 已提交
181
    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="p651218222432"><a name="p651218222432"></a><a name="p651218222432"></a><span>系统语言ID</span></p>
Z
zengyawen 已提交
182 183 184 185 186 187 188 189 190 191 192 193
    </td>
    </tr>
    </tbody>
    </table>

-   示例:

    ```
    i18n.getSystemLanguage();
    ```


Z
zengyawen 已提交
194
## i18n.getSystemRegion<a name="section65121922114312"></a>
Z
zengyawen 已提交
195 196 197 198 199 200 201

getSystemRegion\(\): string

获取系统地区。

-   返回值:

Z
zengyawen 已提交
202 203
    <a name="table145141228431"></a>
    <table><thead align="left"><tr id="row85141522184310"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="p75141722184315"><a name="p75141722184315"></a><a name="p75141722184315"></a>类型</p>
Z
zengyawen 已提交
204
    </th>
Z
zengyawen 已提交
205
    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="p651482224315"><a name="p651482224315"></a><a name="p651482224315"></a>说明</p>
Z
zengyawen 已提交
206 207 208
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
209
    <tbody><tr id="row1051442244317"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="p7514222164318"><a name="p7514222164318"></a><a name="p7514222164318"></a>string</p>
Z
zengyawen 已提交
210
    </td>
Z
zengyawen 已提交
211
    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="p11514522104314"><a name="p11514522104314"></a><a name="p11514522104314"></a>系统地区ID</p>
Z
zengyawen 已提交
212 213 214 215 216 217 218 219 220 221 222 223
    </td>
    </tr>
    </tbody>
    </table>

-   示例:

    ```
    i18n.getSystemRegion();
    ```


Z
zengyawen 已提交
224
## i18n.getSystemLocale<a name="section10514122204316"></a>
Z
zengyawen 已提交
225 226 227 228 229 230 231

getSystemLocale\(\): string

获取系统区域。

-   返回值:

Z
zengyawen 已提交
232 233
    <a name="table11515122294317"></a>
    <table><thead align="left"><tr id="row15515422144313"><th class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.1.3.1.1"><p id="p205151722194316"><a name="p205151722194316"></a><a name="p205151722194316"></a>类型</p>
Z
zengyawen 已提交
234
    </th>
Z
zengyawen 已提交
235
    <th class="cellrowborder" valign="top" width="77.24%" id="mcps1.1.3.1.2"><p id="p12515132211434"><a name="p12515132211434"></a><a name="p12515132211434"></a>说明</p>
Z
zengyawen 已提交
236 237 238
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
239
    <tbody><tr id="row551612214432"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.1.3.1.1 "><p id="p8516142217436"><a name="p8516142217436"></a><a name="p8516142217436"></a>string</p>
Z
zengyawen 已提交
240
    </td>
Z
zengyawen 已提交
241
    <td class="cellrowborder" valign="top" width="77.24%" headers="mcps1.1.3.1.2 "><p id="p45163224436"><a name="p45163224436"></a><a name="p45163224436"></a>系统区域ID</p>
Z
zengyawen 已提交
242 243 244 245 246 247 248 249 250 251 252 253
    </td>
    </tr>
    </tbody>
    </table>

-   示例:

    ```
    i18n.getSystemLocale();
    ```