要回答你的问题,我会选择(2)。
在实践中,我发现对我来说,使用别的东西而不是Java资源包要容易得多。
我个人使用不同的方式来处理这个。我使用gettext方式(在那里有一个名为GetTextResource.java的文件,您必须在应用程序中使用它才能从gettext扩展中受益 - 请参阅here)。
如果你对gettext很熟悉,你一定会发现这种方法更容易和实用。您只需向您的翻译人员提供po文件(可使用poedit进行编辑)。从po文件创建您将在您的应用程序中使用的java类(这是通过msgfmt完成的 - 为po文件的java编译指定参数)。使用xgettext命令(从命令行)可以很容易地更新Po文件。
当然,一切都在gettext manual之内。
优点:
的gettext为您提供了一种选择复数形式[没有更多的消息,如: “删除N文件(S)”(其中N是一个数字) - 看到ngettext。
因为一旦你的java文件与新的令牌
不需要访问使用一些宏每个字符串更新字符串翻译编写脚本的方法(如翻译(DELETE_BUTTON_MACRO))。你只写你这样的代码:
package translateutil;
import gnu.gettext.GettextResource;
import java.util.ResourceBundle;
import java.util.Locale;
public class TranslateUtil
{
private static ResourceBundle myResources =null;
public static boolean init(Locale loc, String resourceName)
{
boolean bRet = true;
Locale.setDefault(loc);
try
{
myResources = ResourceBundle.getBundle(resourceName);
System.out.printf( _("Current language: %s\n"),
Locale.getDefault().getDisplayName());
System.out.printf( _("%s resource found\n"),
myResources.getClass().getName());
}
catch(Exception e)
{
// let the application go on in English in case the ResourceBundle
// was not found. Notify about the error
bRet = false;
System.out.println(e.toString());
myResources = null;
}
return bRet;
}
public static String _(String str)
{
if (myResources == null)
{
return str;
}
{
return GettextResource.gettext(myResources, str);
}
}
public static String _Plural(String singular, String plural, long param)
{
if (myResources == null)
{
if (param == 1)
{
return singular;
}
else
{
return plural;
}
}
else
{
return GettextResource.ngettext(myResources, singular, plural, param);
}
}
}
下面是一个简单
// example
// similar for plural
import static translateutil.TranslateUtil._;
System.out.println(_("The english text"));
不管你的选择是什么:祝你好运!
来源
2010-09-15 22:13:36
INS
太棒了!我知道你在这里提出的很多东西,但是你已经通过组织它来澄清。希望未来的stackoverflowers会发现它很有用。 – jlarson 2010-09-16 13:18:23