i18next-scanner
Advanced tools
Comparing version 2.3.1 to 2.4.0
@@ -63,5 +63,5 @@ 'use strict'; | ||
trans: { // Trans component (https://github.com/i18next/react-i18next) | ||
// list: ['Trans'], // TODO | ||
component: 'Trans', | ||
i18nKey: 'i18nKey', | ||
extensions: ['.js', '.jsx'], | ||
// key: 'i18nKey', // TODO | ||
fallbackKey: false | ||
@@ -169,15 +169,11 @@ }, | ||
// Trans | ||
/* TODO | ||
if (_.isUndefined(_.get(options, 'trans.list'))) { | ||
_.set(options, 'trans.list', defaults.trans.list); | ||
if (_lodash2.default.isUndefined(_lodash2.default.get(options, 'trans.component'))) { | ||
_lodash2.default.set(options, 'trans.component', defaults.trans.component); | ||
} | ||
*/ | ||
if (_lodash2.default.isUndefined(_lodash2.default.get(options, 'trans.i18nKey'))) { | ||
_lodash2.default.set(options, 'trans.i18nKey', defaults.trans.i18nKey); | ||
} | ||
if (_lodash2.default.isUndefined(_lodash2.default.get(options, 'trans.extensions'))) { | ||
_lodash2.default.set(options, 'trans.extensions', defaults.trans.extensions); | ||
} | ||
/* TODO | ||
if (_.isUndefined(_.get(options, 'trans.key'))) { | ||
_.set(options, 'trans.key', defaults.trans.key); | ||
} | ||
*/ | ||
if (_lodash2.default.isUndefined(_lodash2.default.get(options, 'trans.fallbackKey'))) { | ||
@@ -466,3 +462,6 @@ _lodash2.default.set(options, 'trans.fallbackKey', defaults.trans.fallbackKey); | ||
var reTrans = new RegExp('<Trans([^]*?)>([^]*?)</\\s*Trans\\s*>', 'gim'); | ||
var component = opts.component || this.options.trans.component; | ||
var i18nKey = opts.i18nKey || this.options.trans.i18nKey; | ||
var reTrans = new RegExp('<' + component + '([^]*?)>([^]*?)</\\s*' + component + '\\s*>', 'gim'); | ||
var reAttribute = /\b(\S+)\s*=\s*({.*?}|".*?"|'.*?')/gm; | ||
@@ -480,5 +479,5 @@ | ||
try { | ||
transKey = attributes.i18nKey ? getStringFromAttribute(attributes.i18nKey) : ''; | ||
transKey = attributes[i18nKey] ? getStringFromAttribute(attributes[i18nKey]) : ''; | ||
} catch (e) { | ||
this.log('i18next-scanner: i18nKey value must be a static string, saw ' + _chalk2.default.yellow(attributes.i18nKey)); | ||
this.log('i18next-scanner: i18nKey value must be a static string, saw ' + _chalk2.default.yellow(attributes[i18nKey])); | ||
continue; | ||
@@ -485,0 +484,0 @@ } |
{ | ||
"name": "i18next-scanner", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner", |
@@ -111,5 +111,8 @@ # i18next-scanner [![build status](https://travis-ci.org/i18next/i18next-scanner.svg?branch=master)](https://travis-ci.org/i18next/i18next-scanner) [![Coverage Status](https://coveralls.io/repos/i18next/i18next-scanner/badge.svg?branch=master&service=github)](https://coveralls.io/github/i18next/i18next-scanner?branch=master) | ||
trans: { | ||
component: 'Trans', | ||
i18nKey: 'i18nKey', | ||
extensions: ['.js', '.jsx'], | ||
fallbackKey: function(ns, value) { | ||
return value; | ||
// Returns a hash value as the fallback key | ||
return sha1(value); | ||
} | ||
@@ -185,3 +188,4 @@ }, | ||
.parseTransFromString(content, customHandler) // pass a custom handler | ||
.parseTransFromString(content, { fallbackKey: true }) // Use fallback key when key is missing | ||
.parseTransFromString(content, { component: 'Trans', i18nKey: 'i18nKey' }) | ||
.parseTransFromString(content, { fallbackKey: true }) // Uses defaultValue as the fallback key when the i18nKey attribute is missing | ||
.parseTransFromString(content); // use default options and handler | ||
@@ -296,3 +300,3 @@ | ||
parser.get(); | ||
```` | ||
``` | ||
@@ -321,2 +325,5 @@ #### parser.parseFuncFromString | ||
parser.parseTransFromString(context, { component: 'Trans', i18nKey: 'i18nKey' }); | ||
// Uses defaultValue as the fallback key when the i18nKey attribute is missing | ||
parser.parseTransFromString(content, { fallbackKey: true }); | ||
@@ -326,3 +333,4 @@ | ||
fallbackKey: function(ns, value) { | ||
return value; | ||
// Returns a hash value as the fallback key | ||
return sha1(value); | ||
} | ||
@@ -490,2 +498,8 @@ }); | ||
}, | ||
trans: { | ||
component: 'Trans', | ||
i18nKey: 'i18nKey', | ||
extensions: ['.js', '.jsx'], | ||
fallbackKey: false | ||
}, | ||
lngs: ['en'], | ||
@@ -572,2 +586,33 @@ ns: ['translation'], | ||
#### trans | ||
Type: `Object` or `false` | ||
If an `Object` is supplied, you can specify a list of extensions, or override the default. | ||
```js | ||
{ // Default | ||
trans: { | ||
component: 'Trans', | ||
i18nKey: 'i18nKey', | ||
extensions: ['.js', '.jsx'], | ||
fallbackKey: false | ||
} | ||
} | ||
``` | ||
You can set trans to `false` to disable parsing Trans component as below: | ||
```js | ||
{ | ||
trans: false | ||
} | ||
``` | ||
The fallbackKey can either be a boolean value, or a function like so: | ||
```js | ||
fallbackKey: function(ns, value) { | ||
// Returns a hash value as the fallback key | ||
return sha1(value); | ||
} | ||
``` | ||
#### lngs | ||
@@ -574,0 +619,0 @@ |
74017
772
1058