![](/img/trans.png)
[英]Using poEdit to find gettext strings in a JS source file localized with Jed
[英]Extracting strings from JS file with gulp-angular-gettext does not work
我使用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不支持它,所以我們可能無能為力。 當async / await標准化時,它將被添加到espree,我們應該支持它而不做任何更改。 在此之前,在調用angular-gettext之前使用像babel這樣的轉換器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.