1 Reply Latest reply: Aug 27, 2009 12:40 PM by 800459 RSS

    How to do to change from a language to an other language on a frame?

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

      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) {
                System.out.println("hello message:" + bundle.getString("menu"));
                System.out.println("goodbye message:" + bundle.getString("about"));
                System.out.println();
           }
      }
      public class incercare{

           public static void main (String args[])throws Exception{
           
                TestMenu2 t=new TestMenu2("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

      Edited by: Ravanelly on Aug 21, 2009 2:02 AM
        • 1. Re: How to do to change from a language to an other language on a frame?
          800459
          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?
          You need to pass back user selected locale and use that while getting localized message from class ResourceBundle, that should work.
          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.
          The resourcebundles(properties files) should be on classpath, then only class ResourceBundle will be able to use them.