我本地化了我的应用程序,它适用于标签,标题和错误消息。我在我的应用程序中使用了jtable。但是按钮没有得到本地化。内部jtable.js我有
messages: {
serverCommunicationError: 'An error occured while communicating to the server.',
loadingMessage: 'Loading records...',
noDataAvailable: 'No data available!',
areYouSure: 'Are you sure?',
save: 'Save',
saving: 'Saving',
cancel: 'Cancel',
error: 'Error',
close: 'Close',
cannotLoadOptionsFor: 'Can not load options for field {0}'
}
但如果我选择俄语我应该用俄语语言获取这些消息。为此我尝试添加这样的资源文件:
<script type="text/javascript">
(function ($) {
$.widget("hik.jtable", {
messages: {
serverCommunicationError: '@SEFTool.Resources.Models.ValidationStrings.serverCommunication',
loadingMessage: '@SEFTool.Resources.Models.ValidationStrings.loading',
noDataAvailable: '@SEFTool.Resources.Models.ValidationStrings.noData',
areYouSure: '@SEFTool.Resources.Models.ValidationStrings.Sure',
save: '@SEFTool.Resources.Models.ValidationStrings.Save',
saving: '@SEFTool.Resources.Models.ValidationStrings.Saving',
cancel: '@SEFTool.Resources.Models.ValidationStrings.Cancel',
error: '@SEFTool.Resources.Models.ValidationStrings.Error',
close: '@SEFTool.Resources.Models.ValidationStrings.Close',
cannotLoadOptionsFor: '@SEFTool.Resources.Models.ValidationStrings.cannotLoad'
}
});
});
但它无效。如何将当前文化传递给js文件并调用其中的资源文件。
请帮助本地化按钮..
编辑: -
我创建了一个类
public static class MyGlobals
{
public static string serverCommunicationError;
.....
}
和内部视图我这样给了。
@SEFTool.Models.Administration.MyGlobals.serverCommunicationError= '@SEFTool.Resources.Models.ValidationStrings.serverCommunication'
在'@ SEFTool.Resources.Models.ValidationStrings.serverCommunication'里面的俄语语言。但是这个值没有传递给@ SEFTool.Models.Administration.MyGlobals.serverCommunicationError.serverCommunicationError显示为空
编辑: -
内部索引视图我这样做了......但是没有得到输出
<script type="text/javascript">
(function (global) {
var r = global.Resources || {};
r.serverCommunicationError = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.serverCommunication)';
r.loadingMessage = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.loading)';
r.noDataAvailable = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.noData)';
r.areYouSure = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Sure)';
r.save = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Save)';
r.saving = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Saving)';
r.cancel = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Cancel)';
r.error = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Error)';
r.close = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Close)';
r.cannotLoadOptionsFor = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.cannotLoad)';
global.Resources = r;
})(this);
$('#content_1').jtable({
title: '',
paging: true,
pageSize: 10,
sorting: true,
inlineEditor: false,
permissions: 'AED',
答案 0 :(得分:0)
在您的视图(.cshtml)中,设置以下脚本标记:
<script type="text/javascript">
(function(global) {
var r = global.Resources || {};
r.serverCommunicationError = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.serverCommunication)';
r.loadingMessage = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.loading)';
r.noDataAvailable = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.noData)';
r.areYouSure = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Sure)';
r.save = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Save)';
r.saving = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Saving)';
r.cancel = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Cancel)';
r.error = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Error)';
r.close = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.Close)';
r.cannotLoadOptionsFor = '@Html.Raw(SEFTool.Resources.Models.ValidationStrings.cannotLoad)';
global.Resources = r;
})(this);
</script>
然后,在您的脚本文件中,像这样引用它:
messages: {
serverCommunicationError: Resources.serverCommunicationError,
loadingMessage: Resources.loadingMessage,
noDataAvailable: Resources.noDataAvailable,
areYouSure: Resources.areYouSure,
save: Resources.save,
saving: Resources.saving,
cancel: Resources.cancel,
error: Resources.error,
close: Resources.close,
cannotLoadOptionsFor: Resources.cannotLoadOptionsFor
}
请记住,必须在js-file中的代码之前调用第一个脚本标记,以便Resources
对象可用。如果在你的js文件中,你等待DOM准备就绪,那么这将是没有问题的。
此外,这只是我想到的第一个解决方案。也许它不是最好的,而其他人知道更好的方法。我也会以不同的方式解决这个问题。