IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

六十四、9.2 I18n 与 Res

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

文章永久连接:https://tech.souyunku.com/?p=8272

I18n 对象可通过资源文件的 baseName 与 locale 参数获取到与之相对应的 Res 对象,Res 对象提供了 API 用来获取国际化数据。

以下给出具体使用步骤:

  • l创建 i18n_en_US.properties、 i18n_zh_CN.properties 资源文件, i18n 即为资源文件的baseName,可以是任意名称,在此示例中使用”i18n”作为 baseName

  • i18n_en_US.properties 文件中添加如下内容:msg=Hello {0}, today is{1}.

  • i18n_zh_CN.properties 文件中添加如下内容:msg=你好{0}, 今天是{1}.
  • 在 YourJFinalConfig 中使用 me.setI18nDefaultBaseName(“i18n”)配置资源文件默认 baseName

  • 特别注意,java 国际化规范要求 properties 文件的编辑需要使用专用的编辑器,否则会出 乱码,常用的有 Properties Editor,在此可以下载:http://www.oschina.net/p/properties+editor

以下是基于以上步骤以后的代码示例:

// 通过locale参数en_US得到对应的Res对象
Res resEn = I18n. use(“en_US”);
// 直接获取数据
String msgEn = resEn.get(“msg”);
// 获取数据并使用参数格式化
String msgEnFormat = resEn.format(“msg”, “james”, new Date());

// 通过locale参数zh_CN得到对应的Res对象
Res resZh = I18n. use(“zh_CN”);
// 直接获取数据
String msgZh = resZh.get(“msg”);
// 获取数据并使用参数格式化
String msgZhFormat = resZh.format(“msg”, “詹波”, new Date());

// 另外,I18n还可以加载未使用me.setI18nDefaultBaseName()配置过的资源文件,唯一的不同是
// 需要指定baseName参数,下面例子需要先创建otherRes_en_US.properties文件 Res otherRes = I18n. use(“otherRes”, “en_US”); otherRes.get(“msg”);

干货推荐


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(71) 打赏



未经允许不得转载:搜云库技术团队 » 六十四、9.2 I18n 与 Res

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367