如何用纯阿拉伯文本实现struts2i18n



我使用的是Struts 2,有i18n的需求,我已经创建了全局&global_ar属性文件,对于英语的所有字符都正确显示,以前我将所有阿拉伯文本转换为UTF-8代码,此时应用程序工作良好,但是当我将其更改为普通阿拉伯文本时,它停止工作,在浏览器中为阿拉伯文本显示一些奇怪的字符。

JSP文件

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@ taglib prefix="t" tagdir="/WEB-INF/tags/custom_tag"%> 
<t:template> 
   <s:form action="visitations.action" id="visitationForm" theme="simple" method="post">  </s:form>     
<s:text name="country" />:<span class="required">*</span>
</t:template>

使用native2ascii将字符集转换为ASCII。这是消息资源所需的编码。

假设resourcessrc文件夹下的第一个目录,其中包含需要转换的消息属性文件。使用ant

<target name="native2ascii">
  <delete dir="${classes.dir}/resources" includes="*.properties" />
  <native2ascii encoding="cp1256" src="${source.dir}/resources" dest="${classes.dir}/resources" includes="*.properties" />
  <copy todir="${exploaded.dir}/WEB-INF/classes/resources">
    <fileset dir="${classes.dir}/resources" includes="*.properties" />
  </copy>
</target>

在每个构建上运行此脚本,您可能应该自定义它以正确地翻译它,选择文件本机编码的编码字符集。

可以找到JVM支持的一些字符编码:

最新更新