bcabanes / gulp-angular-translate-extract Goto Github PK
View Code? Open in Web Editor NEWGulp version of grunt-angular-translate.
License: MIT License
Gulp version of grunt-angular-translate.
License: MIT License
When using a slightly more complex translate-value-*
attribute, this plugin extracts wrong keys.
<p
translate="page.something"
translate-value-link="<a href="/terms" target="_blank">{{ 'page.terms.title' | translate }}</a>"
></p>
From the HTML above, the following is extracted:
"{{ 'page": {
"terms": {
"title' | translate }}": ""
}
}
But only the key page.terms.title
should actually be extracted. This happens on version 0.1.8.
The following pattern doesn't get extracted:
<span class="sth" translate="key123"></span>
The translate
directive supports translating attributes. E.g. placeholder="…"
can be translated using translate-attr-placeholder="…"
. The extractor doesn't recognise this syntax.
Guys, you're doing exactly the same thing - what about to join forces and merge your effort into one repository?
https://github.com/hard8candy/gulp-angular-translate-extractor/
https://github.com/bcabanes/gulp-angular-translate-extract/
@bcabanes @hard8candy
The HtmlDirective regex:
HtmlDirective: '<[^>]*translate[^{>]*>([^<]*)<\/[^>]*>',
doesn't handle a greater than sign if it's inside an expression on the html element. E.g.:
<span ng-if="something > 0" translate> translate.key </span>
I fixed it like this:
<(?:[^>]*?|(?:[^>]*?["].*?["][^>]*?))translate[^{>]*>([^<]*)<\/[^>]*>
I threw up inside my mouth a little while writing it. It should ignore anything inside quotes before the translate directive. Don't know if anyone can write something prettier?
the output directory i18nextract is getting created in ../../ - or oven somewhere further off.
can you make it work that the standard gulp.dest() works - e.g.
.pipe(gulp.dest('testdirectory/js'));
the config option "dest" is imho not needed, since gulp.dest() takes this task.
the following doesn't write any output:
return gulp.src('modules/**/*.html')
it seems to create the result internally, but the file doesn't get written.
First of all, great plugin, thanks a lot!
If I set namespace: true
and don't have any keys containing dots (i.e. A.B
) the written JSON-object is empty. When I add one key with a dot the JSON-object is written correctly.
The HtmlDirective regex looks like this: <[^>]*translate[^{>]*>([^<]*)<\/[^>]*>
This will not match when I use the translate-values directive before the translate directive, because of the { in the middle of the HtmlDirective regex:
<span translate translate-values="{'something':$ctrl.something}">translation.key</span>
An easy workaround is to put the translate directive after the translate-values directive:
<span translate-values="{'something':$ctrl.something}" translate>translation.key</span>
But I am wondering what the { in the HtmlDirective regex is even guarding against? Is it safe to remove? I see no changes when I remove it and run translate extract on the codebase I'm working on atm.
In some cases I need to add the translation id as a model property and then use it with interpolation on a certain html tag.
The html directive should exclude this case:
<ANY translate="{{ model.someProperty }}"></ANY>
This actually generates the following:
"{{ model": { "someProperty }}": "{{ model.someProperty }}" }
The current regex expressions doesn't recognize any of the following syntax:
$translate('TRANSLATION', {param1: 'value', param2: 'value'});
$translate.instant('TRANSLATION', {param1: 'value', param2: 'value'});
$translate(['TRANSLATION', 'TRANSLATION_1'], {param1: 'value', param2: 'value'});
I was able to make it work by adding a wildcard .*
right before the closing parenthesis. Some better checking should probably be done though.
JavascriptServiceSimpleQuote: '\\$translate\\(\\s*\'((?:\\\\.|[^\'\\\\])*)\'[^\\)]*.*\\)',
JavascriptServiceDoubleQuote: '\\$translate\\(\\s*"((?:\\\\.|[^"\\\\])*)"[^\\)]*.*\\)',
JavascriptServiceArraySimpleQuote: '\\$translate\\((?:\\s*(\\[\\s*(?:(?:\'(?:(?:\\.|[^.*\'\\\\])*)\')\\s*,*\\s*)+\\s*\\])\\s*).*\\)',
JavascriptServiceArrayDoubleQuote: '\\$translate\\((?:\\s*(\\[\\s*(?:(?:"(?:(?:\\.|[^.*\'\\\\])*)")\\s*,*\\s*)+\\s*\\])\\s*).*\\)',
JavascriptServiceInstantSimpleQuote: '\\$translate\\.instant\\(\\s*\'((?:\\\\.|[^\'\\\\])*)\'[^\\)]*.*\\)',
JavascriptServiceInstantDoubleQuote: '\\$translate\\.instant\\(\\s*"((?:\\\\.|[^"\\\\])*)"[^\\)]*.*\\)',
I do:
gulp.task "extract i18n", ->
log "Generate i18n files " + (new Date()).toString()
gulp.src ['public/build/js/app.js']
.pipe angularTranslate
lang: TR_lang
dest: 'public/i18n'
.pipe gulp.dest 'public/i18n'
since the file I want to scan is 'public/build/js/app.js'
And I get a directory at the root of my project called i18n/
If I rerun the task all my translations get removed.
I really don't understand how you use the destination parameter, so if anyone can help me that will be cool.
I'm not sure if this is really an issue. My expectation was that gulp-angular-translate-extract preserves the translated strings in the json files. In other words: I'd like to use the following process:
Is that the way gulp-angular-translate-extract is intended to be used?
If yes, than this is a bug report ;-)
gulp-angular-translate-extract doesn't preserve my already translated strings. Everytime I run it a json file with only the keys present is created. The statistics say: en_US statistics: Updated: 0 / Deleted: 0 / New: 2
Translation is missing for the statement inside if-else block or inside catch block.
Angular allows filters to be defined as a one time binding:
<img src="..." alt="{{::('ALT_TEXT' | translate)}}"/>
See also here: http://stackoverflow.com/a/28590630/4287172
This is useful to prevent having too many watches open. gulp-angular-translate-extract doesn't seem to recognize these keys at the moment. Could you maybe add support for this kind of filters?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.