1e41f4b71Sopenharmony_ci# Multi-Language Capability 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_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. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_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. For details about how to obtain the current system language, see [Obtaining the Language](#obtaining-the-language). 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Defining Resource Files 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciResource files store application content in multiple languages. This framework uses JSON files to store resource definitions. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciPlace the resource definition file of each locale in the **i18n** folder specified in [Directory Structure](js-lite-framework-file.md). Name the resource files in _language-region_.json format. For example, name the resource file for English (United States) **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. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciThe format of the resource file content is as follows: 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_cien-US.json 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci```json 18e41f4b71Sopenharmony_ci{ 19e41f4b71Sopenharmony_ci "strings": { 20e41f4b71Sopenharmony_ci "hello": "Hello world!", 21e41f4b71Sopenharmony_ci "object": "Object parameter substitution-{name}", 22e41f4b71Sopenharmony_ci "array": "Array type parameter substitution-{0}", 23e41f4b71Sopenharmony_ci "symbol": "@#$%^&*()_+-={}[]\\|:;\"'<>,./?" 24e41f4b71Sopenharmony_ci }, 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci "files": { 27e41f4b71Sopenharmony_ci "image": "image/en_picture.PNG" 28e41f4b71Sopenharmony_ci } 29e41f4b71Sopenharmony_ci} 30e41f4b71Sopenharmony_ci``` 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci## Referencing Resources 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_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. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci | Parameter | Type | Mandatory| Description | 37e41f4b71Sopenharmony_ci | ------ | ------------- | ---- | ------------------------------------------------------------ | 38e41f4b71Sopenharmony_ci | path | string | Yes | Resource path. | 39e41f4b71Sopenharmony_ci | params | Array\|Object | No | Content used to replace placeholders during runtime. There are two types of placeholders available:<br>- Named placeholder, for example, {name}. The actual content must be of the object type, for example, **$t('strings.object', { name: 'Hello world' })**.<br>- Digit placeholder, for example, **{0}**. The actual content must be of the array type, for example, **$t('strings.array', ['Hello world']**. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci- Example 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci ```html 44e41f4b71Sopenharmony_ci <!-- xxx.hml --> 45e41f4b71Sopenharmony_ci <div> 46e41f4b71Sopenharmony_ci <!-- Display Hello world! without using a placeholder. --> 47e41f4b71Sopenharmony_ci <text>{{ $t('strings.hello') }}</text> 48e41f4b71Sopenharmony_ci <!-- Replace named placeholder {name} with Hello world and display it. --> 49e41f4b71Sopenharmony_ci <text>{{ $t('strings.object', { name: 'Hello world' }) }}</text> 50e41f4b71Sopenharmony_ci <!-- Replace digit placeholder {0} with Hello world and display it. --> 51e41f4b71Sopenharmony_ci <text>{{ $t('strings.array', ['Hello world']) }}</text> 52e41f4b71Sopenharmony_ci <!-- Obtain the resource content from the .js file and display Hello world. --> 53e41f4b71Sopenharmony_ci <text>{{ hello }}</text> 54e41f4b71Sopenharmony_ci <!-- Obtain the resource content from the .js file, replace named placeholder {name} with Hello world, and display Substitution in an object: Hello world. --> 55e41f4b71Sopenharmony_ci <text>{{ replaceObject }}</text> 56e41f4b71Sopenharmony_ci <!-- Obtain the resource content from the .js file, replace digit placeholder {0} with Hello world, and display Substitution in an array: Hello world. --> 57e41f4b71Sopenharmony_ci <text>{{ replaceArray }}</text> 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci <!-- Display the image in the specified file path. --> 60e41f4b71Sopenharmony_ci <image src="{{ $t('files.image') }}" class="image"></image> 61e41f4b71Sopenharmony_ci <!-- Obtain the image file path from the .js file and display the image. --> 62e41f4b71Sopenharmony_ci <image src="{{ replaceSrc }}" class="image"></image> 63e41f4b71Sopenharmony_ci </div> 64e41f4b71Sopenharmony_ci ``` 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci ```javascript 67e41f4b71Sopenharmony_ci // xxx.js 68e41f4b71Sopenharmony_ci // The following example uses the $t function in the .js file. 69e41f4b71Sopenharmony_ci export default { 70e41f4b71Sopenharmony_ci data: { 71e41f4b71Sopenharmony_ci hello: '', 72e41f4b71Sopenharmony_ci replaceObject: '', 73e41f4b71Sopenharmony_ci replaceArray: '', 74e41f4b71Sopenharmony_ci replaceSrc: '', 75e41f4b71Sopenharmony_ci }, 76e41f4b71Sopenharmony_ci onInit() { 77e41f4b71Sopenharmony_ci this.hello = this.$t('strings.hello'); 78e41f4b71Sopenharmony_ci this.replaceObject = this.$t('strings.object', { name: 'Hello world' }); 79e41f4b71Sopenharmony_ci this.replaceArray = this.$t('strings.array', ['Hello world']); 80e41f4b71Sopenharmony_ci this.replaceSrc = this.$t('files.image'); 81e41f4b71Sopenharmony_ci }, 82e41f4b71Sopenharmony_ci } 83e41f4b71Sopenharmony_ci ``` 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci## Obtaining the Language 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciFor details about how to obtain the language, see [Application Configuration](../js-apis-system-configuration.md). 90