简体   繁体   中英

Converting strings to unicode as part of a maven build

I have some localisation resource files (eg messages_es.properties) which need to be in unicode in order to display properly in the browser. To avoid having to store unicode and non-unicode* versions of the resource files I'd like to incorporate a convert to unicode task into the maven build. Are there any easy methods/tools for doing this?

Example

label.button.loadMoreImages=CARGAR MÁS IMÁGENES -> label.button.loadMoreImages=CARGAR MÁS IMÁGENES

*much easier to work with when texts change and need re-translating

There's simple two ant tasks to convert native to ascii and back that could be arranged as targets like this

  <target name="native2ascii">
    <delete dir="${classes.dir}/resources" includes="*.properties" />
    <native2ascii encoding="cp1252" src="${source.dir}/resources" dest="${classes.dir}/resources" includes="*.properties" />
  </target>

  <target name="ascii2native">
    <native2ascii  encoding="cp1252" src="${classes.dir}/resources" dest="${resources.dir}"  includes="*.properties" reverse="true"/>
  </target>

That would be easy to adjust to your environment.

Your requirements are quite specific and I doubt you'll find a tool to do what you want. Consider writing your own Maven plugin .

First, you must take the properties file and decode the data. Properties files are generally stored in ISO 8859-1, but it is possible to perform your own character decoding by providing an InputStreamReader .

Next, you want to enumerate and XML-escape the non-ASCII values. Apache Commons Lang provides a type for doing that if you don't want to roll your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM