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 // Default directory. 22| |---element 23| | |---string.json 24| |---media 25| | |---icon.png 26| |---profile 27| | |---test_profile.json 28|---en_GB-vertical-car-mdpi // Example of a qualifiers directory, which needs to be created on your own. 29| |---element 30| | |---string.json 31| |---media 32| | |---icon.png 33| |---profile 34| | |---test_profile.json 35|---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. 36|---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. 37``` 38### Resource Directories 39 40#### base Directory 41 42The **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> 43Resource 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. 44 45#### Qualifiers Directory 46 47The qualifiers directory needs to be created as required. The subdirectories **element**, **media**, and **profile** are used to store basic elements such as character strings, colors, and Boolean values, and resource files such as media, animation, and layout.<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. 48 49**Naming Conventions for Qualifiers Directories** 50 51The 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. 52 53- Qualifiers are ordered in the following sequence: MCC_MNC-language_script_country/region-screen orientation-device type-night mode-screen density. You can select one or multiple qualifiers to name your subdirectory based on your application scenarios and device characteristics. 54 55- 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**. 56 57- 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. 58 59Table 2 Requirements for qualifier values 60 61| Qualifier Type | Description and Value Range | 62| ----------- | ---------------------------------------- | 63| 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).| 64| 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).| 65| 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).| 66| 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).| 67| Screen orientation | Indicates the screen orientation of the device. The value can be:<br>- **vertical**: portrait orientation<br>- **horizontal**: landscape orientation| 68| 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--> | 69| Color mode | Indicates the color mode of the device. The value can be:<br>- **dark**: dark mode<br>- **light**: light mode| 70| 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].| 71 72#### rawfile Directory 73 74You 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. 75 76#### resfile Directory 77 78You 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 the application is installed, resources in the **resfile** repository are decompressed to the application sandbox path. After the **resfile** directory is obtained through the **Context** attribute [resourceDir](../reference/apis-ability-kit/js-apis-inner-application-context.md#properties), the resources can be accessed through the file path in read-only mode. 79 80### Resource Group Directories 81 82Resource group directories include **element**, **media**, and **profile**, which are used to store resources of specific types. 83 84 **Table 3** Resource group directories 85 86| Directory | Description | Resource File | 87| --------- | ---------------------------------------- | ---------------------------------------- | 88| 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 | 89| 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**. | 90| 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**. | 91 92**Media Resource Types** 93 94Table 4 Image resource types 95 96| Format | File Name Extension| 97| ---- | ----- | 98| JPEG | .jpg | 99| PNG | .png | 100| GIF | .gif | 101| SVG | .svg | 102| WEBP | .webp | 103| BMP | .bmp | 104 105Table 5 Audio and video resource types 106 107| Format | File Name Extension | 108| ------------------------------------ | --------------- | 109| H.264 AVC |.3gp | 110| Baseline Profile (BP) | .mp4 | 111 112**Resource File Examples** 113 114The content of the **color.json** file is as follows: 115 116The standard hexadecimal color value consists of six hexadecimal digits. The first two digits indicate the opacity, and the last six digits indicate the color value. 117```json 118{ 119 "color": [ 120 { 121 "name": "color_hello", 122 "value": "#ffff0000" 123 }, 124 { 125 "name": "color_world", 126 "value": "#ff0000ff" 127 } 128 ] 129} 130``` 131 132The content of the **float.json** file is as follows: 133 134```json 135{ 136 "float": [ 137 { 138 "name": "font_hello", 139 "value": "28.0fp" 140 }, 141 { 142 "name": "font_world", 143 "value": "20.0fp" 144 } 145 ] 146} 147``` 148 149The content of the **string.json** file is as follows: 150 151```json 152{ 153 "string": [ 154 { 155 "name": "string_hello", 156 "value": "Hello" 157 }, 158 { 159 "name": "string_world", 160 "value": "World" 161 }, 162 { 163 "name": "message_arrive", 164 "value": "We will arrive at %1$s." 165 }, 166 { 167 "name": "message_notification", 168 "value": "Hello, %1$s!,You have %2$d new messages." 169 } 170 ] 171} 172``` 173 174The content of the **plural.json** file is as follows: 175 176```json 177{ 178 "plural": [ 179 { 180 "name": "eat_apple", 181 "value": [ 182 { 183 "quantity": "one", 184 "value": "%d apple" 185 }, 186 { 187 "quantity": "other", 188 "value": "%d apples" 189 } 190 ] 191 } 192 ] 193} 194``` 195 196## Creating a Resource Directory and Resource File 197 198You can create a directory and its files under the **resources** directory based on the naming rules of the qualifiers directory and file types supported by resource group directories. DevEco Studio provides a wizard for you to create resource directories and resource files. 199 200### Creating a Resource Directory and Resource File 201 202Right-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. 203 204In **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 directory by setting **Color Mode** to **Dark** and **Resource type** to **Element**, the system automatically generates a directory named **dark/element**. 205 206  207 208### Creating a Resource Directory 209 210Right-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. 211 212  213 214### Creating a Resource File 215 216Right-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. 217 218  219 220## Using the attr Attribute for Resource Translation 221 222### Function Description 223 224If the string resource referenced by an application needs to support multi-language adaptation, the **attr** attribute can be used to mark the translation scope and status of the string. The **attr** attribute is not involved in resource compilation. 225 226If the **attr** attribute is not configured, a string is translated by default. 227 228**Parameters of attr** 229 230| Name | Type | Description | 231| --------- | ----------------------- | ---- | 232| 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.| 233| priority | string | Translation status of the string.<br>**code**: untranslated<br>**translate**: translated but not verified<br>**LT**: translated and verified<br>**customer**: custom | 234 235### Constraints 236The **attr** attribute applies to the string, strarray, and plural resources in the **base** directory. 237``` 238resources 239|---base 240| |---element 241| | |---string.json 242| | |---strarray.json 243| | |---plural.json 244``` 245### Example 246The following shows the **attr** attribute configured in **string**. The **string1** string is marked as not to be translated, and the **string2** string is marked as to be translated and the translation has been verified. 247 248```json 249{ 250 "string": [ 251 { 252 "name": "string1", 253 "value": "1", 254 "attr": { 255 "translatable": false 256 } 257 }, 258 { 259 "name": "string2", 260 "value": "Hello world!", 261 "attr": { 262 "translatable": true, 263 "priority": "LT" 264 } 265 } 266 ] 267} 268``` 269 270## Resource Access 271 272### HAP Resources 273 274 - Access resources through **$r()** or **$rawfile()**.<br>Resources of the color, float, string, plural, media and profile types are accessed through **$r('app.type.name')**, in which **app** indicates the resource defined in the **resources** directory, **type** indicates the resource type, and **name** indicates the resource name.<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 (/). 275 276 > **NOTE** 277 > 278 > For details about how to use native APIs to access raw files, see [Raw File Development](../napi/rawfile-guidelines.md). 279 280 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: 281 282 ```ts 283 // Access through $r('app.type.name'). 284 Text($r('app.string.string_hello')) 285 .fontColor($r('app.color.color_emphasize')) 286 .fontSize($r('app.float.text_size_headline1')) 287 .fontFamily($r('app.string.font_family_medium')) 288 .backgroundColor($r('app.color.color_palette_aux1')) 289 290 Image($r('app.media.app_icon')) 291 .border({ 292 color: $r('app.color.color_palette_aux1'), 293 radius: $r('app.float.corner_radius_button'), width: 2 294 }) 295 .margin({ 296 top: $r('app.float.elements_margin_horizontal_m'), 297 bottom: $r('app.float.elements_margin_horizontal_l') 298 }) 299 .height(200) 300 .width(300) 301 302 //Access placeholders through $r('app.string.label','aaa','bbb',444). 303 Text($r('app.string.message_notification','LiHua',2)) 304 ``` 305 306- 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. 307 308### Cross-HAP/HSP Resources 309 310<!--Del--> 311#### Cross-Bundle Access (for System Applications Only) 312 313- 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. 314<!--DelEnd--> 315 316#### Inter-Bundle, Cross-Module Access 317 318- 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. 319 320- Access resources through **$r()** or **$rawfile()**. Specifically, perform either of the following: 321 322 1. Add dependencies to the **oh-package.json5** file in the **entry** directory. For example, **"dependencies": {"library":"file":../library}**. 323  324 325 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: 326 327 ```ts 328 Text($r('[hsp].string.test_string')) 329 .fontSize($r('[hsp].float.font_size')) 330 .fontColor($r('[hsp].color.font_color')) 331 Image($rawfile('[hsp].icon.png')) 332 ``` 333 3. Use variables. The following is an example: 334 335 ```ts 336 @Entry 337 @Component 338 struct Index { 339 text: string = '[hsp].string.test_string'; 340 fontSize: string = '[hsp].float.font_size'; 341 fontColor: string = '[hsp].color.font_color'; 342 image: string = '[hsp].media.string'; 343 rawfile: string = '[hsp].icon.png'; 344 345 build() { 346 Row() { 347 Text($r(this.text)) 348 .fontSize($r(this.fontSize)) 349 .fontColor($r(this.fontColor)) 350 351 Image($r(this.image)) 352 353 Image($rawfile(this.rawfile)) 354 } 355 } 356 } 357 ``` 358 > **NOTE** 359 > 360 > 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. 361 362 363### System Resources 364 365You 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). 366 367To 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. 368 369> **NOTE** 370> 371> - The use of system resources is only supported in the declarative development paradigm. 372> 373> - 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. 374> 375> - Currently, when the system font loaded on the UI is displayed (you can view the font in the **system/etc/fontconfig.json** file), the default font is HarmonyOS Sans and follows the standards [Chinese coded character set GB18030-2022](https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=A1931A578FE14957104988029B0833D3). 376 377```ts 378Text('Hello') 379 .fontColor($r('sys.color.ohos_id_color_emphasize')) 380 .fontSize($r('sys.float.ohos_id_text_size_headline1')) 381 .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) 382 .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) 383 384Image($r('sys.media.ohos_app_icon')) 385 .border({ 386 color: $r('sys.color.ohos_id_color_palette_aux1'), 387 radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2 388 }) 389 .margin({ 390 top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), 391 bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l') 392 }) 393 .height(200) 394 .width(300) 395``` 396 397## Resource Matching 398 399When 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. 400 401### Rules for Matching Qualifiers Subdirectories and Device Resources 402 403- 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 404 405- 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**. 406 407- 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. 408 409For more information about how resources are loaded in applications, see the internationalization and localization documents. 410 411### Obtaining Resources for a Specific Configuration 412 413#### Background 414 415You 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. 416 417If this is the case, you can use the following APIs to obtain resources for a specific configuration. 418 419#### Available APIs 420 421| API | Description | 422| ------------------------------------------------------------ | ------------------------------------------------------------ | 423| [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.| 424| [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. | 425| [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. | 426 427#### Example 428 429The 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: 430 431- entry/src/main/resources/zh_CN/element/string.json 432 433```json 434{ 435 "string": [ 436 { 437 "name": "greetings", 438 "value": "你好,世界" 439 } 440 ] 441} 442``` 443 444- entry/src/main/resources/en_US/element/string.json 445 446```json 447{ 448 "string": [ 449 { 450 "name": "greetings", 451 "value": "Hello, world" 452 } 453 ] 454} 455``` 456 457- entry/src/main/resources/de_DE/element/string.json 458 459```json 460{ 461 "string": [ 462 { 463 "name": "greetings", 464 "value": "Hallo, Welt" 465 } 466 ] 467} 468``` 469 470In **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**: 471 472```ts 473@Entry 474@Component 475struct Index { 476 @State englishString: string = "" 477 @State germanString: string = "" 478 479 getString(): string { 480 let resMgr = getContext().resourceManager 481 let resId = $r('app.string.greetings').id 482 483 // Obtain resources that match the current system configuration, including the color mode and resolution, for the current system language. 484 let currentLanguageString = resMgr.getStringSync(resId) 485 486 // Obtain resources that match the current system configuration, including the color mode and resolution, for the English language. 487 let overrideConfig = resMgr.getOverrideConfiguration() 488 overrideConfig.locale = "en_US" // Set the language to English and locale to US. 489 let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) 490 this.englishString = overrideResMgr.getStringSync(resId) 491 492 // Obtain resources that match the current system configuration, including the color mode and resolution, for the German language. 493 overrideConfig.locale = "de_DE" // Set the language to German and locale to DE. 494 overrideResMgr.updateOverrideConfiguration(overrideConfig) // Equivalent to resMgr.updateOverrideConfiguration(overrideConfig). 495 this.germanString = overrideResMgr.getStringSync(resId) 496 497 return currentLanguageString 498 } 499 500 build() { 501 Row() { 502 Column() { 503 Text(this.getString()) 504 .fontSize(50) 505 .fontWeight(FontWeight.Bold) 506 Text(this.englishString) 507 .fontSize(50) 508 .fontWeight(FontWeight.Bold) 509 Text(this.germanString) 510 .fontSize(50) 511 .fontWeight(FontWeight.Bold) 512 } 513 .width('100%') 514 } 515 .height('100%') 516 } 517} 518``` 519 520### Overlay Mechanism 521 522Overlay 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. 523 524- Using overlay in dynamic mode 525 5261. 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/**. 527 5282. 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**. 529 530- Using overlay in static mode 531 532The **app.json5** file in the inter-application overlay resource package supports the following fields: 533```{ 534 "app":{ 535 "bundleName": "com.example.myapplication.overlay", 536 "vendor" : "example", 537 "versionCode": "1000000", 538 "versionName": "1.0.0.1", 539 "icon": "$media:app_icon", 540 "label": "$string:app_name", 541 } 542} 543``` 544The **module.json5** file in the inter-application overlay resource package supports the following fields: 545```{ 546 "module":{ 547 "name": "entry_overlay_module_name", 548 "type": "shared", 549 "description": "$string:entry_overlay_desc", 550 "deviceTypes": [ 551 "default", 552 "tablet", 553 ], 554 "deliverywithInstall": true, 555 556 "targetModuleName": "entry_module_name", 557 "targetPriority": 1, 558 } 559} 560``` 561<!--Del--> 562The **app.json5** file in the cross-application overlay resource package supports the following fields, which are available for system applications only: 563```{ 564 "app":{ 565 "bundleName": "com.example.myapplication.overlay", 566 "vendor" : "example", 567 "versionCode": "1000000", 568 "versionName": "1.0.0.1", 569 "icon": "$media:app_icon", 570 "label": "$string:app_name", 571 "targetBundleName": "com.example.myapplication", 572 "targetPriority": 1, 573 } 574} 575``` 576The **module.json5** file in the cross-application overlay resource package supports the following fields, which are available for system applications only: 577```{ 578 "module":{ 579 "name": "entry_overlay_module_name", 580 "type": "shared", 581 "description": "$string:entry_overlay_desc", 582 "deviceTypes": [ 583 "default", 584 "tablet", 585 ], 586 "deliverywithInstall": true, 587 588 "targetModuleName": "entry_module_name", 589 "targetPriority": 1, 590 } 591} 592``` 593<!--DelEnd--> 594> **NOTE** 595> - **targetBundleName**: name of the target application to apply the overlay feature. The value is a string. 596> 597> - **targetModuleName**: name of the target module to apply the overlay feature. The value is a string. 598> 599> - **targetPriority**: overlay priority. The value is an integer. 600> 601> - Other fields such as **Ability**, **ExtensionAbility**, and **Permission** are not supported. 602> 603> - The overlay feature does not support JSON images. 604 605If 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. 606 607The 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). 608 609<!--no_check-->