@buaa_smat/hometrans 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -112
- package/agents/build-fixer.md +384 -394
- package/agents/code-reviewer.md +240 -240
- package/agents/logic-coder.md +199 -199
- package/agents/logic-context-builder.md +194 -194
- package/agents/review-fixer.md +405 -405
- package/agents/self-test-fixer.md +296 -296
- package/agents/self-tester.md +393 -392
- package/agents/spec-generator.md +540 -540
- package/dist/cli/config-store.js +84 -8
- package/dist/cli/config.js +3 -3
- package/dist/cli/env-vars.js +129 -0
- package/dist/cli/init.js +272 -272
- package/dist/cli/uninstall.js +152 -17
- package/dist/context/index.js +10 -197
- package/env-requirements.json +3 -3
- package/package.json +1 -1
- package/resource/choose_editor.png +0 -0
- package/resource/common_config.png +0 -0
- package/resource/integration_test_config.png +0 -0
- package/resource/set_env.png +0 -0
- package/resource/ui_align_config.png +0 -0
- package/skills/hmos-batch-ui-align/SKILL.md +108 -98
- package/skills/hmos-batch-ui-align/references/conversion-procedure.md +180 -180
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-batch-ui-align/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-batch-ui-align/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-batch-ui-align/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
- package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-convert-pipeline/SKILL.md +429 -415
- package/skills/hmos-fix-build-errors/SKILL.md +272 -273
- package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
- package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
- package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
- package/skills/hmos-incremental-ui-align/SKILL.md +219 -200
- package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
- package/skills/hmos-incremental-ui-align/page_align.md +62 -62
- package/skills/hmos-incremental-ui-align/readme.md +237 -230
- package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +2 -2
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -911
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +3 -3
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +37 -37
- package/skills/hmos-integration-test/SKILL.md +380 -369
- package/skills/hmos-integration-test/readme.md +309 -309
- package/skills/hmos-resources-convert/SKILL.md +623 -623
- package/skills/hmos-resources-convert/references/conversion-rules.md +663 -663
- package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +388 -388
- package/skills/hmos-resources-convert/references/resource-mapping-rules.md +457 -457
- package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +513 -513
- package/skills/hmos-spec-generate/SKILL.md +331 -331
- package/skills/hmos-spec-generate/references/android-platform-tokens.md +105 -105
- package/skills/hmos-spec-generate/references/spec-sample-1.md +78 -78
- package/skills/hmos-spec-generate/references/spec-sample-2.md +58 -58
- package/skills/hmos-spec-generate/references/spec-sample-3.md +116 -116
- package/skills/hmos-spec-generate/references/step4-report-template.md +33 -33
- package/tools/test-tools/autotest/README.md +33 -17
- package/tools/test-tools/autotest/self_test_runner.py +109 -15
- package/resource/hometrans_config.png +0 -0
- package/skills/hmos-incremental-ui-align/config-example.json +0 -11
- package/tools/test-tools/autotest/config.yaml.example +0 -58
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
# Environment:设备环境查询
|
|
2
|
-
|
|
3
|
-
如果开发者需要获取应用程序运行设备的环境参数(如多语言、深浅色模式等)以进行不同的场景判断,可以使用Environment设备环境查询。
|
|
4
|
-
|
|
5
|
-
Environment是ArkUI框架在应用程序启动时创建的单例对象,为[AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage)提供应用程序运行状态的属性。所有属性都是不可变的简单类型。
|
|
6
|
-
|
|
7
|
-
Environment提供了读取系统环境变量并将其值写入AppStorage的功能。开发者需要通过AppStorage获取环境变量的值。详细信息请参阅 [Environment 内置参数](#environment内置参数)。
|
|
8
|
-
|
|
9
|
-
在阅读本文档前,建议提前阅读:[AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage)。
|
|
10
|
-
|
|
11
|
-
## Environment内置参数
|
|
12
|
-
|
|
13
|
-
| 键 | 数据类型 | 描述 |
|
|
14
|
-
| --- | --- | --- |
|
|
15
|
-
| accessibilityEnabled | string | 是否启用获取无障碍屏幕阅读。'true'表示启用,'false'表示不启用。 |
|
|
16
|
-
| colorMode | [ColorMode](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management-environment-variables#colormode) | 色彩模型类型。- ColorMode.LIGHT:浅色。- ColorMode.DARK:深色。 |
|
|
17
|
-
| fontScale | number | 字体大小比例。开发者需要配置configuration,设置fontSizeScale为"followSystem",具体配置步骤可参考[configuration](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/app-configuration-file#configuration标签)使fontScale跟随系统变化。默认值跟随系统默认参数。 |
|
|
18
|
-
| fontWeightScale | number | 字体粗细程度。在不同的系统或者机型中,fontWeightScale的取值范围可能会有所不同。默认值跟随系统默认参数。 |
|
|
19
|
-
| layoutDirection | [LayoutDirection](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management-environment-variables#layoutdirection) | 布局方向类型:- LayoutDirection.LTR:从左到右。- LayoutDirection.RTL:从右到左。 |
|
|
20
|
-
| languageCode | string | 当前系统语言值,取值必须为小写字母(例如:zh)。默认值跟随系统默认参数。 |
|
|
21
|
-
|
|
22
|
-
## 限制条件
|
|
23
|
-
|
|
24
|
-
Environment和[UIContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext)相关联,需要在UIContext明确的时候才可以调用Environment的接口,可以通过在[runScopedTask](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext#runscopedtask)里调用明确上下文。如果不是在UIContext明确的地方调用,将导致无法查询到设备环境数据。
|
|
25
|
-
|
|
26
|
-
```TypeScript
|
|
27
|
-
import { UIAbility } from '@kit.AbilityKit';
|
|
28
|
-
import { window } from '@kit.ArkUI';
|
|
29
|
-
|
|
30
|
-
export default class EntryAbility extends UIAbility {
|
|
31
|
-
onWindowStageCreate(windowStage: window.WindowStage) {
|
|
32
|
-
windowStage.loadContent('pages/Index');
|
|
33
|
-
let window = windowStage.getMainWindow();
|
|
34
|
-
window.then(window => {
|
|
35
|
-
let uiContext = window.getUIContext();
|
|
36
|
-
uiContext.runScopedTask(() => {
|
|
37
|
-
Environment.envProp('languageCode', 'en');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## 使用场景
|
|
45
|
-
|
|
46
|
-
### 从UI中访问Environment参数
|
|
47
|
-
|
|
48
|
-
- 使用Environment.[envProp](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management#envprop10)将设备运行的环境变量存入AppStorage中。
|
|
49
|
-
|
|
50
|
-
```TypeScript
|
|
51
|
-
// 将设备的languageCode存入AppStorage,默认值为en
|
|
52
|
-
Environment.envProp('languageCode', 'en');
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
- 在自定义组件中通过@StorageProp获取languageCode的值。
|
|
56
|
-
|
|
57
|
-
```TypeScript
|
|
58
|
-
@StorageProp('languageCode') lang: string = 'en';
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
设备环境到Component的更新链:Environment --> AppStorage --> Component。
|
|
62
|
-
|
|
63
|
-
> **说明:**
|
|
64
|
-
>
|
|
65
|
-
> 应用无法修改环境变量参数,因此使用@StorageProp获取。这样即使在组件内修改,也不会同步回AppStorage中,影响其他组件处获取环境变量的结果。
|
|
66
|
-
|
|
67
|
-
```TypeScript
|
|
68
|
-
// 将设备languageCode存入AppStorage中
|
|
69
|
-
Environment.envProp('languageCode', 'en');
|
|
70
|
-
|
|
71
|
-
@Entry
|
|
72
|
-
@Component
|
|
73
|
-
struct UiEnvironment {
|
|
74
|
-
@StorageProp('languageCode') languageCode: string = 'en';
|
|
75
|
-
|
|
76
|
-
build() {
|
|
77
|
-
Row() {
|
|
78
|
-
Column() {
|
|
79
|
-
// 输出当前设备的languageCode
|
|
80
|
-
Text(this.languageCode)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 应用逻辑使用Environment
|
|
88
|
-
|
|
89
|
-
```TypeScript
|
|
90
|
-
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
91
|
-
|
|
92
|
-
const DOMAIN = 0x0001;
|
|
93
|
-
const TAG = 'environmentalProject';
|
|
94
|
-
|
|
95
|
-
// 使用Environment.envProp将设备运行languageCode存入AppStorage中
|
|
96
|
-
Environment.envProp('languageCode', 'en');
|
|
97
|
-
// 从AppStorage获取单向绑定的languageCode的变量
|
|
98
|
-
const lang: SubscribedAbstractProperty<string> = AppStorage.prop('languageCode');
|
|
99
|
-
|
|
100
|
-
if (lang.get() === 'zh') {
|
|
101
|
-
// 请将$r('app.string.AppliedLogic_Hello')替换为实际资源文件,在本示例中该资源文件的value值为"你好"
|
|
102
|
-
hilog.info(DOMAIN, TAG, `${$r('app.string.AppliedLogic_Hello')}`);
|
|
103
|
-
} else {
|
|
104
|
-
hilog.info(DOMAIN, TAG, 'Hello!');
|
|
105
|
-
}
|
|
106
|
-
```
|
|
1
|
+
# Environment:设备环境查询
|
|
2
|
+
|
|
3
|
+
如果开发者需要获取应用程序运行设备的环境参数(如多语言、深浅色模式等)以进行不同的场景判断,可以使用Environment设备环境查询。
|
|
4
|
+
|
|
5
|
+
Environment是ArkUI框架在应用程序启动时创建的单例对象,为[AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage)提供应用程序运行状态的属性。所有属性都是不可变的简单类型。
|
|
6
|
+
|
|
7
|
+
Environment提供了读取系统环境变量并将其值写入AppStorage的功能。开发者需要通过AppStorage获取环境变量的值。详细信息请参阅 [Environment 内置参数](#environment内置参数)。
|
|
8
|
+
|
|
9
|
+
在阅读本文档前,建议提前阅读:[AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage)。
|
|
10
|
+
|
|
11
|
+
## Environment内置参数
|
|
12
|
+
|
|
13
|
+
| 键 | 数据类型 | 描述 |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| accessibilityEnabled | string | 是否启用获取无障碍屏幕阅读。'true'表示启用,'false'表示不启用。 |
|
|
16
|
+
| colorMode | [ColorMode](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management-environment-variables#colormode) | 色彩模型类型。- ColorMode.LIGHT:浅色。- ColorMode.DARK:深色。 |
|
|
17
|
+
| fontScale | number | 字体大小比例。开发者需要配置configuration,设置fontSizeScale为"followSystem",具体配置步骤可参考[configuration](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/app-configuration-file#configuration标签)使fontScale跟随系统变化。默认值跟随系统默认参数。 |
|
|
18
|
+
| fontWeightScale | number | 字体粗细程度。在不同的系统或者机型中,fontWeightScale的取值范围可能会有所不同。默认值跟随系统默认参数。 |
|
|
19
|
+
| layoutDirection | [LayoutDirection](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management-environment-variables#layoutdirection) | 布局方向类型:- LayoutDirection.LTR:从左到右。- LayoutDirection.RTL:从右到左。 |
|
|
20
|
+
| languageCode | string | 当前系统语言值,取值必须为小写字母(例如:zh)。默认值跟随系统默认参数。 |
|
|
21
|
+
|
|
22
|
+
## 限制条件
|
|
23
|
+
|
|
24
|
+
Environment和[UIContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext)相关联,需要在UIContext明确的时候才可以调用Environment的接口,可以通过在[runScopedTask](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext#runscopedtask)里调用明确上下文。如果不是在UIContext明确的地方调用,将导致无法查询到设备环境数据。
|
|
25
|
+
|
|
26
|
+
```TypeScript
|
|
27
|
+
import { UIAbility } from '@kit.AbilityKit';
|
|
28
|
+
import { window } from '@kit.ArkUI';
|
|
29
|
+
|
|
30
|
+
export default class EntryAbility extends UIAbility {
|
|
31
|
+
onWindowStageCreate(windowStage: window.WindowStage) {
|
|
32
|
+
windowStage.loadContent('pages/Index');
|
|
33
|
+
let window = windowStage.getMainWindow();
|
|
34
|
+
window.then(window => {
|
|
35
|
+
let uiContext = window.getUIContext();
|
|
36
|
+
uiContext.runScopedTask(() => {
|
|
37
|
+
Environment.envProp('languageCode', 'en');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 使用场景
|
|
45
|
+
|
|
46
|
+
### 从UI中访问Environment参数
|
|
47
|
+
|
|
48
|
+
- 使用Environment.[envProp](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-state-management#envprop10)将设备运行的环境变量存入AppStorage中。
|
|
49
|
+
|
|
50
|
+
```TypeScript
|
|
51
|
+
// 将设备的languageCode存入AppStorage,默认值为en
|
|
52
|
+
Environment.envProp('languageCode', 'en');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- 在自定义组件中通过@StorageProp获取languageCode的值。
|
|
56
|
+
|
|
57
|
+
```TypeScript
|
|
58
|
+
@StorageProp('languageCode') lang: string = 'en';
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
设备环境到Component的更新链:Environment --> AppStorage --> Component。
|
|
62
|
+
|
|
63
|
+
> **说明:**
|
|
64
|
+
>
|
|
65
|
+
> 应用无法修改环境变量参数,因此使用@StorageProp获取。这样即使在组件内修改,也不会同步回AppStorage中,影响其他组件处获取环境变量的结果。
|
|
66
|
+
|
|
67
|
+
```TypeScript
|
|
68
|
+
// 将设备languageCode存入AppStorage中
|
|
69
|
+
Environment.envProp('languageCode', 'en');
|
|
70
|
+
|
|
71
|
+
@Entry
|
|
72
|
+
@Component
|
|
73
|
+
struct UiEnvironment {
|
|
74
|
+
@StorageProp('languageCode') languageCode: string = 'en';
|
|
75
|
+
|
|
76
|
+
build() {
|
|
77
|
+
Row() {
|
|
78
|
+
Column() {
|
|
79
|
+
// 输出当前设备的languageCode
|
|
80
|
+
Text(this.languageCode)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 应用逻辑使用Environment
|
|
88
|
+
|
|
89
|
+
```TypeScript
|
|
90
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
91
|
+
|
|
92
|
+
const DOMAIN = 0x0001;
|
|
93
|
+
const TAG = 'environmentalProject';
|
|
94
|
+
|
|
95
|
+
// 使用Environment.envProp将设备运行languageCode存入AppStorage中
|
|
96
|
+
Environment.envProp('languageCode', 'en');
|
|
97
|
+
// 从AppStorage获取单向绑定的languageCode的变量
|
|
98
|
+
const lang: SubscribedAbstractProperty<string> = AppStorage.prop('languageCode');
|
|
99
|
+
|
|
100
|
+
if (lang.get() === 'zh') {
|
|
101
|
+
// 请将$r('app.string.AppliedLogic_Hello')替换为实际资源文件,在本示例中该资源文件的value值为"你好"
|
|
102
|
+
hilog.info(DOMAIN, TAG, `${$r('app.string.AppliedLogic_Hello')}`);
|
|
103
|
+
} else {
|
|
104
|
+
hilog.info(DOMAIN, TAG, 'Hello!');
|
|
105
|
+
}
|
|
106
|
+
```
|