[英]Extracting strings from JS file with gulp-angular-gettext does not work
I use angular-gettext-tools with @gabegorelick 's gulp-angular-gettext. 我使用angular-gettext-tools和@gabegorelick的gulp-angular-gettext。 Everyhing is okay with html files, but I fail to extract strings from js file.
每次使用html文件都可以,但我无法从js文件中提取字符串。 I tried both gettextCatalog.getString and gettext functions - together and separately - nothing worked.
我尝试了gettextCatalog.getString和gettext函数 - 一起和单独 - 没有任何效果。
My code for extraction (smth.js file) looks like this: 我的提取代码(smth.js文件)如下所示:
$scope.openCreateOfferPopup = function($event, buttonState) {
$event.preventDefault();
loadTypes();
logger('openCreateOfferPopup');
if (buttonState) {
var params;
if (!$rootScope.dashboard.spots || $rootScope.dashboard.spots.length === 0) {
params = {
title: 'Spots needed',
content: gettextCatalog.getString(gettext("Oops! You need to add your spot before creating an offer!"))+
'<br/>'+gettextCatalog.getString(gettext("Please, click on Create new spot button")),
buttons: [{
text: gettextCatalog.getString(gettext("Create spot")),
href: '',
'class': '',
ngClick: 'openCreateSpotPopup($event)',
ngController: 'SpotsController'
}, {
text: gettextCatalog.getString(gettext("cancel")),
href: '#',
'class': 'b-close'
}]
};
DialogService.makeDialog(params, $scope);
return;
}
My gulp task looks like this: 我的gulp任务看起来像这样:
import gulp from 'gulp';
import gettext from 'gulp-angular-gettext';
//import debug from 'gulp-debug';
gulp.task('pot', function () {
return gulp.src(['src/app/**/*.html','src/app/**/*.js',
'!src/app/pages/static/acceptable_policy.html','!src/app/pages/static/legal.html',
'!src/app/pages/static/privacy_policy.html','!src/app/pages/static/refund_policy.html',
'!src/app/pages/static/terms_of_service.html'])
//.pipe(debug({title: 'files to translate:'}))
.pipe(gettext.extract('template.pot', {
// options to pass to angular-gettext-tools...
}))
.pipe(gulp.dest('po/'));
});
I am pretty sure that js file is passed to aangular-gettext-tools - I used gulp-debug to verify it. 我很确定将js文件传递给aangular-gettext-tools - 我使用gulp-debug来验证它。
There are no error messages. 没有错误消息。 Everything is being extracted from html, but no entries from JavaScript.
一切都是从html中提取的,但没有来自JavaScript的条目。
Could you point me to the source of this problem? 你能指点我这个问题的根源吗?
I have gulp-angular-gettext@2.1.0 using angular-gettext-tools@2.1.13 and gulp 4.0.0-alpha.2 我有gulp-angular-gettext@2.1.0使用angular-gettext-tools@2.1.13和gulp 4.0.0-alpha.2
Okay, I found the culprit. 好的,我找到了罪魁祸首。 Angular-gettext-tools don't work with javascript ES7.
Angular-gettext-tools不适用于javascript ES7。 We had a piece of code:
我们有一段代码:
async function loadTypes() {
if ($rootScope.dashboard.types) return;
const { categories } = await Api.offerTypes();
$rootScope.dashboard.types = categories;
}
And it siliently died on async function
. 并且它在
async function
上很容易死亡。 Possibly, old version of espree
package from angular-gettext-tools
is to blame. 可能是来自
angular-gettext-tools
的espree
软件包应该受到指责。
I requested compatibility with ES7 and printing some debug info (to know that files could not be translated due to some error) here: https://github.com/rubenv/angular-gettext-tools/issues/140 我请求与ES7兼容并打印一些调试信息(要知道由于某些错误而无法翻译文件): https : //github.com/rubenv/angular-gettext-tools/issues/140
Right now we are going to use babel to downgrade our javascript to processable version and use it for extraction. 现在我们将使用babel将我们的javascript降级为可处理版本并将其用于提取。
Update to this question from official github: 从官方github 更新到这个问题:
espree doesn't support it so there's probably nothing we can do.
espree不支持它,所以我们可能无能为力。 When async/await is standardized, it will be added to espree, and we should support it without any changes.
当async / await标准化时,它将被添加到espree,我们应该支持它而不做任何更改。 Until then, use a transpiler like babel before calling angular-gettext.
在此之前,在调用angular-gettext之前使用像babel这样的转换器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.