Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-intl-translations-manager

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intl-translations-manager - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

test/getDefaultMessages.test.js

31

contributing.md

@@ -7,24 +7,29 @@ # Contributing

1. Make sure your branch is up to date with the current master
2. Install latest dependencies with
> yarn
1. Make sure your branch is up to date with the current master
2. Install latest dependencies with
3. Develop your feature/bug fix
4. Create tests for as much as possible
5. Make sure eslint errors are fixed, if eslint errors don't show up in your editor you can always check them with
> npm run eslint
> yarn
6. Check if everything works well by using the example application
1. Create a build for the translation manager
3. Develop your feature/bug fix
4. Create tests for as much as possible
5. Make sure eslint errors are fixed, if eslint errors don't show up in your editor you can always check them with
> npm run eslint
6. Check if everything works well by using the example application
7. Create a build for the translation manager
> npm run build
2. Create a build for the example application
8. Create a build for the example application
> cd example
> npm run build
3. Run the translation manager
3. Run the translation manager
> npm run manage:translations
7. Commit your changes according to the conventional changelog commit convention we use
8. Create a pull request
4. Commit your changes according to the conventional changelog commit convention we use
5. Create a pull request
(If you encounter additional steps during your contribution, do not hesitate to update this document)

@@ -1,82 +0,1 @@

{
"name": "react-intl-translations-manager",
"description": "Manage all translations based on the extracted messages of the babel-plugin-react-intl",
"main": "./dist/index.js",
"scripts": {
"clean:install": "rimraf node_modules && npm cache clean && npm install",
"test": "cross-env NODE_ENV=test jest",
"test:watch": "npm test -- --watch",
"coverage": "cross-env npm test -- --coverage --maxWorkers=4",
"report:coverage": "cat ./coverage/coverage-final.json | ./node_modules/codecov.io/bin/codecov.io.js",
"prebuild": "rimraf dist",
"build": "babel src --out-dir dist",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"eslint": "eslint ./src ./test",
"format": "prettier --write --single-quote 'src/**/*.js' 'test/**/*.js'",
"format:staged": "lint-staged"
},
"repository": {
"type": "git",
"url": "https://github.com/GertjanReynaert/react-intl-translations-manager.git"
},
"keywords": [
"react",
"intl",
"translations",
"manager",
"management",
"managing",
"i18n"
],
"author": "Gertjan Reynaert <gertjan.reynaert@gmail.com>",
"contributors": [
"Bart van Andel <bavanandel@gmail.com>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/GertjanReynaert/react-intl-translations-manager/issues"
},
"homepage": "https://github.com/GertjanReynaert/react-intl-translations-manager#readme",
"dependencies": {
"chalk": "^2.1.0",
"glob": "^7.1.2",
"json-stable-stringify": "^1.0.1",
"mkdirp": "^0.5.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.1",
"babel-jest": "^21.2.0",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"codecov.io": "^0.1.6",
"cross-env": "^5.0.5",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^4.7.2",
"eslint-config-prettier": "^2.6.0",
"jest": "^21.2.1",
"lint-staged": "^4.2.3",
"precommit": "^1.2.2",
"prettier": "^1.7.2",
"rimraf": "^2.6.2",
"semantic-release": "^8.0.3"
},
"jest": {
"coverageDirectory": "coverage",
"testEnvironment": "node"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"lint-staged": {
"*.js": [
"prettier --write --single-quote",
"git add"
]
},
"pre-commit": "format:staged",
"version": "5.0.1"
}
{"name":"react-intl-translations-manager","description":"Manage all translations based on the extracted messages of the babel-plugin-react-intl","main":"./dist/index.js","scripts":{"clean:install":"rimraf node_modules && npm cache clean && npm install","test":"cross-env NODE_ENV=test jest","test:watch":"npm test -- --watch","coverage":"cross-env npm test -- --coverage --maxWorkers=4","report:coverage":"cat ./coverage/coverage-final.json | ./node_modules/codecov.io/bin/codecov.io.js","prebuild":"rimraf dist","build":"babel src --out-dir dist","semantic-release":"semantic-release pre && npm publish && semantic-release post","eslint":"eslint ./src ./test","format":"npm run format:js && npm run format:md","format:js":"prettier --write --single-quote 'src/**/*.js' 'test/**/*.js'","format:md":"prettier --write --single-quote --parser markdown '*.md'","format:staged":"lint-staged"},"repository":{"type":"git","url":"https://github.com/GertjanReynaert/react-intl-translations-manager.git"},"keywords":["react","intl","translations","manager","management","managing","i18n"],"author":"Gertjan Reynaert <gertjan.reynaert@gmail.com>","contributors":["Bart van Andel <bavanandel@gmail.com>"],"license":"MIT","bugs":{"url":"https://github.com/GertjanReynaert/react-intl-translations-manager/issues"},"homepage":"https://github.com/GertjanReynaert/react-intl-translations-manager#readme","dependencies":{"chalk":"^2.3.2","glob":"^7.1.2","json-stable-stringify":"^1.0.1","mkdirp":"^0.5.1"},"devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.2.2","babel-jest":"^22.4.3","babel-preset-env":"^1.6.1","babel-preset-stage-3":"^6.24.1","codecov.io":"^0.1.6","cross-env":"^5.1.4","cz-conventional-changelog":"^2.1.0","eslint":"^4.19.1","eslint-config-prettier":"^2.9.0","jest":"^22.4.3","lint-staged":"^7.0.0","precommit":"^1.2.2","prettier":"^1.11.1","rimraf":"^2.6.2","semantic-release":"^8.2.3"},"jest":{"coverageDirectory":"coverage","testEnvironment":"node"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"lint-staged":{"*.js":["prettier --write --single-quote","git add"]},"pre-commit":"format:staged","version":"5.0.2"}

@@ -41,3 +41,3 @@ # React-intl-translations-manager

or
or

@@ -49,2 +49,3 @@ ```

## Setup
### Basic

@@ -55,2 +56,3 @@

Create a script in your package.json
```json

@@ -63,3 +65,5 @@ {

```
Create a file with your config you can run with the npm script
```js

@@ -75,3 +79,3 @@ // translationRunner.js

translationsDirectory: 'src/translations/locales/',
languages: ['nl'], // any language you need
languages: ['nl'] // any language you need
});

@@ -111,60 +115,70 @@ ```

- `messagesDirectory` (required),
- Directory where the babel plugin puts the extracted messages. This path is
relative to your projects root.
- example: `src/locales/extractedMessages`
- `translationsDirectory` (required),
- Directory of the translation files the translation manager needs to maintain.
- example: `src/locales/lang`
- `whitelistsDirectory` (optional, default: `translationsDirectory`)
- Directory of the whitelist files the translation manager needs to maintain.
These files contain the key of translations that have the exact same text in
a specific language as the defaultMessage. Specifying this key will suppress
`unmaintained translation` warnings.
- example: `Dashboard` in english is also accepted as a valid translation for
dutch.
- `languages` (optional, default: `[]`)
- What languages the translation manager needs to maintain. Specifying no
languages actually doesn't make sense, but won't break the translationManager
either. (Please do not include the default language, react-intl will automatically include it.)
- example: for `['nl', 'fr']` the translation manager will maintain a
`nl.json`, `fr.json`, `whitelist_nl.json` and a `whitelist_fr.json` file
- `singleMessagesFile` (optional, default: `false`)
- Option to output a single JSON file containing the aggregate of all extracted messages,
grouped by the file they were extracted from.
- example:
* `messagesDirectory` (required),
* Directory where the babel plugin puts the extracted messages. This path is
relative to your projects root.
* example: `src/locales/extractedMessages`
* `translationsDirectory` (required),
* Directory of the translation files the translation manager needs to maintain.
* example: `src/locales/lang`
* `whitelistsDirectory` (optional, default: `translationsDirectory`)
* Directory of the whitelist files the translation manager needs to maintain.
These files contain the key of translations that have the exact same text in
a specific language as the defaultMessage. Specifying this key will suppress
`unmaintained translation` warnings.
* example: `Dashboard` in english is also accepted as a valid translation for
dutch.
* `languages` (optional, default: `[]`)
* What languages the translation manager needs to maintain. Specifying no
languages actually doesn't make sense, but won't break the translationManager
either. (Please do not include the default language, react-intl will automatically include it.)
* example: for `['nl', 'fr']` the translation manager will maintain a
`nl.json`, `fr.json`, `whitelist_nl.json` and a `whitelist_fr.json` file
* `singleMessagesFile` (optional, default: `false`)
* Option to output a single JSON file containing the aggregate of all extracted messages,
grouped by the file they were extracted from.
* example:
```json
[
{
"path": "src/components/foo.json",
"descriptors": [
{
"id": "bar",
"description": "Text for bar",
"defaultMessage": "Bar",
}
]
}
]
[
{
"path": "src/components/foo.json",
"descriptors": [
{
"id": "bar",
"description": "Text for bar",
"defaultMessage": "Bar"
}
]
}
]
```
- `detectDuplicateIds` (optional, default: `true`)
- If you want the translationManager to log duplicate message ids or not
- `sortKeys` (optional, default: `true`)
- If you want the translationManager to sort it's output, both json and console output
- `jsonOptions` (optional, default: { space: 2, trailingNewline: false })
- `overridePrinters` (optional, default: {})
- Here you can specify custom logging methods. If not specified a default printer is used.
- Possible printers to configure:
* `detectDuplicateIds` (optional, default: `true`)
* If you want the translationManager to log duplicate message ids or not
* `sortKeys` (optional, default: `true`)
* If you want the translationManager to sort it's output, both json and console output
* `jsonOptions` (optional, default: { space: 2, trailingNewline: false })
* `overridePrinters` (optional, default: {})
* Here you can specify custom logging methods. If not specified a default printer is used.
* Possible printers to configure:
```js
const printers = {
printDuplicateIds: ( duplicateIds ) => { console.log(`You have ${duplicateIds.length } duplicate IDs`) },
printLanguageReport: ( report ) => { console.log('Log report for a language') },
printNoLanguageFile: ( lang ) => { console.log(`No existing ${lang} translation file found. A new one is created.`) },
printNoLanguageWhitelistFile: ( lang ) => { console.log(`No existing ${lang} file found. A new one is created.`) },
};
const printers = {
printDuplicateIds: duplicateIds => {
console.log(`You have ${duplicateIds.length} duplicate IDs`);
},
printLanguageReport: report => {
console.log('Log report for a language');
},
printNoLanguageFile: lang => {
console.log(
`No existing ${lang} translation file found. A new one is created.`
);
},
printNoLanguageWhitelistFile: lang => {
console.log(`No existing ${lang} file found. A new one is created.`);
}
};
```
- `overrideCoreMethods` (optional, default: {})
- Here you can specify overrides for the core hooks. If not specified, the
default methods will be used.
- Possible overrides to configure:
* `overrideCoreMethods` (optional, default: {})
* Here you can specify overrides for the core hooks. If not specified, the
default methods will be used.
* Possible overrides to configure:
```js

@@ -180,4 +194,4 @@ const overrideCoreMethods = {

reportLanguage: () => {},
afterReporting: () => {},
}
afterReporting: () => {}
};
```

@@ -202,9 +216,19 @@

space: 4,
trailingNewline: true,
trailingNewline: true
},
overridePrinters: {
printDuplicateIds: ( duplicateIds ) => { console.log(`You have ${duplicateIds.length } duplicate IDs`) },
printLanguageReport: ( report ) => { console.log('Log report for a language') },
printNoLanguageFile: ( lang ) => { console.log(`No existing ${lang} translation file found. A new one is created.`) },
printNoLanguageWhitelistFile: ( lang ) => { console.log(`No existing ${lang} file found. A new one is created.`) },
printDuplicateIds: duplicateIds => {
console.log(`You have ${duplicateIds.length} duplicate IDs`);
},
printLanguageReport: report => {
console.log('Log report for a language');
},
printNoLanguageFile: lang => {
console.log(
`No existing ${lang} translation file found. A new one is created.`
);
},
printNoLanguageWhitelistFile: lang => {
console.log(`No existing ${lang} file found. A new one is created.`);
}
},

@@ -220,8 +244,8 @@ overrideCoreMethods: {

reportLanguage: () => {},
afterReporting: () => {},
},
afterReporting: () => {}
}
});
```
*This config is only as illustration for all possible options, these arent
\*This config is only as illustration for all possible options, these arent
recommended configuration options.

@@ -235,2 +259,3 @@

#### provideExtractedMessages
```js

@@ -242,2 +267,3 @@ const extractedMessages = provideExtractedMessages();

Example:
```js

@@ -250,6 +276,6 @@ // Minimal expected return value

id: 'foo_ok',
defaultMessage: 'OK',
},
],
},
defaultMessage: 'OK'
}
]
}
];

@@ -259,2 +285,3 @@ ```

#### outputSingleFile
```js

@@ -267,2 +294,3 @@ outputSingleFile(extractedMessages);

#### outputDuplicateKeys
```js

@@ -275,2 +303,3 @@ outputDuplicateKeys(duplicateIds);

#### beforeReporting
```js

@@ -283,2 +312,3 @@ beforeReporting();

#### provideLangTemplate
```js

@@ -292,2 +322,3 @@ const languageResults = provideLangTemplate(lang);

#### provideTranslationsFile
```js

@@ -298,5 +329,6 @@ const 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.
```js
const translationsFile = {
messageId: 'message',
messageId: 'message'
};

@@ -306,2 +338,3 @@ ```

#### provideWhitelistFile
```js

@@ -312,11 +345,11 @@ const whitelistFile = provideWhitelistFile(languageResults);

Here you should return the whitelisted messsage ids for the specified language. This must be an array of strings.
```js
const whitelistFile = [
'messageId',
];
const whitelistFile = ['messageId'];
```
#### reportLanguage
```js
reportLanguage(languageResults)
reportLanguage(languageResults);
```

@@ -327,4 +360,5 @@

#### afterReporting
```js
afterReporting()
afterReporting();
```

@@ -335,2 +369,3 @@

### readMessageFiles
```js

@@ -343,2 +378,3 @@ const extractedMessages = readMessageFiles(messagesDirectory);

Example output:
```js

@@ -352,6 +388,6 @@ const extractedMessages = [

description: 'Ok text',
defaultMessage: 'OK',
},
],
},
defaultMessage: 'OK'
}
]
}
];

@@ -361,2 +397,3 @@ ```

### createSingleMessagesFile
```js

@@ -368,8 +405,9 @@ createSingleMessagesFile({ messages, directory });

- messages: (required)
- directory: (required, string) contains the path to the directory where the file should be written into.
- fileName: (optional, default: `defaultMessages.json`) this filename should contain the `.json` extension
- jsonSpaceIndentation: (optional, default: `2`) number of spaces used for indentation (0-10)
* messages: (required)
* directory: (required, string) contains the path to the directory where the file should be written into.
* fileName: (optional, default: `defaultMessages.json`) this filename should contain the `.json` extension
* jsonSpaceIndentation: (optional, default: `2`) number of spaces used for indentation (0-10)
### getDefaultMessages
```js

@@ -384,3 +422,3 @@ const messages = getDefaultMessages(extractedMessages);

messages: {
messageId: 'message',
messageId: 'message'
},

@@ -387,0 +425,0 @@ duplicateIds: [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc