ResourceBundle.getBundle can’t work(update problem)

hi~

Question 1:When I tried to translate things in my code to Chinese by using Localizing, I found that it just didn’t work and I don’t know why…

here is my code, it is a sample from wiki.

second is my translation file - Lang_zh, I placed it on the file where Screen3.java and the src file on

I got “can’t find resource for bundle java.util.PropertyResourceBundle,key nice game” for error message



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.system.AppSettings;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.builder.ImageBuilder;

import de.lessvoid.nifty.builder.LayerBuilder;

import de.lessvoid.nifty.builder.PanelBuilder;

import de.lessvoid.nifty.builder.ScreenBuilder;

import de.lessvoid.nifty.builder.TextBuilder;

import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;

import de.lessvoid.nifty.controls.label.builder.LabelBuilder;

import java.util.ResourceBundle;



/**

  • This demo shows a two-screen layout in Nifty’s Java syntax.
  • You see two screens with two layers each, containing several panels.
  • The panels contain images, text, and controls (label and buttons).
  • Buttons have an interaction defined, and some of the text
  • is dynamically defined, using the MyStartScreen controller.
  • @author iamcreasy

    */

    public class Screen3 extends SimpleApplication {

    private static Screen3 app;



    public static void main(String[] args) {

    app = new Screen3();

    AppSettings settings = new AppSettings(true);

    settings.setResolution(640, 480);

    app.setShowSettings(false); // splashscreen

    app.setSettings(settings);

    app.start();

    }



    @Override

    public void simpleInitApp() {

    app.setDisplayFps(false);

    app.setDisplayStatView(false);

    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

    assetManager, inputManager, audioRenderer, guiViewPort);

    Nifty nifty = niftyDisplay.getNifty();

    guiViewPort.addProcessor(niftyDisplay);

    flyCam.setDragToRotate(true);

    nifty.loadStyleFile("nifty-default-styles.xml");

    nifty.loadControlFile("nifty-default-controls.xml");



    // <screen>

    nifty.addScreen("start", new ScreenBuilder("start") {{

    controller(new mygame.MyStartScreen());

    layer(new LayerBuilder("background") {{

    childLayoutCenter();



    // add image

    image(new ImageBuilder() {{

    filename("Interface/start-background.png");

    }});



    }});



    layer(new LayerBuilder("foreground") {{

    childLayoutVertical();



    // panel added

    panel(new PanelBuilder("panel_top") {{

    childLayoutCenter();

    alignCenter();

    height("25%");

    width("75%");



    // add text

    text(new TextBuilder() {{

    text(ResourceBundle.getBundle("Lang").getString("nice Game"));

    font("Interface/Fonts/Default.fnt");

    height("100%");

    width("100%");

    }});



    }});



    panel(new PanelBuilder("panel_mid") {{

    childLayoutCenter();

    alignCenter();

    height("50%");

    width("75%");



    // add text

    text(new TextBuilder() {{

    text(ResourceBundle.getBundle("Lang").getString("hello World"));

    wrap(true);

    height("100%");

    width("100%");

    }});



    }});



    panel(new PanelBuilder("panel_bottom") {{

    childLayoutHorizontal();

    alignCenter();

    height("25%");

    width("75%");



    panel(new PanelBuilder("panel_bottom_left") {{

    childLayoutCenter();

    valignCenter();

    height("50%");

    width("50%");



    // add button controlStart")"{{

    control(new ButtonBuilder("StartButton", ResourceBundle.getBundle("Lang").getString("Start")){{

    alignCenter();

    valignCenter();

    height("50%");

    width("50%");

    visibleToMouse(true);

    interactOnClick("startGame(hud)");

    }});



    }});



    panel(new PanelBuilder("panel_bottom_right") {{

    childLayoutCenter();

    valignCenter();

    height("50%");

    width("50%");



    // add button control

    control(new ButtonBuilder("QuitButton", ResourceBundle.getBundle("Lang").getString("Quit")){{

    alignCenter();

    valignCenter();

    height("50%");

    width("50%");

    visibleToMouse(true);

    interactOnClick("quitGame()");

    }});



    }});

    }}); // panel added

    }});



    }}.build(nifty));





    nifty.addScreen("hud", new ScreenBuilder("hud") {{

    controller(new mygame.MyStartScreen());



    layer(new LayerBuilder("background") {{

    childLayoutCenter();



    // add image

    image(new ImageBuilder() {{

    filename("Interface/hud-frame.png");

    }});



    }});



    layer(new LayerBuilder("foreground") {{

    childLayoutHorizontal();



    // panel added

    panel(new PanelBuilder("panel_left") {{

    childLayoutVertical();

    height("100%");

    width("80%");

    // <!-- spacer -->

    }});



    panel(new PanelBuilder("panel_right") {{

    childLayoutVertical();

    height("100%");

    width("20%");



    panel(new PanelBuilder("panel_top_right1") {{

    childLayoutCenter();

    height("15%");

    width("100%");



    // add label control

    control(new LabelBuilder(){{

    id("score");

    color("#000");

    text("123");

    width("100%");

    height("100%");

    }});



    }});



    panel(new PanelBuilder("panel_top_right2") {{

    childLayoutCenter();

    height("15%");

    width("100%");



    // add image

    image(new ImageBuilder() {{

    filename("Interface/face1.png");

    valignCenter();

    alignCenter();

    height("50%");

    width("30%");

    }});



    }});



    panel(new PanelBuilder("panel_bot_right") {{

    childLayoutCenter();

    valignCenter();

    height("70%");

    width("100%");

    }});

    }}); // panel added

    }});

    }}.build(nifty));



    nifty.gotoScreen("start"); // start the screen

    //nifty.gotoScreen("hud"); // start the screen

    }

    }

    [/java]



    Lang_zh.properties

    nice Game = 好遊戲

    hello World = 你好世界

    Start = 開始遊戲

    Quit = 離開



    Thank you for help me.

    Hope people who help me will get million yearly salary^^

I don’t think spaces are legal in property file keys…



You will also run into problems with BitMapFont files unless you generate one containing the Chinese characters.

zarch said:
I don't think spaces are legal in property file keys...


Zarch is right, white-space characters must be escaped if they are to be part of the key. Best to avoid space ' ', colon : and equal = in they key since they are used as separators.

Property files must be encoded as iso-8859-1, for characters not in that set they must be unicode escaped, that can be done with the native2ascii tool in the JDK.

http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/native2ascii.html

Wikipedia actually have a very good summary of these rules: http://en.wikipedia.org/wiki/.properties

And please next time save our eyes when putting code in a post:

Thank you people who help me

hope you get million dollor salary


update: I follow zarch's advice, make no space in the bundle file, however, the problem is still here
and I am not quite understanding what jmaasing was talking about when I clicked into the website he gave.
I save the properties file as format UTF-8, isn't it correct?

Lang_zh.properties
nice=好
hello=你好
Start=開始
Quit=離開

error message:
can't find resource for bundle java.util.propertyresourcebundle key nice

I have one more question, the question is: did I wrong that I put the properties file on the src file?If I was wrong, where do I put into?

I finally solve my problem but just like what zarch said, I have a new problem that with bitmap fonts…

Thank you everyone

1 Like