Results 1 to 5 of 5
  1. #1
    KingdomX is offline Member
    Join Date
    Dec 2011
    Location
    Brazil
    Posts
    26
    Rep Power
    0

    Question Help with multilingual website through Java

    I'm trying to create a multilingual website the way i used to do on PHP, but i'm unable to achieve the final aspect of the structuring... Here's how it works:

    I have the language class which will set the chosen website language for the user... The string Lang below holds the package name/structure on the project so that it can determine which package to access:
    Java Code:
    package Language;
    
    public class Language {
        private Integer UserLang;
        public String[] Lang = new String[3];
        
        public Language(){
            this.Lang[0] = "enUS"; 
            this.Lang[1] = "ptBR"; 
            this.Lang[2] = "esES"; 
        }
    }
    Then, i have all the three packages similar to this (as you can see, the same structuring and same Java file name):
    Java Code:
    package Language.enUS;
    
    public class gamerslustPortal {
        public String test = "test from inside the Language.enUS";
    }
    Java Code:
    package Language.ptBR;
    
    public class gamerslustPortal {
        public String test = "test from inside the Language.ptBR";
    }
    Java Code:
    package Language.esES;
    
    public class gamerslustPortal {
        public String test = "test from inside the Language.esES";
    }
    From the main portal then, i'm trying to access the specific class from the package:
    Java Code:
            Language lang = new Language();
            page import="Language."+Lang.lang[0]+".gamerslustPortal"; // enUS
    Since the Java file from the 3 different languages have the same name, i can then create a language system that simply swaps the package folder and read the same string name on the same Java file name, but on a different package.

    The problem is that the "page import" won't work the way i want it to.

    Any ideas on how to do this? Perhaps another way?

    Thanks in advance!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default Re: Help with multilingual website through Java

    The problem is that the "page import" won't work the way i want it to.
    Can you show what the code does and explain why it is not the way you want it to work?
    And explain what is the way you want it to work.

    Have you looked at the ResourceBundle class?
    Last edited by Norm; 01-01-2012 at 09:18 PM.

  3. #3
    KingdomX is offline Member
    Join Date
    Dec 2011
    Location
    Brazil
    Posts
    26
    Rep Power
    0

    Default Re: Help with multilingual website through Java

    Hmmmm, i'm not sure as how to go on explaining it better...

    Basically i want to dinamically read a different Java file with the localized string inside:
    Java Code:
    Language lang = new Language();
    page import="Language."+Lang.lang[0]+".gamerslustPortal"; // enUS
    page import="Language."+Lang.lang[1]+".gamerslustPortal"; // ptBR
    page import="Language."+Lang.lang[2]+".gamerslustPortal"; // esES
    I'm going to have a look at this ResourceBundle class you mentioned too.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default Re: Help with multilingual website through Java

    page import="L...
    What is the datatype of page? The stuff to the right of the = looks like a String.
    Also import is a keyword and can't be used as a variable name.

  5. #5
    KingdomX is offline Member
    Join Date
    Dec 2011
    Location
    Brazil
    Posts
    26
    Rep Power
    0

    Thumbs up Re: Help with multilingual website through Java

    Thank you! After some research i managed to do what i wanted with ResourceBundle Class!

    Solved! Thanks! Here's the code for further search reference:

    gamerslustPortal.properties (file located under Language.enUS package)
    Java Code:
    test = test from inside the .property file
    Language.java (class created to make a dynamic chance on the website language.
    Java Code:
    package Language;
    
    public class Language {
        private Integer UserLang;
        public String[] Lang = new String[3];
        
        public Language(){
            this.Lang[0] = "enUS"; 
            this.Lang[1] = "ptBR"; 
            this.Lang[2] = "esES"; 
        }
    }
    index.jsp
    Java Code:
    <%@ page import="java.util.ResourceBundle"%>
    
    Language lang = new Language();
            String MESSAGES_PROPERTIES = "Language."+lang.Lang[0]+".gamerslustPortal";  
            ResourceBundle labels = ResourceBundle.getBundle(MESSAGES_PROPERTIES);
            String value = labels.getString("test");
            out.print(value);

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2011, 03:28 AM
  2. Java website
    By Eleeist in forum New To Java
    Replies: 5
    Last Post: 05-05-2011, 09:21 AM
  3. Java and Website
    By Fares in forum Advanced Java
    Replies: 3
    Last Post: 11-14-2010, 02:22 PM
  4. Multilingual application in struts
    By twinklingstar in forum Web Frameworks
    Replies: 0
    Last Post: 10-04-2010, 09:40 AM
  5. How to download website (Get all link in website)
    By finalmem in forum Advanced Java
    Replies: 0
    Last Post: 11-12-2008, 08:43 AM

Posting Permissions

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