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.

Unlike obtaining data from external systems or dynamically generating data during running, hard coding refers to directly writing data, parameters, and constants into the program code to implement specific features. Hard-coded 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 from multiple segments. Concatenation makes it difficult to obtain the complete sentence, potentially 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 occur.

image_0000001784263061

Constraints

  1. 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.

  2. 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"
    }