Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Costa committed Sep 11, 2017
2 parents a8ff288 + 458fa9a commit 2c39a3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-intl-gettext",
"version": "5.0.1",
"version": "5.1.0",
"description": "utilities to integrate react-intl with gettext",
"main": "dist/index.js",
"scripts": {
Expand Down
21 changes: 17 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import program from 'commander'
import headerFormatter from './json2po/headerFormatter'
import potFormatter from './json2po/potFormatter'
import messageReader from './json2po/jsonMessageReader'
import poMessageReader from './po2json/poMessageReader'
import poMessageReader, {
defaultPattern,
defaultNameMatcherPatternString,
} from './po2json/poMessageReader'
import {
getUserPackageJson,
buildVersionFromPackageJson,
Expand Down Expand Up @@ -61,24 +64,34 @@ program
program
.command('po2json <src> <dest>')
.description('converts po files to json')
.option('-p, --pattern [pattern]', 'glob pattern used to find the src files [**/*.po]', '**/*.po')
.option(
'-p, --pattern [pattern]',
`glob pattern used to find the src files [${defaultPattern}]`,
defaultPattern
)
.option('--pretty', 'pretty print json')
.option(
'-i, --ignore <patterns>',
'add a pattern or an array of glob patterns to exclude matches',
list
)
.action((src, dest, { pattern, pretty, ignore }) => {
.option(
'--lang-matcher-pattern [lang-matcher-pattern]',
`pattern used to match the language from the file name [${defaultNameMatcherPatternString}]`,
defaultNameMatcherPatternString
)
.action((src, dest, { pattern, pretty, ignore, langMatcherPattern }) => {
writeFileSync(
dest,
JSON.stringify(
poMessageReader({
cwd: src,
messagesPattern: pattern,
langMatcherPattern,
ignore,
}),
null,
pretty ? '\t' : undefined
pretty ? ' ' : undefined
)
)
})
Expand Down
10 changes: 7 additions & 3 deletions src/po2json/poMessageReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { join } from 'path'
import { readFileSync } from 'fs'
import { po } from 'gettext-parser'

const defaultNameMatcher = filename => filename.match(/.*[-](.*)\.po$/)[1]
const newNameMatcher = regex => filename => filename.match(regex)[1]

export const defaultNameMatcherPatternString = '.*-(.*)\\.po$'
export const defaultPattern = '**/*.po'

export default ({
messagesPattern = '**/*.po',
messagesPattern = defaultPattern,
cwd = process.cwd(),
langMatcher = defaultNameMatcher,
langMatcherPattern = defaultNameMatcherPatternString,
langMatcher = newNameMatcher(langMatcherPattern),
ignore,
}) => {
const translations = globSync(messagesPattern, { cwd, ignore }).map(filename => {
Expand Down

0 comments on commit 2c39a3d

Please sign in to comment.