Extract all string from a java project

前端 未结 5 1714
青春惊慌失措
青春惊慌失措 2020-12-01 17:02

I have a rather big number of source files that I need parse and extract all string literals and put them in a file as play old java constant.
For exemple:



        
5条回答
  •  臣服心动
    2020-12-01 17:36

    I fully acknowledge what Pax Diablo said. We're using that function too.

    When applied to a class file the function "Externalize strings" will create two files, a class Messages.class and a properties file messages.properties. Then it will redirect all direct usages of string literals to a call to Messages.get(String key) and using the key you entered for the string in the "Ext. String" wizard.

    BTW: What's so bad about property files? As he said, you can just change the properties file and don't have to change the class if you need to change the text.

    Another advantage is this one: The way of extracting the string literals into a property file leaves you free to translate the source language in any language you want without modifying any code. The properties file loader loads the target language file automatically by using the corresponding file with the language iso code. So you don't have to worry about the platform your code runs on, it will select the appropriate language (nearly) automatically. See documentation of class ResourceBundle for how this works in detail.

提交回复
热议问题