Struts2 : internationalize s:date?

前端 未结 2 1616
眼角桃花
眼角桃花 2021-01-24 20:46

works perfectly for fomatting my date to the french standard. But It\'s hard-written in my jsp. So I ha

相关标签:
2条回答
  • 2021-01-24 21:33

    Create localized date format inside your properties files, e.g. with struts.date.format key:

    struts.date.format = dd.MM.yyyy
    

    And use getText method to get this date format in <s:date> tag format attribute:

    <s:date name="date" format="%{getText('struts.datetime.format')}"/>
    
    0 讨论(0)
  • 2021-01-24 21:34

    Absolutely. Internationalization (i18n) is handled out-of-the-box in almost every framework out there, then it's better to spend time on understand how to make it works than to write some unneded, buggy custom solution.

    With Struts2, you must ensure to have:

    • I18nInterceptor in your Interceptor Stack;
    • I18nInterceptor defined in struts.xml: <constant name="struts.custom.i18n.resources" value="global" />;
    • the localized, correctly named global.properties file for each locale you want to handle;
    • the request_locale` parameter (if you have not changed the language in your browser) when calling your Actions, giving the I18nInterceptor the ability to hijack the request to the correct resource;
    • an appropriate character encoding on your pages: <%@ page contentType=”text/html;charset=UTF-8″ %>.

    Take a look at the guides available on the web too:

    http://www.mkyong.com/struts2/struts-2-i18n-or-localization-example/

    http://www.2bloggers.com/2011/12/localization-i18n-in-struts2.html

    http://www.roseindia.net/struts/struts/struts2.2.1/tags/i18ntag.html

    http://www.roseindia.net/struts/strutsinternationalization.shtml

    http://www.roseindia.net/tutorials/I18N/internationalison-code.shtml

    0 讨论(0)
提交回复
热议问题