2013-03-19 142 views
1

我有一些本地化資源文件(例如messages_es.properties)需要使用unicode才能在瀏覽器中正確顯示。爲了避免必須存儲資源文件的unicode和非unicode *版本,我想將轉換爲unicode任務併入到maven版本中。有沒有簡單的方法/工具來做到這一點?將字符串轉換爲unicode作爲maven版本的一部分

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

*容易得多,當文字變成工作,需要重新翻譯

+0

也許這可以幫助:http://stackoverflow.com/questions/8330485/how-to-convert-ascii-to-utf8-with-maven – 2013-03-19 11:00:06

+0

它可能會更好,如果您的翻譯使用適當的屬性文件編輯。 – McDowell 2013-03-19 11:10:17

+0

@McDowell - 不在我的控制範圍內 – wheresrhys 2013-03-19 11:29:49

回答

0

您的要求是非常具體的,我懷疑你會找到一個工具來做你想做的。考慮writing your own Maven plugin

首先,您必須獲取屬性文件並解碼數據。屬性文件通常存儲在ISO 8859-1中,但有可能通過提供InputStreamReader來提供perform your own character decoding

接下來,您想列舉和XML轉義非ASCII值。 Apache Commons Lang提供了一個類型來做到這一點,如果你不想推出自己的。

0

有簡單的兩個Ant任務本土轉換爲ASCII和背部,可能是排列爲這樣的目標

<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> 

這將很容易適應您的環境。

+0

1)海報正在使用Maven(儘管我意識到可以使用另一個)2)目標必須產生XML轉義;不是Java Unicode轉義。 – McDowell 2013-03-19 11:43:00

+0

@McDowell 1)它不能被集成到maven中嗎? 2)OP要求「轉換爲unicode」。 – 2013-03-19 11:47:39

相關問題