我将 angular-gettext-tools 与@gabegorelick 的 gulp-angular-gettext 一起使用。 html 文件一切正常,但我无法从 js 文件中提取字符串。我尝试了 gettextCatalog.getString 和 gettext 函数 - 一起和单独 - 没有任何效果。
我的提取代码(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;
}
我的 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/'));
});
我很确定 js 文件已传递给 aangular-gettext-tools - 我使用 gulp-debug 来验证它。
没有错误信息。一切都从 html 中提取,但没有来自 JavaScript 的条目。
你能指出这个问题的根源吗?
我有 gulp-angular-gettext@2.1.0 使用 angular-gettext-tools@2.1.13 和 gulp 4.0.0-alpha.2
最佳答案
好的,我找到了罪魁祸首。 Angular-gettext-tools 不适用于 javascript ES7。 我们有一段代码:
async function loadTypes() {
if ($rootScope.dashboard.types) return;
const { categories } = await Api.offerTypes();
$rootScope.dashboard.types = categories;
}
它在 async function
上默默地死了。可能是 angular-gettext-tools
中的 espree
包的旧版本是罪魁祸首。
我在这里请求与 ES7 的兼容性并打印一些调试信息(以了解文件由于某些错误而无法翻译): https://github.com/rubenv/angular-gettext-tools/issues/140
现在我们将使用 babel 将我们的 javascript 降级为可处理的版本,并将其用于提取。
从官方github更新这个问题:
espree doesn't support it so there's probably nothing we can do. When async/await is standardized, it will be added to espree, and we should support it without any changes. Until then, use a transpiler like babel before calling angular-gettext.
关于javascript - 使用 gulp-angular-gettext 从 JS 文件中提取字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37074070/