adxp-i18n-tool
v1.0.5
Published
This tool reads all files with the specified extensions under the `target_path` and searches for usages of the `getFormatMessage` function. It performs the following actions:
Readme
Features
This tool reads all files with the specified extensions under the target_path and searches for usages of the getFormatMessage function. It performs the following actions:
getFormatMessage(id: string, defaultMessage?: string, params?: object)If
idis empty, a uniqueidwill be generated, and the value specified indefaultMessagewill be registered in all message files.If
idis specified butdefaultMessageis not provided:- It is inconvenient to read code when
defaultMessageis not specified ingetFormatMessage. To alleviate this, if a message corresponding to theidexists in any message file, its value will be inserted as thedefaultMessage. - If there are multiple message files, the last message file listed will be used as the default source for
defaultMessage.
- It is inconvenient to read code when
All message files should contain the same set of
ids. If a specificidexists only in some files, it will be added to the rest as well.
Installation & Usage
Configure your environment with the .env file:
i18n_messages_path=/Users/adxp/dev/ai-platform/frontend/ai-snb/src/app/common/i18n/messages
i18n_messages_files=en.json,ko.json,fr.json
target_path=/Users/adxp/dev/ai-platform/frontend/ai-snb/src
target_extension=tsx,ts⚠️ Important
🛑 Ensure that all source files to be modified are committed beforehand. Since this tool modifies the source code directly, you must run it in a state where you can safely revert changes.
🛑 모든 소스 코드가 commit 된 상태인지를 먼저 확인하십시오. 이 tool 은 소스 코드를 직접 수정하기 때문에, 변경 사항을 revert 할 수 있는 상태에서 실행되어야만 합니다.
When Modifying the Source Code
Run the following commands to update the i18n language files and automatically add any messages that are not yet saved in the language files. If you have modified a default message in the source code, all language files will be overwritten with the new default message. Therefore, you must manually open each language file and update the translations accordingly.
npm install -g adxp-i18n-tool
adxp-i18n-tool exec --env ./.envWhen the i18n Language Files Have Been Modified
If you've modified the i18n language files—for example, to update translations or edit messages—you'll need to synchronize them with the default messages in the source code. If you run the i18n tool without doing so, the language files may be reset to match the defaults. When a key exists in all language files but none of the values match the default message in the source code, the tool assumes that the default message has changed and will overwrite all translations with the new default.
⚠️ To avoid losing your edits, run the tool with the --overwrite-default-message option to explicitly sync the changes.
npm install -g adxp-i18n-tool
adxp-i18n-tool exec --env ./.env --overwrite-default-message