gpt4 book ai didi

java - 如何用LWUIT解决本地化问题

转载 作者:行者123 更新时间:2023-12-01 05:42:00 26 4
gpt4 key购买 nike

我用一个 textField 和命令制作了一个简单的表单,我想要两种语言:波斯语和英语,以便我可以在运行时根据需要使用它们。

我使用 ResourceEditor 进行了一些翻译,并将它们保存在 English.resFarsi.res 名称下,然后将它们添加到我的资源中.

现在我在调用本地化方法时遇到问题,因为我不知道该怎么做。我将在这里发布我的代码,请纠正我。

这是我的代码:

public class Midlet extends javax.microedition.midlet.MIDlet {

private Hashtable locale;

public void startApp() {
Display.init(this);

try {
Resources res = Resources.open("/Lang.res");
//Lang.res is resource file where these languages are stored
// using resoureEditor.
locale = res.getL10N("English.res", "en");

/* See text below. */
} catch (IOException ex) {
ex.printStackTrace();
}

Form main = new Form((String) locale.get("FORM"));
main.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

Label label = new Label((String) locale.get("NAME"));
TextField tf1 = new TextField("");
Button button = new Button((String) locale.get("OK"));

main.addComponent(label);
main.addComponent(tf1);
main.addComponent(button);

main.addCommand(new Command((String) locale.get("BACK")) {
public void actionPerformed(ActionEvent evt) {}
});
main.show();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}

这是我的English.res:

#Export locale from the Theme Creator
#Tue Aug 02 19:35:55 IRDT 2011
FORM=form
OK=ok
BACK=back
NAME=name

try block 中的这两行正确吗?

       Resources res = Resources.open("/Lang.res");    
locale = res.getL10N("English.res", "en");

Lang.res 是使用 resoureEditor 存储这些语言的资源文件。

我还需要做什么?

我在第一行遇到异常。 en 是所需语言区域的名称,与 res 文件中的值列匹配。

我仍然不确定它是否正确,但是,第一个参数是什么?区域设置?

最佳答案

我建议使用“资源编辑器”来创建L10N资源,它可以与gui同步,使这个任务更容易完成,并且很容易在代码中检索。

try {
Constants.res = Resources.open("/Lang.res");
} catch (Exception e){
System.err.println("can't load resource file:" + e);
}
Hashtable h = Constants.res.getL10N("English.res","en");

关于java - 如何用LWUIT解决本地化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6915087/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com