1e41f4b71Sopenharmony_ci# Multi-Language Capability 
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciApplications designed based on the development framework apply to different countries and regions. With the multi-language capability, you do not need to develop application versions in different languages, and your users can switch between various locales. This also facilitates project maintenance.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciYou only need to perform operations in [Defining Resource Files](#defining-resource-files) and [Referencing Resources](#referencing-resources) to use the multi-language capability of this framework. 
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Defining Resource Files
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciResource files store application content in multiple languages. This framework uses JSON files to store resource definitions.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciPlace the resource file of each locale in the **i18n** directory described in [File Organization](js-service-widget-file.md). Resource files are named in *language-region***.json** format. For example, the resource file for English (United States) is named **en-US.json**. If there is no resource file of the locale that matches the system language, content in the **en-US.json** file will be used by default.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ciDifferent languages have different matching rules for singular and plural forms. In the resource file, **zero**, **one**, **two**, **few**, **many**, and **other** are used to define the string content in different singular and plural forms. For example, there is only the **other** scenario in Chinese since the language does not have singular and plural forms. **One** and **other** scenarios are applicable to English. All the preceding six scenarios are needed for Arabic.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci The following example takes **en-US.json** and **ar-AE.json** as examples:
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci```json
21e41f4b71Sopenharmony_ci{
22e41f4b71Sopenharmony_ci    "strings": {
23e41f4b71Sopenharmony_ci        "hello": "Hello world!",
24e41f4b71Sopenharmony_ci        "symbol": "@#$%^&*()_+-={}[]\\|:;\"'<>,./?",
25e41f4b71Sopenharmony_ci        "plurals": {
26e41f4b71Sopenharmony_ci            "one": "one person",
27e41f4b71Sopenharmony_ci            "other": "other people"
28e41f4b71Sopenharmony_ci        }
29e41f4b71Sopenharmony_ci    },
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci    "files": {
32e41f4b71Sopenharmony_ci        "image": "image/en_picture.PNG"
33e41f4b71Sopenharmony_ci    }
34e41f4b71Sopenharmony_ci}
35e41f4b71Sopenharmony_ci```
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci```json
39e41f4b71Sopenharmony_ci{
40e41f4b71Sopenharmony_ci    "strings": {
41e41f4b71Sopenharmony_ci        "plurals": {
42e41f4b71Sopenharmony_ci            "zero": "لا أحد",
43e41f4b71Sopenharmony_ci            "one": "وحده",
44e41f4b71Sopenharmony_ci            "two": "اثنان",
45e41f4b71Sopenharmony_ci            "few": "ستة اشخاص",
46e41f4b71Sopenharmony_ci            "many": "خمسون شخص",
47e41f4b71Sopenharmony_ci            "other": "مائة شخص"
48e41f4b71Sopenharmony_ci        }
49e41f4b71Sopenharmony_ci    }
50e41f4b71Sopenharmony_ci}
51e41f4b71Sopenharmony_ci```
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci## Referencing Resources
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciMulti-language syntax used on application development pages (including simple formatting and singular-plural formatting) can be used in **.hml** or **.js** files.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci- Simple formatting
59e41f4b71Sopenharmony_ci  Use the **$t** function to reference to resources of different locales. The **$t** function is available for both **.hml** and **.js** files. The system displays content based on a resource file path specified via **$t** and the specified resource file whose locale matches the current system language.
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci    **Table 1** Simple formatting
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci  | Name  | Type      | Parameter      | Mandatory  | Description                                    |
64e41f4b71Sopenharmony_ci  | ---- | -------- | -------- | ---- | -------------------------------------- |
65e41f4b71Sopenharmony_ci  | $t   | Function | Described in **$t parameters**| Yes   | Sets the parameters based on the system language, for example, **this.$t('strings.hello')**.|
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci    **Table 2** $t parameters
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci  | Name  | Type    | Mandatory  | Description  |
70e41f4b71Sopenharmony_ci  | ---- | ------ | ---- | ---- |
71e41f4b71Sopenharmony_ci  | path | string | Yes   | Resource path.|
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci- Example code for simple formatting
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci  ```html
76e41f4b71Sopenharmony_ci  <!-- xxx.hml -->
77e41f4b71Sopenharmony_ci   <div> 
78e41f4b71Sopenharmony_ci     <text>{{ $t('strings.hello') }}</text>  
79e41f4b71Sopenharmony_ci     <image src="{{ $t('files.image') }}" class="image"></image> 
80e41f4b71Sopenharmony_ci   </div>
81e41f4b71Sopenharmony_ci  ```
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci- Singular-Plural Conversion
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci  **Table 3** Singular-plural conversion
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci  | Name  | Type      | Parameter       | Mandatory  | Description                                      |
88e41f4b71Sopenharmony_ci  | ---- | -------- | --------- | ---- | ---------------------------------------- |
89e41f4b71Sopenharmony_ci  | $tc  | Function | Described in **$tc parameters**| Yes   | Converts between the singular and plural forms based on the system language, for example, **this.$tc('strings.plurals')**.<br>The resource content is distinguished by the following JSON keys: **zero**, **one**, **two**, **few**, **many**, and **other**.|
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci  **Table 4** $tc parameters
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci  | Parameter   | Type    | Mandatory  | Description   |
94e41f4b71Sopenharmony_ci  | ----- | ------ | ---- | ----- |
95e41f4b71Sopenharmony_ci  | path  | string | Yes   | Resource path. |
96e41f4b71Sopenharmony_ci  | count | number | Yes   | Number|
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci- Example code for converting between the singular and plural forms
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci  ```html
101e41f4b71Sopenharmony_ci  <!--xxx.hml-->
102e41f4b71Sopenharmony_ci  <div>
103e41f4b71Sopenharmony_ci      <!-- When the value 0 is passed, "0 people" matches the Arabic string whose key is zero. -->
104e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 0) }}</text>
105e41f4b71Sopenharmony_ci      <!-- When the value 1 is passed, "1 person" matches the Arabic string whose key is one. -->
106e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 1) }}</text>
107e41f4b71Sopenharmony_ci      <!-- When the value 2 is passed, "2 people" matches the Arabic string whose key is two. -->
108e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 2) }}</text>
109e41f4b71Sopenharmony_ci      <!-- When the value 6 is passed, "6 people" matches the Arabic string whose key is few. -->
110e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 6) }}</text>
111e41f4b71Sopenharmony_ci      <!-- When the value 50 is passed, "50 people" matches the Arabic string whose key is many. -->
112e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 50) }}</text>
113e41f4b71Sopenharmony_ci      <!-- When the value 100 is passed, "100 people" matches the Arabic string whose key is other. -->
114e41f4b71Sopenharmony_ci    <text>{{ $tc('strings.plurals', 100) }}</text>
115e41f4b71Sopenharmony_ci  </div>
116e41f4b71Sopenharmony_ci  ```
117