harmony 鸿蒙Hard Coding and Concatenation Prevention
Hard Coding and Concatenation Prevention
Use Cases
A key part of localization is the translation of resource files. To improve the translation efficiency, avoid hard coding and concatenation during development.
Different from obtaining data from external systems or generating data during operation, hard coding means to directly embedding data, parameters, and constants into programs to implement specific functions. Hard coding content displayed on the UI, including text in images, audios, and subtitles, is prohibited as this can increase the difficulty and workload in localization. In addition, a complete piece of text on the UI should not be concatenated by multiple segments. Concatenation makes it difficult to obtain the complete sentence, resulting in translation errors or semantic errors. For example, in the following figure, when Rain tomorrow and Bring an umbrella are directly concatenated, a capitalization error will arise.
Constraints
Avoid using hard coding. Extract the strings to be translated into resource files, separate them from the code, and use dedicated APIs for loading. For details, see Multilingual Resource Provisioning.
Do not directly concatenate strings. If variables (for example, Video and Browser in Open Video and Open Browser) are present, use placeholders as the substitute of variables to make the syntax complete. Example of a resource placeholder:
{
"name": "string1",
"value": "Open %s"
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Character Processing
harmony 鸿蒙Overview of Internationalization and Localization
harmony 鸿蒙Language and Locale Name Localization
harmony 鸿蒙Locale ID and Cultural Habit Division
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦