Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
64ebb5e6e8 | ||
|
40051f4144 | ||
|
14eb09f947 | ||
|
8d1e2c5a2f | ||
|
4892ea5146 | ||
|
ee28fe2a64 | ||
|
7c06b66974 | ||
|
b2ae17697d | ||
|
5259da8fe3 | ||
|
2d73f056ff |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Kim Biesbjerg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@@ -93,3 +93,5 @@ Options:
|
||||
[boolean] [default: false]
|
||||
--clean, -c Remove obsolete strings when merging
|
||||
[boolean] [default: false]
|
||||
--verbose, -vb If true, prints all processed file paths to console
|
||||
[boolean] [default: true]
|
||||
|
1278
package-lock.json
generated
Normal file
1278
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@biesbjerg/ngx-translate-extract",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.4",
|
||||
"description": "Extract strings from projects using ngx-translate",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
@@ -47,30 +47,30 @@
|
||||
},
|
||||
"config": {},
|
||||
"devDependencies": {
|
||||
"@types/chai": "3.5.2",
|
||||
"@types/chai": "4.0.1",
|
||||
"@types/glob": "5.0.30",
|
||||
"@types/mocha": "2.2.41",
|
||||
"@types/cheerio": "0.22.1",
|
||||
"@types/chalk": "0.4.31",
|
||||
"@types/flat": "0.0.28",
|
||||
"@types/yargs": "6.6.0",
|
||||
"@types/yargs": "8.0.0",
|
||||
"@types/mkdirp": "0.3.29",
|
||||
"chai": "3.5.0",
|
||||
"mocha": "3.3.0",
|
||||
"ts-node": "3.0.4",
|
||||
"tslint": "5.2.0",
|
||||
"tslint-eslint-rules": "4.0.0",
|
||||
"typescript": "2.3.2"
|
||||
"chai": "4.0.2",
|
||||
"mocha": "3.4.2",
|
||||
"ts-node": "3.1.0",
|
||||
"tslint": "5.4.3",
|
||||
"tslint-eslint-rules": "4.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "1.1.3",
|
||||
"yargs": "8.0.1",
|
||||
"cheerio": "0.22.0",
|
||||
"chalk": "2.0.1",
|
||||
"yargs": "8.0.2",
|
||||
"cheerio": "1.0.0-rc.2",
|
||||
"fs": "0.0.1-security",
|
||||
"gettext-parser": "1.2.2",
|
||||
"glob": "7.1.1",
|
||||
"glob": "7.1.2",
|
||||
"path": "0.12.7",
|
||||
"mkdirp": "0.5.1",
|
||||
"flat": "2.0.1"
|
||||
"flat": "2.0.1",
|
||||
"typescript": "2.4.1"
|
||||
}
|
||||
}
|
||||
|
@@ -82,6 +82,12 @@ export const cli = yargs
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
})
|
||||
.option('verbose', {
|
||||
alias: 'vb',
|
||||
describe: 'Log all output to console',
|
||||
default: true,
|
||||
type: 'boolean'
|
||||
})
|
||||
.exitProcess(true)
|
||||
.parse(process.argv);
|
||||
|
||||
|
@@ -14,6 +14,7 @@ export interface ExtractTaskOptionsInterface {
|
||||
sort?: boolean;
|
||||
clean?: boolean;
|
||||
patterns?: string[];
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
export class ExtractTask implements TaskInterface {
|
||||
@@ -22,7 +23,8 @@ export class ExtractTask implements TaskInterface {
|
||||
replace: false,
|
||||
sort: false,
|
||||
clean: false,
|
||||
patterns: []
|
||||
patterns: [],
|
||||
verbose: true
|
||||
};
|
||||
|
||||
protected _parsers: ParserInterface[] = [];
|
||||
@@ -64,7 +66,7 @@ export class ExtractTask implements TaskInterface {
|
||||
let collection: TranslationCollection = new TranslationCollection();
|
||||
this._input.forEach(dir => {
|
||||
this._readDir(dir, this._options.patterns).forEach(path => {
|
||||
this._out(chalk.gray('- %s'), path);
|
||||
this._options.verbose && this._out(chalk.gray('- %s'), path);
|
||||
const contents: string = fs.readFileSync(path, 'utf-8');
|
||||
this._parsers.forEach((parser: ParserInterface) => {
|
||||
collection = collection.union(parser.extract(contents, path));
|
||||
|
@@ -2,7 +2,9 @@ import { ParserInterface } from './parser.interface';
|
||||
import { AbstractTemplateParser } from './abstract-template.parser';
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
|
||||
import * as $ from 'cheerio';
|
||||
import * as cheerio from 'cheerio';
|
||||
|
||||
const $ = cheerio.load('', {xmlMode: true});
|
||||
|
||||
export class DirectiveParser extends AbstractTemplateParser implements ParserInterface {
|
||||
|
||||
|
@@ -18,7 +18,7 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
|
||||
const regExp: RegExp = /(['"`])((?:(?!\1).|\\\1)+)\1\s*\|\s*translate/g;
|
||||
let matches: RegExpExecArray;
|
||||
while (matches = regExp.exec(template)) {
|
||||
collection = collection.add(matches[2].replace('\\\'', '\''));
|
||||
collection = collection.add(matches[2].split('\\\'').join('\''));
|
||||
}
|
||||
|
||||
return collection;
|
||||
|
@@ -118,7 +118,7 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface
|
||||
if (!methodAccess || methodAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
||||
return false;
|
||||
}
|
||||
if (!methodAccess.name || (methodAccess.name.text !== 'get' && methodAccess.name.text !== 'instant')) {
|
||||
if (!methodAccess.name || (methodAccess.name.text !== 'get' && methodAccess.name.text !== 'instant' && methodAccess.name.text !== 'stream')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -118,4 +118,10 @@ describe('DirectiveParser', () => {
|
||||
expect(template).to.equal('<p translate="KEY">Hello World</p>');
|
||||
});
|
||||
|
||||
it('should extract contents from within custom tags', () => {
|
||||
const contents = `<custom-table><tbody><tr><td translate>Hello World</td></tr></tbody></custom-table>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello World']);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -36,6 +36,12 @@ describe('PipeParser', () => {
|
||||
expect(keys).to.deep.equal([`World's largest potato`]);
|
||||
});
|
||||
|
||||
it('should extract strings with multiple escaped quotes', () => {
|
||||
const contents = `{{ 'C\\'est ok. C\\'est ok' | translate }}`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal([`C'est ok. C'est ok`]);
|
||||
});
|
||||
|
||||
it('should extract interpolated strings using translate pipe in attributes', () => {
|
||||
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
|
@@ -60,6 +60,19 @@ describe('ServiceParser', () => {
|
||||
expect(keys).to.deep.equal(['Hello World']);
|
||||
});
|
||||
|
||||
it('should extract strings in TranslateService\'s stream() method', () => {
|
||||
const contents = `
|
||||
@Component({ })
|
||||
export class AppComponent {
|
||||
public constructor(protected _translateService: TranslateService) { }
|
||||
public test() {
|
||||
this._translateService.stream('Hello World');
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello World']);
|
||||
});
|
||||
|
||||
it('should extract array of strings in TranslateService\'s get() method', () => {
|
||||
const contents = `
|
||||
@Component({ })
|
||||
@@ -86,7 +99,20 @@ describe('ServiceParser', () => {
|
||||
expect(key).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should not extract strings in get()/instant() methods of other services', () => {
|
||||
it('should extract array of strings in TranslateService\'s stream() method', () => {
|
||||
const contents = `
|
||||
@Component({ })
|
||||
export class AppComponent {
|
||||
public constructor(protected _translateService: TranslateService) { }
|
||||
public test() {
|
||||
this._translateService.stream(['Hello', 'World']);
|
||||
}
|
||||
`;
|
||||
const key = parser.extract(contents, componentFilename).keys();
|
||||
expect(key).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should not extract strings in get()/instant()/stream() methods of other services', () => {
|
||||
const contents = `
|
||||
@Component({ })
|
||||
export class AppComponent {
|
||||
@@ -97,6 +123,7 @@ describe('ServiceParser', () => {
|
||||
public test() {
|
||||
this._otherService.get('Hello World');
|
||||
this._otherService.instant('Hi there');
|
||||
this._otherService.stream('Hi there');
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
|
Reference in New Issue
Block a user