
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
@gooddata/i18n-toolkit
Advanced tools
Localization validator to validate localization complexity and intl and html format.
This package is a part of the GoodData.UI SDK. To learn more, check the source monorepo.
This is a translations validator script that is able to validate rules for valid translations files.
.json files - Toolkit validate structure of json files based on json schema that is defined in src/schema/localization.ts. If file is not valid by this schema, validation immediately failed.Install by npm ...
npm install @gooddata/i18n-toolkit --save-dev
... or by yarn
yarn add @gooddata/i18n-toolkit -D
Toolkit is used from command line and has some options to enabled all checks. By default, all check are disabled and need to be turn on by one by for all cases.
-p, --paths <paths>This option is required and it is more paths for directory where are translations jsons that is split by ",". There can be lots of *.json files, all files are behaving as a localisations files and need to be valid. There need to be file en-US.json that is used as a default file for other validations. Without this path and file, validator can not work.
Example
i18n-toolkit --paths src/share/translations src/Component/translations
-c, --config <path>This option is path for Configuration file that can be used for determine all options and also specified rules for option -u, --usage that turns on localisation usage messages id validation.
-s, --structureTurn on validation of structure base ond json schema.
-i, --intlTurn on validation of ICU messages used in localisation files.
-h, --htmlTurn on validation of HTML marks inside localisation messages.
-u, --usageTurn on localisation message id usage validation. This fill turn on feature that try to find if key is really used in application or not. There are more options related to this see Configuration file.
-m, --commentsTurn on validation of translation comments. This will check that all translation entries have non-empty comment fields to provide context for translators. The validation will fail with a clear error message when comments are missing.
-d, --debugTurn on debug mode that shows more info on errors and spam console more often that in normal mode.
-w, --cwd <path>This option is used to define another working directory that is current. By defaul this tool has working directory as directory where program run, but this option can override this and define another directory as cwd.
package.json
{
...
"scripts": {
...
"validate-locales": "i18n-toolkit --paths app/localization --structure --intl --html"
},
"devDependencies": {
"@gooddata/i18n-toolkit": "^8.10.0-alpha.101",
...
}
}
.i18nrc.jsInstead of command line arguments, this tool also be configured by config file. Configuration file is necessary to use if you want to use --usage otpion to determine if localizations ids are used or not because there are rules for messages. By default, toolkit search for config file .i18nrc.js in cwd, but can be overridden by --config option on command line.
module.exports = {
paths: ["./src/fixtures/", "./src/translations/"],
//settings
structure: true, //OPTIONAL, same as "--structure" option on command line
intl: true, //OPTIONAL, same as "--intl" option on command line
html: true, //OPTIONAL, same as "--html" option on command line
usage: true, //OPTIONAL, same as "--usage" option on command line
comments: true, //OPTIONAL, same as "--comments" option on command line
debug: true, //OPTIONAL, same as "--debug" option on command line
//REQUIRED if usage=true, source files with code from tool reads and parse usage of localisations messages
source: "src/**/*.{ts,js,tsx,jsx}",
//REQUIRED if usage=true, rules definition for validation usage
rules: [
{
//OPTIONAL, define regular expression, this option will be valid only for locales inside dir that match expression
dir: /src\/fixtures/,
//REQUIRED, define pattern for messages id to have been process with this rule, if you want all, use /.+/ pattern, can be array of expressions or single expression
pattern: [/^text\./, /^properly\./],
//OPTIONAL, if set true, locales messages will be filtered by previous regex pattern and other messages will be skipped, more info bellow
filterTranslationFile: false,
//OPTIONAL, all messages for this rule will be ignored (not processed and not marked as missing or unused)
ignore: false,
},
],
};
source: stringThis is setting for usage check and its only required if usage=true. It is pattern for source files with code from tool reads and parse usage of localisations messages. Default value is src/**/*.{ts,js,tsx,jsx} and can be changed to any glob style files path.
rules: Array<ToolkitTranslationRule>List of rules that will be applied on extracted and loaded rules. Tool extract all messages from source files and load localisation files defined in path or paths and then apply these rules on files. Every rule can have some special settings and these properties are described below.
rules[].dir: RegExpDefine regular expression, this option will be valid only for locales inside dir that match expression. If there are more directories with locales (for example src/locales and src/external/locales) you can specify, that this rule can be valid only for locales that is inside directory with matching regex pattern. If dir is omitted, this rule will be applied in every folder.
rules[].pattern: RegExpDefine pattern for messages id to have been process with this rule, if you want all, use /.+/ pattern, can be array of expressions or single expression. If filterTranslationFile is set to false and there will be messages. that not match by pattern Regex, tool automatically mark this messages as invalid.
rules[].filterTranslationFile: booleanIf set true, locales messages will be filtered by previous regex pattern and other messages will be skipped. This is useful if your locales file contains also locales for 3rd party library, and you want to validate only yours validation messages and others will be skipped. In this case you need to define 2 rules tha one validate messages and second mark others as ignored.
rules: [
//all message that starts with dialogs. and screen. will be validated
{
pattern: [/^dialogs\./, /^screen\./],
filterTranslationFile: true,
},
//all messages that starts with share.widget will be ignored
{
pattern: [/^share\.widget\./],
filterTranslationFile: true,
ignore: true,
},
];
rules[].ignore: booleanAll messages for this rule will be ignored (not processed and not marked as missing or unused). Its handy for keys that can be extracted from source code or keys that are used in other apps.
Basic usage and recommended one is used <FormatMessage /> component for react. There is an example how to use this component.
<FormattedMessage
id="message.id"
values={{
count: 0,
name: "Stanley",
}}
/>
In case that we need to get only string, and we are not able to use component, use intl.formatMessage as we can see below.
const text = intl.formatMessage(
{ id: "message.id" },
{
count: 0,
name: "Stanley",
},
);
Do not create message id dynamically. Try to always used full strings without any conditions. With dynamic messages, this is not possible to found usages of localisation string!
It is good practice using defineMessages that is intended to define all messages in current component / file. This allows us to use some dynamic operations with messages.
const messages = defineMessages({
textOne: { id: "message.textOne" },
textTwo: { id: "message.textTwo" },
});
const text = intl.formatMessage(condition ? messages.textOne : messages.textTwo);
(C) 2017-2022 GoodData Corporation
This project is under MIT License. See LICENSE.
FAQs
Localization validator to validate localization complexity and intl and html format.
The npm package @gooddata/i18n-toolkit receives a total of 672 weekly downloads. As such, @gooddata/i18n-toolkit popularity was classified as not popular.
We found that @gooddata/i18n-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 72 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.