1# Resource Categories and Access 2 3During application development, you may need to use different resources, such as colors, fonts, spacing, and icons, based on the device or configuration. Depending on the resource type, you can achieve this using the following methods: 4 5- Application resources: configure device- or configuration-specific resources in the resource files. 6 7- System resources: Obtain the ID and configuration-specific values of colors, fonts, or other resources in [Resources](https://gitee.com/openharmony/docs/blob/master/en/design/ux-design/design-resources.md); obtain system icons in [HarmonyOS Symbol](https://developer.huawei.com/consumer/cn/design/harmonyos-symbol/). 8 9 10## Resource Categories 11 12Resource files used during application development must be stored in specified directories for management. There are two types of resource directories, namely, resource directories and resource group directories. The resource directories are the **base**, qualifiers, **rawfile**, and **resfile** directories. The resource group directories are the **element**, **media**, and **profile** directories. 13 14> **NOTE** 15> 16> The common resource files used across projects in the stage model are stored in the **resources** directory under **AppScope**. 17 18Example of the **resources** directory: 19``` 20resources 21|---base 22| |---element 23| | |---string.json 24| |---media 25| | |---icon.png 26| |---profile 27| | |---test_profile.json 28|---en_US // Default directory. When the device language is en-us, resources in this directory are preferentially matched. 29| |---element 30| | |---string.json 31| |---media 32| | |---icon.png 33| |---profile 34| | |---test_profile.json 35|---zh_CN // Default directory. When the device language is zh-cn, resources in this directory are preferentially matched. 36| |---element 37| | |---string.json 38| |---media 39| | |---icon.png 40| |---profile 41| | |---test_profile.json 42|---en_GB-vertical-car-mdpi // Example of a qualifiers directory, which needs to be created on your own. 43| |---element 44| | |---string.json 45| |---media 46| | |---icon.png 47| |---profile 48| | |---test_profile.json 49|---rawfile // Other types of files are saved as raw files and will not be integrated into the resources.index file. You can customize the file name as needed. 50|---resfile // Other types of files are saved as raw files and will not be integrated into the resources.index file. You can customize the file name as needed. 51``` 52### Resource Directories 53 54#### base Directory 55 56The **base** directory is provided by default. Under this directory, the **element** subdirectory stores basic elements such as strings, colors, and boolean values, and the **media** and **profile** subdirectories store resource files such as media, animations, and layouts.<br> 57Resource files in the directories are compiled into binary files, and each resource file is assigned an ID. Access resource files in the directories based on the resource type and resource name. 58 59#### Qualifiers Directory 60 61**en_US** and **zh_CN** are two default qualifiers directories. You need to create other qualifiers directories on your own. Under this directory, the **element**, **media**, and **profile** subdirectories store basic elements such as strings, colors, and Boolean values, as well as resource files such as media, animations, and layouts.<br>Resource files in the directories are compiled into binary files, and each resource file is assigned an ID. Access resource files in the directories based on the resource type and resource name. 62 63**Naming Conventions for Qualifiers Directories** 64 65The name of a qualifiers directory consists of one or more qualifiers that represent the application scenarios or device characteristics, covering the mobile country code (MCC), mobile network code (MNC), language, script, country or region, screen orientation, device type, night mode, and screen density. The qualifiers are separated using underscores (\_) or hyphens (\-). Before creating a qualifiers directory, familiarize yourself with the directory naming conventions. 66 67- Qualifiers are ordered in the following sequence: **\_MCC_MNC-language_script_country/region-orientation-device-color mode-density_**. You can select one or multiple qualifiers to name your subdirectory based on your application scenarios and device characteristics. 68 69- Separation between qualifiers: The language, script, and country/region qualifiers are separated using underscores (\_); the MNC and MCC qualifiers are also separated using underscores (\_); other qualifiers are separated using hyphens (\-). For example, **zh_Hant_CN** and **zh_CN-car-ldpi**. 70 71- Value range of qualifiers: The value of each qualifier must meet the requirements specified in the following table. Otherwise, the resource files in the resources directory cannot be matched. 72 73Table 2 Requirements for qualifier values 74 75| Qualifier Type | Description and Value Range | 76| ----------- | ---------------------------------------- | 77| MCC&MNC| Indicates the MCC and MNC, which are obtained from the network where the device is registered.<br>The MCC can be either followed by the MNC with an underscore (_) in between or be used independently. For example, **mcc460** represents China, and **mcc460_mnc00** represents China Mobile.<br>For details about the value range, see [ITU-T E.212](https://www.itu.int/rec/T-REC-E.212) (the international identification plan for public networks and subscriptions).| 78| Language | Indicates the language used by the device. The value consists of two or three lowercase letters. For example, **zh** indicates Chinese, **en** indicates English, and **mai** indicates Maithili.<br>For details about the value range, see [ISO 639](https://www.iso.org/iso-639-language-code) (codes for the representation of names of languages).| 79| Text | Indicates the script type used by the device. The value starts with one uppercase letter followed by three lowercase letters. For example, **Hans** indicates simplified Chinese, and **Hant** indicates traditional Chinese.<br>For details about the value range, see [ISO 15924](https://www.iso.org/standard/81905.html) (codes for the representation of names of scripts).| 80| Country/Region | Indicates the country or region where the user is located. The value consists of two or three uppercase letters or three digits. For example, **CN** indicates China, and **GB** indicates the United Kingdom.<br>For details about the value range, see [ISO 3166-1](https://www.iso.org/iso-3166-country-codes.html) (codes for the representation of names of countries and their subdivisions).| 81| Screen orientation | Indicates the screen orientation of the device. The value can be:<br>- **vertical**: portrait orientation<br>- **horizontal**: landscape orientation| 82| Device type | <!--RP1-->Indicates the device type. The value can be:<br>- **car**: a telematics device<br>- **tablet**: tablet<br>- **tv**: smart TV<br>- **wearable**: smart wearable<!--RP1End--> | 83| Color mode | Indicates the color mode of the device. The value can be:<br>- **dark**: dark mode<br>- **light**: light mode| 84| Screen density | Indicates the screen density of the device, in dpi. The value can be:<br>- **sdpi**: small-scale DPI. This value is applicable to devices with a DPI range of (0, 120].<br>- **mdpi**: medium-scale DPI. This value is applicable to devices with a DPI range of (120, 160].<br>- **ldpi**: large-scale DPI. This value is applicable to devices with a DPI range of (160, 240].<br>- **xldpi**: extra-large-scale DPI. This value is applicable to devices with a DPI range of (240, 320].<br>- **xxldpi**: extra-extra-large-scale DPI. This value is applicable to devices with a DPI range of (320, 480].<br>- **xxxldpi**: extra-extra-extra-large-scale DPI. This value is applicable to devices with a DPI range of (480, 640].| 85 86#### rawfile Directory 87 88You can create multiple levels of subdirectories with custom names to store various resource files.<br>Resource files in the subdirectories are directly packed into the application without being compiled, and no IDs will be assigned to the resource files. Access the directories based on the specified file path and file name. 89 90#### resfile Directory 91 92You can create multiple levels of subdirectories with custom names to store various resource files.<br>Resource files in the subdirectories are directly packed into the application without being compiled, and no IDs will be assigned to the resource files. After an application is installed, the **resfile** directory is decompressed to the application sandbox path. You can obtain the path through the [resourceDir](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-ability-kit/js-apis-inner-application-context.md#properties) attribute of **Context**. 93 94### Resource Group Directories 95 96Resource group directories include **element**, **media**, and **profile**, which are used to store resources of specific types. 97 98 **Table 3** Resource group directories 99 100| Directory | Description | Resource File | 101| --------- | ---------------------------------------- | ---------------------------------------- | 102| element | Element resources. Each type of data is represented by a JSON file. (Only files are supported in this directory.) The options are as follows:<br>- **boolean**: boolean data<br>- **color**: color data<br>- **float**: floating point number ranging from -2^128 to 2^128<br>- **intarray**: array of integers<br>- **integer**: integer ranging from -2^31 to 2^31-1<!--Del--><br>- **pattern**: style (for system applications only)<!--DelEnd--><br>- **plural**: plural form data<br>- **strarray**: array of strings<br>- **string**: string. [See descriptions for formatting strings.](../reference/apis-localization-kit/js-apis-resource-manager.md#getstringsync10)<!--Del--><br>- **theme**: theme (for system applications only)<!--DelEnd-->| It is recommended that files in the **element** subdirectory be named the same as the following files, each of which can contain only data of the same type:<br>- boolean.json<br>- color.json<br>- float.json<br>- intarray.json<br>- integer.json<!--Del--><br>- pattern.json<!--DelEnd--><br>- plural.json<br>- strarray.json<br>- string.json | 103| media | Indicates media resources, including non-text files such as images, audios, and videos. (Only files are supported in this directory.)<br>Table 4 and Table 5 describe the types of images, audios, and videos. | The file name can be customized, for example, **icon.png**. | 104| profile | Indicates a custom configuration file. You can obtain the file content by using the [getProfileByAbility](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagergetprofilebyability) API. (Only JSON files are supported in this directory.) | The file name can be customized, for example, **test_profile.json**. | 105 106**Media Resource Types** 107 108Table 4 Image resource types 109 110| Format | File Name Extension| 111| ---- | ----- | 112| JPEG | .jpg | 113| PNG | .png | 114| GIF | .gif | 115| SVG | .svg | 116| WEBP | .webp | 117| BMP | .bmp | 118 119Table 5 Audio and video resource types 120 121| Format | File Name Extension | 122| ------------------------------------ | --------------- | 123| H.264 AVC |.3gp | 124| Baseline Profile (BP) | .mp4 | 125 126**Resource File Examples** 127 128The content of the **color.json** file is as follows: 129 130```json 131{ 132 "color": [ 133 { 134 "name": "color_hello", 135 "value": "#ffff0000" 136 }, 137 { 138 "name": "color_world", 139 "value": "#ff0000ff" 140 } 141 ] 142} 143``` 144 145The content of the **float.json** file is as follows: 146 147```json 148{ 149 "float":[ 150 { 151 "name":"font_hello", 152 "value":"28.0fp" 153 }, 154 { 155 "name":"font_world", 156 "value":"20.0fp" 157 } 158 ] 159} 160``` 161 162The content of the **string.json** file is as follows: 163 164```json 165{ 166 "string":[ 167 { 168 "name":"string_hello", 169 "value":"Hello" 170 }, 171 { 172 "name":"string_world", 173 "value":"World" 174 }, 175 { 176 "name":"message_arrive", 177 "value":"We will arrive at %1$s." 178 }, 179 { 180 "name":"message_notification", 181 "value":"Hello, %1$s!,You have %2$d new messages." 182 } 183 ] 184} 185``` 186 187The content of the **plural.json** file is as follows: 188 189```json 190{ 191 "plural":[ 192 { 193 "name":"eat_apple", 194 "value":[ 195 { 196 "quantity":"one", 197 "value":"%d apple" 198 }, 199 { 200 "quantity":"other", 201 "value":"%d apples" 202 } 203 ] 204 } 205 ] 206} 207``` 208 209## Creating a Resource Directory and Resource File 210 211You can create a directory and its files under the **resources** directory based on the preceding descriptions of the qualifiers directories and resource group directories. DevEco Studio provides a wizard for you to create resource directories and resource files. 212 213### Creating a Resource Directory and Resource File 214 215Right-click the **resources** directory and choose **New** > **Resource File**. If no qualifier is selected, the file is created in a resource group directory under **base**. If one or more qualifiers are selected, the system automatically generates a subdirectory and creates the file in this subdirectory. 216 217In **File name**, enter the name of the resource file to create. In **Resource type**, select the type of the resource group, which is **element** by default. In **Root Element**, select a resource type. To select a qualifier, highlight it under **Available qualifiers** and click the right arrow. To deselect a qualifier, highlight it under **Selected qualifiers** and click the left arrow.<br>The created directory is automatically named in the format of *Qualifiers.Resource group type*. For example, if you create a subdirectory by setting **Color Mode** to **Dark** and **Resource type** to **Element**, the system automatically generates a subdirectory named **dark.element**. 218 219  220 221### Creating a Resource Directory 222 223Right-click the **resources** directory and choose **New** > **Resource Directory** to create a directory only. By default, the **base** directory is created. You can create qualifiers directories as required, by specifying the qualifier and resource group type, including element, media, and profile. 224 225  226 227### Creating a Resource File 228 229Right-click a directory under **resources** and choose **New** > **XXX Resource File**. This operation creates a resource file under this directory. For example, you can create an element resource file in the **element** subdirectory. 230 231  232 233## Using the attr Attribute for Resource Translation 234 235### Function Description 236 237You can use the **attr** attribute to specify whether a string should be translated and the translation status. The **attr** attribute is not involved in resource compilation. 238 239If the **attr** attribute is not configured, a string is translated by default. 240``` 241"attr": { 242 "translatable": false|true 243 "priority": "code|translate|LT|customer" 244} 245``` 246**Parameters of attr** 247 248| Name | Type | Description | 249| --------- | ----------------------- | ---- | 250| translatable | boolean | Whether the string needs to be translated.<br> **true**: The string needs to be translated.<br> **false**: The string does not need to be translated. | 251| priority | string | Translation status of the string.<br>**code**: untranslated<br>**translate**: translated but not verified<br>**LT**: translated and verified<br>**customer**: custom | 252 253### Constraints 254The **attr** attribute applies to the string, strarray, and plural resources in the **base** directory. 255``` 256resources 257|---base 258| |---element 259| | |---string.json 260| | |---strarray.json 261| | |---plural.json 262``` 263### Example 264This example sets the **attr** attribute for strings. 265 266```json 267{ 268 "string": [ 269 { 270 "name": "string1", 271 "value": "1", 272 "attr": { 273 "translatable": false 274 } 275 }, 276 { 277 "name": "string2", 278 "value": "Hello world!", 279 "attr": { 280 "translatable": true, 281 "priority": "LT" 282 } 283 } 284 ] 285} 286``` 287 288## Resource Access 289 290### HAP Resources 291 292 - Access resources through **$r()** or **$rawfile()**.<br>To access resources of the color, float, string, plural, media, or profile type, use the "$r('app.type.name')" format, where **app** indicates the resource defined in the **resources** directory, **type** indicates the resource type or resource save path, and **name** indicates the name you assign to the resource.<br>To access strings with multiple placeholders in the **string.json** file, use the "$r('app.string.label','aaa','bbb',444)" format.<br>To access resources in the **rawfile** subdirectory, use the "$rawfile('filename')" format. Wherein **filename** indicates the relative path of a file in the **rawfile** subdirectory, which must contain the file name extension and cannot start with a slash (/). 293 294 > **NOTE** 295 > 296 > For details about how to use native APIs to access raw files, see [Raw File Development](../napi/rawfile-guidelines.md). 297 298 As described in [Resource Group Directories](#resource-group-directories), you can reference .json resource files, including **color.json**, **string.json**, and** plural.json**.<br>The usage is as follows: 299 300 ```ts 301 // Access through $r('app.type.name'). 302 Text($r('app.string.string_hello')) 303 .fontColor($r('app.color.ohos_id_color_emphasize')) 304 .fontSize($r('app.float.ohos_id_text_size_headline1')) 305 .fontFamily($r('app.string.ohos_id_text_font_family_medium')) 306 .backgroundColor($r('app.color.ohos_id_color_palette_aux1')) 307 308 Image($r('app.media.ohos_app_icon')) 309 .border({ 310 color: $r('app.color.ohos_id_color_palette_aux1'), 311 radius: $r('app.float.ohos_id_corner_radius_button'), width: 2 312 }) 313 .margin({ 314 top: $r('app.float.ohos_id_elements_margin_horizontal_m'), 315 bottom: $r('app.float.ohos_id_elements_margin_horizontal_l') 316 }) 317 .height(200) 318 .width(300) 319 320 //Access placeholders through $r('app.string.label','aaa','bbb',444). 321 Text($r('app.string.message_notification','LiHua',2)) 322 ``` 323 324- Obtain a **ResourceManager** object through the application context, and then call [resource management APIs](../reference/apis-localization-kit/js-apis-resource-manager.md) to access different resources.<br>For example, call **getContext().resourceManager.getStringByNameSync('test')** to obtain string resources; call **getContext().resourceManager.getRawFd('rawfilepath')** to obtain the descriptor of the HAP where a raw file is located, and then use the descriptor ({fd, offset, length}) to access the raw file. 325 326### Cross-HAP/HSP Resources 327 328<!--Del--> 329#### Cross-Bundle Access (for System Applications Only) 330 331- Create the context of the HAP/HSP file through [createBundleContext(context, bundleName)](../reference/apis-ability-kit/js-apis-app-ability-application-sys.md#applicationcreatebundlecontext12). After obtaining the **resourceManager** object, call [resource management](../reference/apis-localization-kit/js-apis-resource-manager.md) APIs to access different resources. 332<!--DelEnd--> 333 334#### Inter-Bundle, Cross-Module Access 335 336- Create the context of different modules in an application through [createModuleContext(context, moduleName)](../reference/apis-ability-kit/js-apis-app-ability-application.md#applicationcreatemodulecontext12). After obtaining the **resourceManager** object, call [resource management](../reference/apis-localization-kit/js-apis-resource-manager.md) APIs to access different resources. 337 338- Access resources through **$r()** or **$rawfile()**. Specifically, perform either of the following: 339 340 1. Add dependencies to the **oh-package.json5** file in the **entry** directory. For example, **"dependencies": {"library":"file":../library}**. 341  342 343 2. Use *[hsp].type.name*, where **hsp** indicates the HSP module name, **type** indicates the resource type, and **name** indicates the resource name. The following is an example: 344 345 ```ts 346 Text($r('[hsp].string.test_string')) 347 .fontSize($r('[hsp].float.font_size')) 348 .fontColor($r('[hsp].color.font_color')) 349 Image($rawfile('[hsp].icon.png')) 350 ``` 351 3. Use variables. The following is an example: 352 353 ```ts 354 @Entry 355 @Component 356 struct Index { 357 text: string = '[hsp].string.test_string'; 358 fontSize: string = '[hsp].float.font_size'; 359 fontColor: string = '[hsp].color.font_color'; 360 image: string = '[hsp].media.string'; 361 rawfile: string = '[hsp].icon.png'; 362 363 build() { 364 Row() { 365 Text($r(this.text)) 366 .fontSize($r(this.fontSize)) 367 .fontColor($r(this.fontColor)) 368 369 Image($r(this.image)) 370 371 Image($rawfile(this.rawfile)) 372 } 373 } 374 } 375 ``` 376 > **NOTE** 377 > 378 > The HSP module name must be placed in the brackets ([]). If the **rawfile** directory contains multiple levels of folders, the path must start from the first level, for example, **$rawfile('[hsp].oneFile/twoFile/icon.png')**. When **$r** or **$rawfile** is used for cross-HSP resource access, resource verification is not available at compile time, and you need to manually check that the target resources exist in the corresponding location. 379 380 381### System Resources 382 383You can obtain the ID and configuration-specific values of colors, fonts, or other resources in [Resources](https://gitee.com/openharmony/docs/blob/master/en/design/ux-design/design-resources.md), obtain system icons in [HarmonyOS Symbol](https://developer.huawei.com/consumer/cn/design/harmonyos-symbol/), and further set the icon colors through [SymbolGlyph](../reference/apis-arkui/arkui-ts/ts-basic-components-symbolGlyph.md). 384 385To access system resources, use the "$r('sys.type.resource_name')" format, where **sys** indicates the system resource, **type** indicates the resource type, such as color, float, string, media, or symbol, and **resource_name** indicates the resource name. 386 387> **NOTE** 388> 389> - The use of system resources is only supported in the declarative development paradigm. 390> 391> - For preset applications, you are advised to use system resources. For third-party applications, you can choose to use system resources or custom application resources as required. 392> 393> - You can view the fonts for the system resources in the **system/etc/fontconfig.json** file. The default font is **'HarmonyOS Sans'**. 394 395```ts 396Text('Hello') 397 .fontColor($r('sys.color.ohos_id_color_emphasize')) 398 .fontSize($r('sys.float.ohos_id_text_size_headline1')) 399 .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) 400 .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) 401 402Image($r('sys.media.ohos_app_icon')) 403 .border({ 404 color: $r('sys.color.ohos_id_color_palette_aux1'), 405 radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2 406 }) 407 .margin({ 408 top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), 409 bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l') 410 }) 411 .height(200) 412 .width(300) 413``` 414 415## Resource Matching 416 417When your application needs to use a resource, the system preferentially searches the qualifiers subdirectories that match the current device state. The system searches the **base** subdirectory for the target resource only when the **resources** directory does not contain any qualifiers subdirectories that match the current device state or the target resource is not found in the qualifiers subdirectories. The **rawfile** directory is not searched for resources. 418 419### Rules for Matching Qualifiers Subdirectories and Device Resources 420 421- Qualifiers are matched with the device resources in the following priorities: MCC&MNC > locale (options: language, language_script, language_country/region, and language_script_country/region) > screen orientation > device type > color mode > screen density 422 423- If the qualifiers subdirectories contain the MCC, MNC, language, script, screen orientation, device type, and color mode qualifiers, their values must be consistent with the current device status so that the subdirectories can be used for matching the device resources. For example, the qualifiers subdirectory **zh_CN-car-ldpi** cannot be used for matching the resource files labeled **en_US**. 424 425- If there are multiple qualifiers subdirectories for the screen density, the closest qualifiers are matched upwards; otherwise, downwards. For example, if qualifiers directories **xldpi** and **xxldpi** exist and the device screen density is **xxldpi**, the qualifier directory **xxldpi** will be matched. 426 427For more information about how resources are loaded in applications, see the internationalization and localization documents. 428 429### Obtaining Resources for a Specific Configuration 430 431#### Background 432 433You can add qualifiers to the project-level **resources** directory to meet different system settings such as multi-language support and dark and light color modes. you may find some resources fail to be obtained due to matching rules of the qualifiers directories. 434 435If this is the case, you can use the following APIs to obtain resources for a specific configuration. 436 437#### Available APIs 438 439| API | Description | 440| ------------------------------------------------------------ | ------------------------------------------------------------ | 441| [getOverrideResourceManager](../reference/apis-localization-kit/js-apis-resource-manager.md#getoverrideresourcemanager12)(configuration?: [Configuration](../reference/apis-localization-kit/js-apis-resource-manager.md#configuration)) : [ResourceManager](../reference/apis-localization-kit/js-apis-resource-manager.md#resourcemanager) | Obtains a **ResourceManager** object for loading resources for a specific configuration. This API returns the result synchronously.| 442| [getOverrideConfiguration](../reference/apis-localization-kit/js-apis-resource-manager.md#getoverrideconfiguration12)() : [Configuration](../reference/apis-localization-kit/js-apis-resource-manager.md#configuration) | Obtains the specified configuration. This API returns the result synchronously. | 443| [updateOverrideConfiguration](../reference/apis-localization-kit/js-apis-resource-manager.md#updateoverrideconfiguration12)(configuration: [Configuration](../reference/apis-localization-kit/js-apis-resource-manager.md#configuration)) : void | Updates the specified configuration. | 444 445#### Example 446 447The following example demonstrates how to obtain the resources for languages other than the one in use. Assume that the following resource files with the same name are defined in the **resources** directories for Chinese, English, and German: 448 449- entry/src/main/resources/zh_CN/element/string.json 450 451```json 452{ 453 "string": [ 454 { 455 "name": "greetings", 456 "value": "你好,世界" 457 } 458 ] 459} 460``` 461 462- entry/src/main/resources/en_US/element/string.json 463 464```json 465{ 466 "string": [ 467 { 468 "name": "greetings", 469 "value": "Hello, world" 470 } 471 ] 472} 473``` 474 475- entry/src/main/resources/de_DE/element/string.json 476 477```json 478{ 479 "string": [ 480 { 481 "name": "greetings", 482 "value": "Hallo, Welt" 483 } 484 ] 485} 486``` 487 488In **Index.ets**, add code to obtain the resources of the three languages and display them in the text box. The current system language is Chinese. The following is sample code in **entry/src/main/ets/pages/Index.ets**: 489 490```ts 491@Entry 492@Component 493struct Index { 494 @State englishString: string = "" 495 @State germanString: string = "" 496 497 getString(): string { 498 let resMgr = getContext().resourceManager 499 let resId = $r('app.string.greetings').id 500 501 // Obtain resources that match the current system configuration, including the color mode and resolution, for the current system language. 502 let currentLanguageString = resMgr.getStringSync(resId) 503 504 // Obtain resources that match the current system configuration, including the color mode and resolution, for the English language. 505 let overrideConfig = resMgr.getOverrideConfiguration() 506 overrideConfig.locale = "en_US" // Set the language to English and locale to US. 507 let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) 508 this.englishString = overrideResMgr.getStringSync(resId) 509 510 // Obtain resources that match the current system configuration, including the color mode and resolution, for the German language. 511 overrideConfig.locale = "de_DE" // Set the language to German and locale to DE. 512 overrideResMgr.updateOverrideConfiguration(overrideConfig) // Equivalent to resMgr.updateOverrideConfiguration(overrideConfig). 513 this.germanString = overrideResMgr.getStringSync(resId) 514 515 return currentLanguageString 516 } 517 518 build() { 519 Row() { 520 Column() { 521 Text(this.getString()) 522 .fontSize(50) 523 .fontWeight(FontWeight.Bold) 524 Text(this.englishString) 525 .fontSize(50) 526 .fontWeight(FontWeight.Bold) 527 Text(this.germanString) 528 .fontSize(50) 529 .fontWeight(FontWeight.Bold) 530 } 531 .width('100%') 532 } 533 .height('100%') 534 } 535} 536``` 537 538### Overlay Mechanism 539 540Overlay is a resource replacement mechanism. With overlay resource packages, you can enable your application UI to adapt to different styles of various brands and products, without having to repack your application HAPs. The overlay mechanism works in dynamic and static modes. Overlay resource packages contain only resource files, resource index files, and configuration files. 541 542- Using overlay in dynamic mode 543 5441. Place the overlay resource package in the target application installation path and install the package using **hdc install**. For example, for the com.example.overlay application, place the overlay resource package in **data/app/el1/bundle/public/com.example.overlay/**. 545 5462. The application uses [addResource(path)](../reference/apis-localization-kit/js-apis-resource-manager.md#addresource10) to load overlay resources and uses [removeResource(path)](../reference/apis-localization-kit/js-apis-resource-manager.md#removeresource10) to remove overlay resources. The path to an overlay resource consists of the application's sandbox root directory (obtained through **getContext().bundleCodeDir**) and the overlay resource bundle name. For example, **let path = getContext().bundleCodeDir + "Overlay resource bundle name"**, such as **/data/storage/el1/bundle/overlayResourcePackageName**. 547 548- Using overlay in static mode 549 550The **app.json5** file in the inter-application overlay resource package supports the following fields: 551```{ 552 "app":{ 553 "bundleName": "com.example.myapplication.overlay", 554 "vendor" : "example", 555 "versionCode": "1000000", 556 "versionName": "1.0.0.1", 557 "icon": "$media:app_icon", 558 "label": "$string:app_name", 559 } 560} 561``` 562The **module.json5** file in the inter-application overlay resource package supports the following fields: 563```{ 564 "module":{ 565 "name": "entry_overlay_module_name", 566 "type": "shared", 567 "description": "$string:entry_overlay_desc", 568 "deviceTypes": [ 569 "default", 570 "tablet", 571 ], 572 "deliverywithInstall": true, 573 574 "targetModuleName": "entry_module_name", 575 "targetPriority": 1, 576 } 577} 578``` 579The **app.json5** file in the cross-application overlay resource package supports the following fields, which are available for system applications only: 580```{ 581 "app":{ 582 "bundleName": "com.example.myapplication.overlay", 583 "vendor" : "example", 584 "versionCode": "1000000", 585 "versionName": "1.0.0.1", 586 "icon": "$media:app_icon", 587 "label": "$string:app_name", 588 "targetBundleName": "com.example.myapplication", 589 "targetPariority": 1, 590 } 591} 592``` 593The **module.json5** file in the cross-application overlay resource package supports the following fields, which are available for system applications only: 594```{ 595 "module":{ 596 "name": "entry_overlay_module_name", 597 "type": "shared", 598 "description": "$string:entry_overlay_desc", 599 "deviceTypes": [ 600 "default", 601 "tablet", 602 ], 603 "deliverywithInstall": true, 604 605 "targetModuleName": "entry_module_name", 606 "targetPriority": 1, 607 } 608} 609``` 610> **NOTE** 611> - **targetBundleName**: name of the target application to apply the overlay feature. The value is a string. 612> 613> - **targetModuleName**: name of the target module to apply the overlay feature. The value is a string. 614> 615> - **targetPriority**: overlay priority. The value is an integer. 616> 617> - Other fields such as **Ability**, **ExtensionAbility**, and **Permission** are not supported. 618> 619> - The overlay feature does not support JSON images. 620 621If the **module.json5** file of a module contains the **targetModuleName** and **targetPriority** fields during project creation on DevEco Studio, the module is identified as a module with the overlay feature in the installation phase. Modules with the overlay feature generally provide an overlay resource file for other modules on the device, so that the module specified by **targetModuleName** can display different colors, labels, themes, and the like by using the overlay resource file in a running phase. 622 623The overlay feature is enabled by default. For details about how to enable and disable this feature, see [@ohos.bundle.overlay (overlay)](../reference/apis-ability-kit/js-apis-overlay.md). 624 625<!--no_check-->