Gathering detailed insights and metrics for react-intl-translations-manager
Gathering detailed insights and metrics for react-intl-translations-manager
Gathering detailed insights and metrics for react-intl-translations-manager
Gathering detailed insights and metrics for react-intl-translations-manager
react-intl-translations-manager-bc
Manage all translations based on the extracted messages of the babel-plugin-react-intl
exact-translations-manager
CUSTOM EXTENSION OF react-intl-translations-manager. Manage all translations based on the extracted messages of the babel-plugin-react-intl
react-intl-manager-exact
CUSTOM EXTENSION OF react-intl-translations-manager. Manage all translations based on the extracted messages of the babel-plugin-react-intl
react-intl-manager
Manage all translations based on the extracted messages of the babel-plugin-react-intl
Manage all translations based on the extracted messages of the babel-plugin-react-intl
npm install react-intl-translations-manager
Typescript
Module System
Node Version
NPM Version
89.8
Supply Chain
98.7
Quality
74.2
Maintenance
100
Vulnerability
98.1
License
JavaScript (98.16%)
HTML (1.84%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
297 Stars
122 Commits
40 Forks
5 Watching
257 Branches
6 Contributors
Minified
Minified + Gzipped
Latest Version
5.0.3
Package Id
react-intl-translations-manager@5.0.3
Unpacked Size
354.79 kB
Size
94.44 kB
File Count
44
NPM Version
5.8.0
Node Version
8.11.0
Cumulative downloads
Total Downloads
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
React-intl-translations-manager will help you in managing your translations. Hereby it will give you the current status of your translation, telling you what duplicate keys you have, what messages aren't translated yet, what messages were added/deleted since the last time you checked.
You'll still need to update the translations manually in your json files, but now you know what messages you still need to update.
yarn add --dev react-intl-translations-manager
or
npm i --save-dev react-intl-translations-manager
This is an example of the most basic usage of this plugin, in the API documentation below you can find more options.
Create a script in your package.json
1{ 2 "scripts": { 3 "manage:translations": "node ./translationRunner.js" 4 } 5}
Create a file with your config you can run with the npm script
1// translationRunner.js
2const manageTranslations = require('react-intl-translations-manager').default;
3
4// es2015 import
5// import manageTranslations from 'react-intl-translations-manager';
6
7manageTranslations({
8 messagesDirectory: 'src/translations/extractedMessages',
9 translationsDirectory: 'src/translations/locales/',
10 languages: ['nl'] // any language you need
11});
Run the translation manager with your new npm script
npm run manage:translations
Now you can check the status of your translations by just running the script. Then you can change the missing translations in the translation files.
If you encounter messages that are identical in translation in a certain language as in your default language (example: Dashboard (english) = Dashboard (dutch)), then you can whitelist the translation-key in the language specific whitelist file. This will prevent the message from showing up as untranslated when checking the translations status.
This will maintain all translation files. Based on your config you will get output for duplicate ids, and per specified language you will get the deleted translations, added messages (new messages that need to be translated), and not yet translated messages. It will also maintain a whitelist file per language where you can specify translation keys where the translation is identical to the default message. This way you can avoid untranslated message warnings for these messages.
messagesDirectory
(required),
src/locales/extractedMessages
translationsDirectory
(required),
src/locales/lang
whitelistsDirectory
(optional, default: translationsDirectory
)
unmaintained translation
warnings.Dashboard
in english is also accepted as a valid translation for
dutch.languages
(optional, default: []
)
['nl', 'fr']
the translation manager will maintain a
nl.json
, fr.json
, whitelist_nl.json
and a whitelist_fr.json
filesingleMessagesFile
(optional, default: false
)
1[ 2 { 3 "path": "src/components/foo.json", 4 "descriptors": [ 5 { 6 "id": "bar", 7 "description": "Text for bar", 8 "defaultMessage": "Bar" 9 } 10 ] 11 } 12]
detectDuplicateIds
(optional, default: true
)
sortKeys
(optional, default: true
)
jsonOptions
(optional, default: { space: 2, trailingNewline: false })overridePrinters
(optional, default: {})
1const printers = { 2 printDuplicateIds: duplicateIds => { 3 console.log(`You have ${duplicateIds.length} duplicate IDs`); 4 }, 5 printLanguageReport: report => { 6 console.log('Log report for a language'); 7 }, 8 printNoLanguageFile: lang => { 9 console.log( 10 `No existing ${lang} translation file found. A new one is created.` 11 ); 12 }, 13 printNoLanguageWhitelistFile: lang => { 14 console.log(`No existing ${lang} file found. A new one is created.`); 15 } 16};
overrideCoreMethods
(optional, default: {})
1const overrideCoreMethods = { 2 provideExtractedMessages: () => {}, 3 outputSingleFile: () => {}, 4 outputDuplicateKeys: () => {}, 5 beforeReporting: () => {}, 6 provideLangTemplate: () => {}, 7 provideTranslationsFile: () => {}, 8 provideWhitelistFile: () => {}, 9 reportLanguage: () => {}, 10 afterReporting: () => {} 11};
This is the config with all options applied:
1// import manageTranslations from 'react-intl-translations-manager';
2
3manageTranslations({
4 messagesDirectory: 'src/translations/extractedMessages',
5 translationsDirectory: 'src/translations/locales/',
6 whitelistsDirectory: 'src/translations/locales/whitelists/',
7 languages: ['nl'], // any language you need
8 singleMessagesFile: true,
9 detectDuplicateIds: false,
10 sortKeys: false,
11 jsonOptions: {
12 space: 4,
13 trailingNewline: true
14 },
15 overridePrinters: {
16 printDuplicateIds: duplicateIds => {
17 console.log(`You have ${duplicateIds.length} duplicate IDs`);
18 },
19 printLanguageReport: report => {
20 console.log('Log report for a language');
21 },
22 printNoLanguageFile: lang => {
23 console.log(
24 `No existing ${lang} translation file found. A new one is created.`
25 );
26 },
27 printNoLanguageWhitelistFile: lang => {
28 console.log(`No existing ${lang} file found. A new one is created.`);
29 }
30 },
31 overrideCoreMethods: {
32 provideExtractedMessages: () => {},
33 outputSingleFile: () => {},
34 outputDuplicateKeys: () => {},
35 beforeReporting: () => {},
36 provideLangTemplate: () => {},
37 provideTranslationsFile: () => {},
38 provideWhitelistFile: () => {},
39 reportLanguage: () => {},
40 afterReporting: () => {}
41 }
42});
*This config is only as illustration for all possible options, these arent recommended configuration options.
These are the core methods of the translationManager and what purpose they serve.
1const extractedMessages = provideExtractedMessages();
Here you should return all extracted messages. This should be an array, with an object per file. Each object should at least contain a descriptors
key which in turn has an array of message objects. Each message object should at least contain the id and message.
Example:
1// Minimal expected return value 2const extractedMessages = [ 3 { 4 descriptors: [ 5 { 6 id: 'foo_ok', 7 defaultMessage: 'OK' 8 } 9 ] 10 } 11];
1outputSingleFile(extractedMessages);
This gives you the option to output the extractedMessages. This way you can for example shrink all extracted files into a single File containing all messages.
1outputDuplicateKeys(duplicateIds);
This gives you the option to warn for duplicate ids.
1beforeReporting();
Here you can do the preparation of the reporting, like creating the necessary folders, or printing a start message
1const languageResults = provideLangTemplate(lang);
Here you should provide the template for the language results. This is just a basic object ({}
) which can contain pre-filled in data, potentially based on the language.
The following keys are restricted and will be overridden by the core: report
, noTranslationFile
and noWhitelistFile
.
1const translationsFile = provideTranslationsFile(languageResults);
Here you should return the translations for the specified language. This must be an object with the message id and message in a key value format.
1const translationsFile = { 2 messageId: 'message' 3};
1const whitelistFile = provideWhitelistFile(languageResults);
Here you should return the whitelisted messsage ids for the specified language. This must be an array of strings.
1const whitelistFile = ['messageId'];
1reportLanguage(languageResults);
Here you can handle the reporting of the results for a language, like logging and creating files based on the results.
1afterReporting();
Here you can do actions after all reports are made, like cleanup or printing a finished message.
1const extractedMessages = readMessageFiles(messagesDirectory);
This is a babel-plugin-react-intl
specific helper method. It will read all extracted JSON file for the specified directory, filter out all files without any messages, and output an array with all messages.
Example output:
1const extractedMessages = [ 2 { 3 path: 'src/components/Foo.json', 4 descriptors: [ 5 { 6 id: 'foo_ok', 7 description: 'Ok text', 8 defaultMessage: 'OK' 9 } 10 ] 11 } 12];
1createSingleMessagesFile({ messages, directory });
This helper method will output all messages (potentially read by readMessageFiles
) in a single jsonFile.
defaultMessages.json
) this filename should contain the .json
extension2
) number of spaces used for indentation (0-10)1const messages = getDefaultMessages(extractedMessages);
This helper method will flatten all files (as returned from readMessageFiles
) into a single object.
1const messages = { 2 messages: { 3 messageId: 'message' 4 }, 5 duplicateIds: [ 6 // potentially double used message keys, 7 ] 8};
See the LICENSE file for license rights and limitations (MIT).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/10 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
113 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More