zoukankan      html  css  js  c++  java
  • 【Struts2复习知识点二十三】 国际化I18N处理

    struts.xml

    <constant name="struts.custom.i18n.resources" value="app"></constant>

    资源文件的名称为 app_*_*.properties

    app_en_US.properties

    View Code
    login.username=username:
    login.password=password:
    login.login=login
    welcome.msg=welcome:{0}

    app_zh_CN.properties

    View Code
    login.username=\u7528\u6237\u540d\uff1a
    login.password=\u5bc6 \u7801\uff1a
    login.login=\u767b\u5f55
    welcome.msg=\u6b22\u8fce\u4f60\uff1a{0}

    在jsp中取值:

    View Code
    <s:property value="getText('login.username')"/> <input name="username" />
    <s:property value="getText('login.password')"/><input name="password" type="password" />
    <input type="submit" value="<s:property value="getText('login.login')"/>" />

    getTest()方法为action的父类继承的方法。

    带参数的取值:

    welcome.msg=welcome:{0} 可以定义动态参数,{0}占位。

    View Code
    <s:text name="welcome.msg">
    <s:param value="username"></s:param>
    </s:text>

    用<s:text>取值,用<s:param>赋值。

    动态的语言切换

    View Code
    <a href="admin/lang?request_locale=en_US">en</a>
    <a href="admin/lang?request_locale=zh_CN">cn</a>

    request_locale 会自动解析。

    用<s:debug>跟踪 会发现,在action及session中存了相关信息,保证每个页面都用此语言解析。

     



  • 相关阅读:
    使用Docker搭建Wordpress
    Django开发Web页面html增加判断展示
    Python如何取小数点位数
    html内容可编写
    MySQL 设置 非空约束依然能插进去的办法
    Git拉取远程所有分支
    my.ini 配置文件
    node
    TP upload 上传根目录不存在
    linux 安装 memcache
  • 原文地址:https://www.cnblogs.com/surge/p/2368585.html
Copyright © 2011-2022 走看看