Results 1 to 6 of 6
  1. #1
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Smile How to do to change from a language to an other language?

    Hello,

    I want to know how i have to do when i choice a language example from english to french(a lot of them) all the words from english are translated in french.Example the program below how i implement?
    When a do a system.out.println apeared ok in console, but i want to change on frame?how to do concrete?

    And other question where i put the .properties files?I put in the same package like the class but don't appeared nothing....and when i putted in src package it's was ok.

    I hope I posted on the right Post.

    Please help I'm a beginner :)
    Thanks a lot for you time


    The code:

    package inter;

    import java.awt.BorderLayout;
    import java.awt.Choice;
    import java.awt.Frame;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Locale;
    import java.util.ResourceBundle;

    class TestMenu2a extends Frame implements ActionListener, ItemListener{
    Label nord;
    Frame f;
    Choice c,cro,cen;
    public ResourceBundle captro,capten;
    public Locale localro=new Locale("ro", "RO"),localen;
    String language,country;
    @SuppressWarnings("deprecation")
    public TestMenu2a (String titlu){
    super(titlu);
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    //dispose();
    System.exit(0);
    }
    });
    setLayout(new GridLayout(10,3));
    nord=new Label("About", Label.CENTER);
    c=new Choice();

    c.add("Romana");
    c.add("Engleza");

    add(nord,BorderLayout.NORTH);
    add(c);
    pack();
    show();
    c.addItemListener(this);
    }

    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    System.exit(0);
    }

    public void itemStateChanged(ItemEvent e) {
    // TODO Auto-generated method stub
    if (c.getName()=="Romana")
    System.out.println("aloha");
    localro=new Locale("ro", "RO");
    captro=ResourceBundle.getBundle("TestMenu2Pmessage ",localro);
    displayValues(captro);

    if (c.getName()=="Engleza")
    System.out.println("englezaaaa");
    localen=new Locale("en", "EN");
    capten=ResourceBundle.getBundle("TestMenu2Pmessage ",localen);
    displayValues(capten);

    }


    public static void displayValues(ResourceBundle bundle) {
    //String a,b;
    //a=bundle.getString("menu");
    //b=bundle.getString("menu");


    System.out.println("hello message:" + bundle.getString("menu"));
    System.out.println("goodbye message:" + bundle.getString("about"));
    System.out.println();
    }
    }
    public class intern{

    public static void main (String args[])throws Exception{

    TestMenu2a t=new TestMenu2a("Menu");
    t.setSize(150, 120);
    t.show();

    }
    }



    The .properties files:

    TestMenu2Pmessage_en_EN.properties
    menu=Menu
    about=About

    TestMenu2Pmessage_ro_RO.properties
    menu=Meniu
    about=Despre

    TestMenu2Pmessage.properties
    menu=Menu
    about=About
    Attached Files Attached Files

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    812
    Rep Power
    6

    Default

    Hi,
    You have to put proper comments.We can't give solution by studying each and every line of code.Your comments makes us to trace the issue faster.

    let me ask some questions.

    1.In the below block ,do u think c.getName() will print what u expect? First put S.O.P.Ur if condition will never be true.

    2.To get the selected Item from choice u need to use this method c.getSelectedItem().

    public void itemStateChanged(ItemEvent e) {
    // TODO Auto-generated method stub
    if (c.getName()=="Romana")
    System.out.println("aloha");
    localro=new Locale("ro", "RO");
    captro=ResourceBundle.getBundle("TestMenu2Pmessage ",localro);
    displayValues(captro);

    if (c.getName()=="Engleza")
    System.out.println("englezaaaa");
    localen=new Locale("en", "EN");
    capten=ResourceBundle.getBundle("TestMenu2Pmessage ",localen);
    displayValues(capten);

    }
    Ramya:cool:

  3. #3
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default

    Yes you have right i puted c.getSelectedItem() and work and appeared ok in console..now i want to change the name and on frame
    What you mean by "First put S.O.P.Ur if condition will never be true."
    I don't understand what is the signification of S.O.P.Ur .
    Last edited by Ravanelly; 08-21-2009 at 04:02 PM.

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    812
    Rep Power
    6

    Default

    Hi,
    I asked you to put S.O.P for debugging sake.

    Just change the method block like this below

    Java Code:
     public void itemStateChanged(ItemEvent e) {
    		// TODO Auto-generated method stub
    		System.out.println(c.getName());
    		if (c.getSelectedItem().equals("Romana"))
    		{
    			localro=new Locale("ro", "RO");
    			captro=ResourceBundle.getBundle("TestMenu2Pmessage",localro);
    			displayValues(captro);
    		}
    		if (c.getSelectedItem().equals("Engleza"))
    		{
    
    			localen=new Locale("en", "EN");
    			capten=ResourceBundle.getBundle("TestMenu2Pmessage",localen);
    			displayValues(capten);
    		}
    	}
    	
    
    	public  void displayValues(ResourceBundle bundle) {
    		//String a,b;
    		//a=bundle.getString("menu");
    		//b=bundle.getString("menu");
    		
    		System.out.println("hello message:" + bundle.getString("menu"));
    		nord.setText(bundle.getString("menu"));
    		System.out.println("goodbye message:" + bundle.getString("about"));
    		nord.setText(bundle.getString("about"));
    		
    	}
    Ramya:cool:

  5. #5
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    I think S.O.P. is short for System.out.println(), used to print stuff out to the console. Useful to check values of fields at moments.

  6. #6
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default

    thanks,
    for your time I realize my mistakes.

    Have a nice day guys :)

Similar Threads

  1. Is this the right language?
    By rws in forum New To Java
    Replies: 9
    Last Post: 11-15-2008, 03:27 PM
  2. IDE for new language
    By mitra2008 in forum Eclipse
    Replies: 2
    Last Post: 06-23-2008, 06:43 PM
  3. Application in language bar!
    By rameshraj in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 04:41 PM
  4. V language 0.004
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-19-2007, 03:18 PM
  5. TOM programming language 2.5
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-14-2007, 08:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •