做一个记录和mx.utils.StringUtil.substitute()包做个记录:
Using this class, the example above would look more like this:
receivedMessage=At %time%, you received a message from %userName%.
// then in your code
trace(ResourceStringUtil.getResoureceStringWithTokens("receivedMessage", {time: "11:49", userName: "Mims"}));
// displays
At 11:49, you received a message from Mims.
import mx.resources.ResourceManager;
/**
* A utility for string related functions within.
*
* @author Mims H. Wright
*/
public class ResourceStringUtil
{
public static function get DEFAULT_BUNDLE():String { return "Strings"; }
/**
* Replaces tokens in a resource string with values from a generic object.
* The tokens in the string will be replaced if a matching named property exists
* in the tokenValues object.
*
* @param key The key name for looking up the string in the resource bundle.
* @param tokenValues A generic object containing values for the tokens.
* @param bundle The resource bundle to use. Default is Strings.
*
* @example <listing version="3.0">
*
* // If the following is defined in Strings.properties...
* userSelectedProductMessage=%userName% viewed %productName% at %date%.
*
* // you could retrieve that data with values replaced by using...
* var message:String = ResourceStringUtil.getResoureceStringWithTokens(
* "userSelectedProductMessage",
* {
* userName: "mims",
* productName: product.name,
* date: newDate()
* });
*/
static public function getResourceStringWithTokens(key:String, tokenValues:Object, bundle:String = ""):String {
if (bundle == "") { bundle = DEFAULT_BUNDLE; }
var string:String = ResourceManager.getInstance().getString(bundle, key);
// match tokens in the format %token%
var tokens:Array = string.match(/%[A-Za-z0-9]+%/g);
for each (var token:String in tokens) {
var propertyName:String = token.slice(1, token.length-1);
if (tokenValues[propertyName] != undefined && tokenValues[propertyName] != null) {
var value:String = String(tokenValues[propertyName]);
string = string.replace("%" + propertyName + "%", value);
} else {
//else just make that string blank.
string = string.replace("%" + propertyName + "%", "");
}
}
return string;
}
}
分享到:
相关推荐
介绍 Flex 项目 国际化的 具体方法
flex 入门介绍 flex 如何结合 j2ee 开发应用程序以及 flex 的国际化等
flex 国际化 可运行 资源文件 成功运行 flex4
Adobe Flex 3.2 语言参考.chm
flex3语言参考手册,对学习FLEX有很好的帮助。
Flex格式化代码工具 安装步骤参考readme.txt
Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex 代码格式化Flex ...
实现flex4窗体最大化 最小话 和关闭功能
NULL 博文链接:https://orientalpigeon.iteye.com/blog/910425
flex格式化插件,flex格式化插件,flex格式化插件
之前学习flex4.6时下载的flex4.6API帮助,打开太过缓了。经过我的优化,现在查询起来速度非常快。希望各位喜欢。
中文版,Flex4中文语言参考 chm格式 从官网压缩编制
Flex自定义组件,带最大化、最小化、还原及关闭按钮。
这样估计以后会有中文版的Flex2 了...),使用Flex2的本地化特性我们可以很容易创建多语言本地化的Flex应用,为我们的Flex应用打入国际市场添威助力,不过不像Java的 本地化资源动态获取的方式,目前Flex2的本地化...
Flex4语言参考手册 Flex4语言参考手册
FLEX3完全参考手册 完全适合自学者使用 内容齐全 希望对您有帮助
此为国际象棋的源文件,我对国际象棋玩的不好,了解的朋友可以多试试呵呵
Adobe Flex 4.1 语言参考。离线版
Flex 3.2 语言参考 离线版本 Flex3.2 API
Flex 3.2 语言参考 Flex 3.2 离线版 API