Good Java property files editor

99封情书 提交于 2019-12-02 17:57:19

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.

skzs

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!