Read the original article:How to use interpolation in internationalization
Context
While using internalization, users need to customize messages.
Description
Internalization is used to have multilingual applications. During this process, developers may need to customize messages for app users to provide a better experience. For example, instead of saying "Welcome, dear user." they want to say "Welcome, Mr X.".
Given the message in string.json, how can we customize it for users?
{
"name": "welcome",
"value": "Welcome, dear user."
},
Solution / Approach
The resource configuration file string.json supports the configuration of string and number placeholders such as %s and %d. You can define variables in the corresponding page and use Resources and variable splicing in the actual component to achieve the desired effect.
{
"name": "welcome",
"value": "Welcome %s."
},
And use it like this:
Text($r('app.string.welcome', 'Mr X'))
Key Takeaways
- Internalization is used to have multilingual applications.
- string.json supports the configuration of string and number placeholders such as %s and %d.
Top comments (0)