开发者

Good Java property files editor

I work on an open-source Java project, and we have a lot of resource property files that contains localizable message resources. Those files are translated by volunteers to 20+ languages, and I'm a developer who primarily edits code.

In Java, resource files for different locales are grouped together by a naming convention. For example, if the default (normally English) resource is "foo.properties", Japanese resource is in "foo_ja.properties", French one is "foo_fr.properties", etc. For the sake of this question, let's call this group a "resource group."

Now, every so often, I need to refactor those resource files. In addition, I need the tool to support the basics of the property files. All in all, my list of requirements are something like:

  1. Renami开发者_开发百科ng property key name, and I want a tool to rename all the keys in all the files in the same group, without me individually going through them.
  2. Move a property from one resource group to another, and I want a tool to do so for each resource file in the group.
  3. In Java, resource files are in the ISO-8859-1 encoding and not in the platform default encoding.
  4. I don't want to see \uXXXX when editing/browsing property files, but I do expect the tool to preserve them.
  5. I don't want the tool to rearrange the order of properties in the resource file, nor mess with the comments. I expect the tool to preserve them.
  6. I want the tool to handle other syntax details of resource files, such as multiline text.

Unfortunately, I'm not finding any good tool that fits these criteria. I'm primarily an IntelliJ IDEA user, but it doesn't do #2 and #3. Eclipse built-in property file editor is even worse, and AFAICT it doesn't do #1, #2, #4. In fact it lacks the view that cuts across resource files in the same group. NetBeans is similarly primitive. The same goes for NetBeans, although it does #4.

Does anyone know of a good tool that fits the bill?


I used plugin for eclipse. I think this one: http://sourceforge.net/projects/eclipse-rbe/

It is OK, allows adding and renaming properties, shows warnings if property is not translated to all supported languages etc.

Its disadvantage is that it always uses `\uXXXX' notation for unicode characters. So, you must use this plugin to read created files. It makes search very hard. And I do not know whether it is possible to configure it to create UTF-8 encoded bundles.


Take a look at the online tool POEditor https://poeditor.com. Its project based.


Check out Multiproperties, if you are still looking for such a plugin:see here

Only #6 requirement is missing.


Properties Editor (Eclipse plugin) does #4 for sure. Never needed it for anything else.


Turns out IntelliJ should be able to do #3 (except it doesn't work in the current releasedue to a bug.) So that leaves me with just #2.

For the time being (and for the problem at hand) I decided that putting together a Groovy script is faster than trying out those tools:

#!/usr/bin/env groovy
// base name of the resource group to move a property from
File base = new File(args[0])
// key name of the property to move
String from = args[1]
// base name of the resource group to move the property to
File dst  = new File(args[2])
// name of the new property after move
String to = args[3]

/*
TODO:
  support multi-line
  insert the text in a better place, in the sort order
*/

base.parentFile.eachFileMatch(~"${base.name}(_.*)?\\.properties") { f ->
  def l = f.name.substring(base.name.length())
  println "${f}"

  def tmp = new File(f.path+".tmp")

  // delete this property from the source, and remember it
  def dropped = null;
  tmp.withWriter("iso-8859-1") { w ->
    f.filterLine(w,"iso-8859-1") { line ->
      if (line.startsWith(from)) {
        dropped = line;
        return false;
      } else {
        return true;
      }
    }
  }
  tmp.renameTo(f)

  if (dropped==null)    return; // nothing to copy to

  // append
  f = new File(dst.path+l)
  tmp = new File(f.path+".tmp")
  println "-> ${f}"

  existing = f.bytes
  needsLF = (existing[existing.length-1]!='\n')

  f.withWriterAppend("iso-8859-1") { w ->
    if (needsLF) w.write('\n')
    w.write(to+dropped.substring(from.length()))
    w.write('\n')
  }
}

This script is a hack and doesn't understand the property file syntax, so it's not terribly reliable. But VCS can compensate that downside by letting you see exactly what the script did.

I'm still hoping to find a good tool so that I'm more productive in a longer run. So please keep the answers coming!


At this point, I guess the answer is that there is no good property files editor in Java that matches the listed criteria. prbeditor sounded promising but it's gone, IntelliJ IDEA looks good on paper but is suffering a critical bug, and then the Eclipse plugins are all somewhat primitive.


I have been using prbeditor for some time now and I think it can handle the requirements you have:

  1. Can be done by changing the key column in the table view.
  2. Can be done by copying the key column which will actually copy the key and all the values in the different languages and then pasting it into a different table view, which will insert the key and values into the different columns of the table view.
  3. Characters can be escaped using \uXXXX, not sure if it does it only for non ISO-8591-1 characters or even for all non US-ASCII characters.
  4. \uXXXX is decoded for the editor and written back to the file as \uXXXX.
  5. The order of properties is not changed, not sure about how it handles comments.
  6. You can enter multiline text and it will correctly write to the properties file.


This is old but is a good tool.

JRC-Editor: http://zaval.org/products/jrc-editor/ it do all you except but re-ordering the keys (sort them) which may not be what you want. (May be this feature can be turned off)

Although it might not be good to re-order the keys, I found it very useful when lots of people work on one resource bundle. Source control tools, like SVN, have a better chance to merge the sorted resource bundles.


check out j18n http://j18n.nomagicsoftware.com It does what you want and introduces resource inheritance and also provides versioning for all edits

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜