What is internationalization (I18n)?
- It's painful.
In large projects, creating key names for hundreds of cases manually is a very boring and error-prone task. Unstandardized naming can lead to maintenance difficulties.
Solutions
Automatically converts the script to a standardized Key by smart algorithm. For Chinese, the automatic extraction and formatting of spellings greatly saves development time and ensures consistency of norms.
Best practice in international naming of key names
1. Modular Prefix: use hierarchical naming, e.g. login.button.submithelps organize JSON files and avoid conflicts.
2. Select the appropriate format:
- camelCase: The most common format for modern front-end frameworks (React/Vue).
- snake_case: Commonly at the back end or configuration of some traditional items.
- kebab-case: Fits as CSS class name or HTML attribute.
3. Keep semantic: The key name should describe “what it is” rather than “what it shows”. For example, use auth.error_message Not auth.please_input_password。
How do you use the generated JSON in the project?
Here. react-i18next For example, you can put the generated JSON directly into your language package file:
{
"common": {
"save": "Save",
"cancel": "Cancel"
}
}