我正试着用AngularJS做翻译。当preferredLanguage设置为en时,翻译工作正常。但是,如果我更改为任何其他,例如lt,我就会出错。
ReferenceError:未定义要求
在线:
var lcFile = require('path').join(__dirname, 'locale', lc + '.js'),我的应用程序的配置如下所示:
myApp.config(['$translateProvider', function ($translateProvider) {
$translateProvider.translations('lt', {
"OTHER_LIKES" : "{peopleCount, plural, one {# žmogus tai mėgsta} few {# žmonės tai mėgsta} other {# žmonių tai mėgsta}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {tu ir # žmogus tai mėgsta} few {tu ir # žmonės tai mėgsta} other {tu ir # žmonių tai mėgsta}}",
"YOU_LIKE" : "Tu mėgsti tai"
});
$translateProvider.translations('en', {
"OTHER_LIKES" : "{peopleCount, plural, one {# person likes this} few {# people likes this} other {# people likes this}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {You and # other likes this} few {You and # other likes this} other {You and # other likes this}}",
"YOU_LIKE" : "You like this"
});
$translateProvider.preferredLanguage('lt');
$translateProvider.fallbackLanguage('en');
$translateProvider.addInterpolation('$translateMessageFormatInterpolation');
}]);发布于 2015-12-28 22:26:27
结合messageformat.js版本0.2.2,我也遇到了这个错误。设置区域设置时,将通知MessageFormat翻译提供程序。如果它没有配置必要的区域设置,它将尝试require()文件。因为require是一个node.js关键字,浏览器不支持它,所以它会失败。
为了避免这种情况,您可以通过构建过程中的供应商脚本从messageformat.js发行版将所需的区域设置连接起来。
示例区域设置定义:
MessageFormat.locale.en=function(n){return n===1?"one":"other"}https://stackoverflow.com/questions/30883613
复制相似问题