大家好,我的项目是Struts2。我们已经为客户端验证编写了通用的js文件。现在的问题是,为了实现内部化,我们必须根据语言更改警报消息。所以我的问题是,有没有办法访问js文件中的资源属性。或者任何人提出一些相同的替代方案或例子。
发布于 2012-07-14 00:34:02
将警报消息存储在js文件中,文件名如下
alert_en.js alert_fr.js alert_jp.js
在每个文件中存储警报,如下所示
var ALERT_EMAIL_INCORRECT = "Incorrect email";
var ALERT_USERNAME_INCORRECT = "Incorrect username";根据用户语言包括文件。
或
您可以使用JSP文件从资源包中加载消息,并将其链接到页面中,如下所示。
<script type="text/javascript" src="YOUR-FILE.JSP"></script>在这个JSP文件中,您在从资源束中读取数据后输出JavaScript。
还可以检查this。
发布于 2014-08-30 02:06:09
您可以使用我创建的messageResource.js库读取js文件中的属性文件。
1)在html中包含messageResource.js。
<script src="messageResource.min.js"></script>2)您可以通过js访问属性文件的键值对,如下所示。
// initialize messageResource.js with settings
messageResource.init({
// path to directory containing message resource files(.properties files),
// give empty string or discard this configuration if files are in the
// same directory as that of html file.
filePath : 'path/messageresource/'
});
// will load the file 'path/messageresource/moduleName_en_US.properties'
// and callbackFunction will be executed when loading is complete.
messageResource.load('moduleName', callbackFunction, 'en_US');
// use messageResource.get function to get values from loaded file.
var value = messageResource.get('key', 'moduleName', 'en_US');发布于 2012-07-14 00:00:32
您可以编写一个JSON文件,以原生英语为键,L10N消息为值,根据用户的浏览器语言配置,使用AJAX加载相关的JSON,并对带有警告的消息进行告警(TanslatedTableUSER_LANG)
https://stackoverflow.com/questions/11473705
复制相似问题