访问* .js文件中的资源属性文件 [英] accessing resource property file in *.js file

查看:99
本文介绍了访问* .js文件中的资源属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的项目在struts 2中.我们编写了用于客户端验证的通用js文件. 现在的问题是,要实现内部化,我们必须根据语言更改警报消息. 所以我的问题是,有什么方法可以访问js文件中的资源属性. 或任何一个建议相同的替代或示例.

Hi my project is in struts 2. We have written common js files for client side validation. now the problem is that to implement internalization we have to change alert message as per the language. so my question is that is there any way to access resource property in js file. or any one suggest some alternative or example for the same.

推荐答案

您可以使用 messageResource.js 库.

1)在HTML中包含messageResource.js.

1) Include messageResource.js in your html.

<script src="messageResource.min.js"></script>

2)您可以按如下方式从js访问属性文件的键值对.

2) You can access key-value pair of properties file from js as follows.

// 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');

这篇关于访问* .js文件中的资源属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆