优秀的 Java 属性文件编辑器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5164910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:46:18  来源:igfitidea点击:

Good Java property files editor

javaideresourcespropertieseditor

提问by Kohsuke Kawaguchi

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.

我在一个开源 Java 项目上工作,我们有很多包含可本地化消息资源的资源属性文件。这些文件由志愿者翻译成 20 多种语言,我是一名主要编辑代码的开发人员。

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

在 Java 中,不同语言环境的资源文件按命名约定组合在一起。例如,如果默认(通常是英文)资源是“foo.properties”,日文资源在“foo_ja.properties”,法文资源是“foo_fr.properties”等。为了这个问题,我们就叫这个组一个“资源组”。

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. Renaming 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.
  1. 重命名属性键名称,我想要一个工具来重命名同一组中所有文件中的所有键,而无需我单独遍历它们。
  2. 将属性从一个资源组移动到另一个资源组,我想要一个工具为组中的每个资源文件执行此操作。
  3. 在 Java 中,资源文件采用 ISO-8859-1 编码,而不是平台默认编码。
  4. 我不想在编辑/浏览属性文件时看到 \uXXXX,但我确实希望该工具能够保留它们。
  5. 我不希望该工具重新排列资源文件中的属性顺序,也不希望弄乱注释。我希望该工具能够保存它们。
  6. 我希望该工具能够处理资源文件的其他语法细节,例如多行文本。

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.

不幸的是,我没有找到任何符合这些标准的好工具。我主要是 IntelliJ IDEA 用户,但它不做 #2 和 #3。Eclipse 内置的属性文件编辑器更糟糕,而且 AFAICT 它不做 #1、#2、#4。事实上,它缺乏跨同一组中的资源文件的视图。NetBeans 同样是原始的。NetBeans 也是如此,尽管它是 #4。

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

有谁知道适合该法案的好工具?

采纳答案by Kohsuke Kawaguchi

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.

在这一点上,我猜答案是 Java 中没有符合所列条件的好的属性文件编辑器。prbeditor 听起来很有希望,但它已经消失了,IntelliJ IDEA 在纸面上看起来不错,但遇到了一个严重的错误,然后 Eclipse 插件都有些原始。

回答by AlexR

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

我使用了eclipse插件。我认为这个: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.

它的缺点是它总是使用 `\uXXXX' 表示 unicode 字符。因此,您必须使用此插件来读取创建的文件。它使搜索变得非常困难。而且我不知道是否可以将其配置为创建 UTF-8 编码的包。

回答by skzs

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

如果您仍在寻找这样的插件,请查看Multiproperties请参见此处

Only #6 requirement is missing.

仅缺少 #6 要求。

回答by OblongZebra

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

看看在线工具 POEditor https://poeditor.com。其项目为基础。

回答by mihn

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

属性编辑器(Eclipse 插件)确实是#4。从来不需要它做其他事情。

回答by Kohsuke Kawaguchi

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.

事实证明 IntelliJ 应该能够做到 #3(除非它在当前版本中由于错误而不起作用。)所以我只剩下 #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:

就目前而言(以及手头的问题),我决定将 Groovy 脚本放在一起比尝试这些工具要快:

#!/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.

这个脚本是一个黑客,不理解属性文件的语法,所以它不是非常可靠。但是 VCS 可以通过让您确切地看到脚本的作用来弥补这一缺点。

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!

我仍然希望找到一个好的工具,以便从长远来看我的工作效率更高。所以请继续回答!

回答by Reboot

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

我已经使用prbeditor一段时间了,我认为它可以满足您的要求:

  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.
  1. 可以通过更改表视图中的键列来完成。
  2. 可以通过复制键列来完成,该列实际上将复制键和不同语言的所有值,然后将其粘贴到不同的表视图中,这会将键和值插入到表视图的不同列中。
  3. 字符可以使用 \uXXXX 进行转义,不确定它是否仅对非 ISO-8591-1 字符或所有非 US-ASCII 字符进行转义。
  4. \uXXXX 被编辑器解码并作为 \uXXXX 写回文件。
  5. 属性的顺序没有改变,不确定它是如何处理注释的。
  6. 您可以输入多行文本,它将正确写入属性文件。

回答by Alireza Fattahi

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)

JRC-Editor:http: //zaval.org/products/jrc-editor/它可以为您完成所有工作,除了重新排序可能不是您想要的键(对它们进行排序)。(可能是这个功能可以关掉)

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.

虽然重新排序密钥可能不太好,但我发现当很多人在一个资源包上工作时它非常有用。源代码控制工具,如 SVN,有更好的机会合并已排序的资源包。

回答by james

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

查看 j18n http://j18n.nomagicsoftware.com它可以满足您的需求并引入资源继承,还为所有编辑提供版本控制