Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ typings/

# DynamoDB Local files
.dynamodb/

# Project files
locales
bin
.DS_Store
3 changes: 0 additions & 3 deletions bin/react-intl-extract.js

This file was deleted.

1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ program
.allowUnknownOption()
.option('-l,--locales <items>', 'list of output languages, default en,it', list)
.option('-s,--src [value]', 'source directory, default /src')
.option('-e,--extensions <items>', 'extensions of files to be searched', list)
.option('-o,--output [value]', 'output directory: where dictionaries are saved, default /locales')
.parse(process.argv);

Expand Down
7 changes: 7 additions & 0 deletions example/src/app/componentC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FormattedMessage } from 'react-intl';

export default () => (
<div>
<FormattedMessage id='string3' defaultMessage='msg3'></FormattedMessage>
</div>
);
2,544 changes: 2,408 additions & 136 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-intl-extract",
"version": "1.0.4",
"name": "@rpeterson/react-intl-extract",
"version": "1.0.5",
"description": "Extracts strings from react and creates dictionaries",
"homepage": "https://github.com/alefalezza/react-intl-extract",
"repository": {
Expand All @@ -9,31 +9,45 @@
},
"main": "index.js",
"bin": {
"react-intl-extract": "./bin/react-intl-extract.js"
"react-intl-extract": "./bin/react-intl-extract"
},
"scripts": {
"start": "node cli.js",
"build": "nexe cli.js -o bin/react-intl-extract --clean",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "alessandro falezza",
"contributors": [
{
"name": "Ryan Peterson"
}
],
"license": "ISC",
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/preset-typescript": "^7.3.3",
"babel-plugin-react-intl": "^3.0.1",
"commander": "^2.19.0",
"commander": "^2.20.0",
"glob": "^7.1.3",
"lodash": "^4.17.11",
"nexe": "^3.1.0",
"react-intl": "^2.8.0",
"react-intl-translations-manager": "^5.0.3",
"rimraf": "^2.6.3"
},
"files": [
"index.js",
"cli.js",
"bin/**/*",
"src/**/*"
]
"bin/react-intl-extract"
],
"babel": {
"presets": [
"module:@babel/preset-react",
"module:@babel/preset-typescript"
],
"plugins": [
"module:@babel/plugin-proposal-export-default-from",
"module:babel-plugin-react-intl"
]
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This tool configures babel, react intl and babel-plugin-react-intl and offers a

- `-l` (`--locales`): list of languages, it will produce a dictionary for every language, comma separated (deafult: `en,it`)
- `-s` (`--src`): source directory, where your `.jsx|.tsx` files are located (default `${cwd}/src`)
- `-e` (`--extensions`): file extensions, a csv list of extensions to extract from (default 'jsx,tsx')
- `-o` (`--output`): destination directory, where your dictionaries will be saved (default `${cwd}/locales`)
- `-v` (`--version`): shows script version
- `-h` (`--help`): shows available options
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const path = require('path');
const cwd = process.cwd();

module.exports = {
locales: ['en', 'it'],
locales: ['en'],
extensions: ['jsx', 'tsx', 'js', 'ts'],
src: path.join(cwd, 'src'),
output: path.join(cwd, 'locales')
};
8 changes: 3 additions & 5 deletions src/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const log = console.log;

const tmp = join(__dirname, '../', '.tmp');

const extensions = ['jsx', 'tsx'];

const globOptions = (src) => ({
root: src
});
Expand All @@ -29,12 +27,12 @@ const babelOptions = (src) => ({

module.exports = (options) => {
log(`Extracting i18n messages from ${options.src}`);
const { locales, src, output } = options;
const files = findFiles(src);
const { locales, src, output, extensions } = options;
const files = findFiles(src, extensions);
extractMessages(locales, src, output)(files);
};

const findFiles = (src) => {
const findFiles = (src, extensions) => {
const output = [];
extensions.forEach(ext => {
const files = glob.sync(`/**/*.${ext}`, globOptions(src));
Expand Down