Results 1 to 6 of 6

Thread: Adding a new language to a project

Hybrid View

  1. #1

    Default Adding a new language to a project

    Hi there !

    I created a new project with SpringRoo 1.2.
    I used the reverse engineering to generate all the BO objects, the service layer and the UI pages.

    Now I try to internationalize my application.

    I added the 6 languages handled by default by SpringRoo without any trouble.

    Now I have several questions :

    1) why are there only 6 languages handled by default ? I saw several properties files for other languages on internet : maybe they could be added ?

    2) I tried to add new languages but it is very hard (at least for me...). I didn't understand the story about creating an i18n project ... but I found two existing project around French and Russian. I tried to add them using those two Roo commands :
    Code:
    osgi start --url http://spring-roo-addon-mvc-i18n-russian.googlecode.com/svn/repo/net/dzmitryb/roo/addon/mvc/russian/net.dzmitryb.roo.addon.mvc.russian/0.1.0.BUILD/net.dzmitryb.roo.addon.mvc.russian-0.1.0.BUILD.jar
    osgi start --url http://code.google.com/p/fr-test/source/browse/repo/org/springframework/roo/addon/i18n/french/org.springframework.roo.addon.i18n.french/0.1.0.RELEASE/org.springframework.roo.addon.i18n.french-0.1.0.RELEASE.jar
    ... but this didn't work :'(
    The first one added the messages_ru.properties file, the russian flag icon and changed the footer.jspx file ! But when I cliqued on the flag, I had the english language ...
    I created the messages_fr.properties file, added the expected icon and changed the footer.jspx file ... same result !
    I tried a lot of changes, install, uninstall, and ... suddenly, I don't know why, but it worked !

    3) now I try to add portuguese language ... I added the properties file, the icon and changed the footer.jspx file ... but it doesn't work :'(
    My question main is : all the structure is set so that the application can switch from one language to another, just by specifying the 2 letters country code :
    Code:
    <util:language label="English" locale="en"/>
    OR
    <util:language label="Français" locale="fr"/>
    So why isn't it possible to simply add a new property file and a new button to make it works ?

    Thanks in advance for attention.


    Cédric VIDREQUIN.

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Roo has a convenient, built-in add-on discovery mechanism which does exactly what you need:


    Code:
    roo> addon search french
    1 found, sorted by rank; T = trusted developer; R = Roo 1.2 compatible
    ID T R DESCRIPTION -------------------------------------------------------------
    01 Y - 0.1.0.BUILD France language support for Spring Roo Web MVC JSP
           Scaffolding
    --------------------------------------------------------------------------------
    [HINT] use 'addon info id --searchResultId ..' to see details about a search result
    [HINT] use 'addon install id --searchResultId ..' to install a specific search result, or
    [HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version
    ~.web roo> addon install id 1
    Target resource(s):
    -------------------
       spring-roo-addon-french (0.1.0.BUILD)
    
    Deploying...done.
    
    Successfully installed add-on: spring-roo-addon-french [version: 0.1.0.BUILD]
    [Hint] Please consider rating this add-on with the following command:
    [Hint] addon feedback bundle --bundleSymbolicName org.springframework.roo.addon.french --rating ... --comment "..."
    ~.web roo> web mvc language --code fr
    ec3fc44 Created SRC_MAIN_WEBAPP/WEB-INF/i18n/messages_fr.properties
    0f67f12 Created SRC_MAIN_WEBAPP/images/fr.png
    46d0f10 Updated SRC_MAIN_WEBAPP/WEB-INF/views/footer.jspx
    This is also documented in our reference guide. The i18n addon creation steps are outlined here and here.

    HTH,
    Stefan
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #3

    Default

    Hello Stefan,

    thank you for taking time to have a look at my problem !

    As I said in my previous message, I managed to make work the French and the Russian languages, using the add-on discovery mechanism and some web search.

    The problem I have is : how adding a new language that is not supplied in the add-on list ?
    I'm trying to add Portuguese language : I have the messages_pt.properties file and the flag icon, I tried to create the i18n stuffs like this (but it fails) :
    Code:
    roo> addon create i18n --topLevelPackage com.myCompany.myProject --locale pt --messageBundle SpringRooI18nAddons/pt/messages_pt.properties
    Command 'addon create i18n --topLevelPackage com.vialtis.ferry --locale pt --messageBundle SpringRooI18nAddons/pt/messages_pt.properties' was found but is not currently available (type 'help' then ENTER to learn about this command)
    Did I miss something ?

    Cédric.

  4. #4
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    The addon create command will only work in empty directories. This is because it will create a complete new project for your addon so you can package it as a (OSGi-ready jar bundle, and potentially make it available to other Roo users). Once you have created your addon project and packaged it (mvn package) you can install the addon:

    Code:
    roo> osgi start --url file:///<path-to-jar>foo.jar
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  5. #5
    Join Date
    Aug 2012
    Location
    BiH, Sarajevo
    Posts
    1

    Default

    Hi I'm having problems too when "Adding a new language to a project"
    I want to make locale for Bosnian language in Latin and Cyrillic (http://en.wikipedia.org/wiki/Bosnian_language) So i will have to commands
    //Cyrillic
    addon create i18n --topLevelPackage spring.roo.addon.mvc.i18n.bosnian.Cyrillic --locale bs_cy --messageBundle messages_bs-Cyrl-BA.properties --language Bosanski --flaggraphic bs.png --description "Localization for Bosnian Cyrillic"

    //latin
    addon create i18n --topLevelPackage spring.roo.addon.mvc.i18n.bosnian.Latin --locale bs_la --messageBundle messages_bs-Latn-BA.properties --language Bosanski --flaggraphic bs.png --description "Localization for Bosnian Latin"


    And when I add them
    osgi start --url file:///....\spring.roo.addon.mvc.i18n.bosnian.cyrillic-0.1.0.BUILD-SNAPSHOT.jar
    osgi start --url file:///....\spring.roo.addon.mvc.i18n.bosnian.latin-0.1.0.BUILD-SNAPSHOT.jar

    In project in roo I can see them

    roo>web mvc language --code
    bs_la bs_cy de en es it nl sv

    but i'm getting exception
    java.lang.IllegalStateException: Failed to convert 'bs_cy' to type I18n for option ',code'
    when adding language

    roo> web mvc language --code bs_cy
    java.lang.IllegalStateException: Failed to convert 'bs_cy' to type I18n for option ',code'


    One strange thing is if I issue
    addon create i18n --topLevelPackage spring.roo.addon.mvc.i18n.bosnian.Cyrillic --locale bs_cy --messageBundle messages_bs-Cyrl-BA.properties --language Bosanski --flaggraphic bs.png --description "Localization for Bosnian Cyrillic"

    I have to modify in BosanskiLanguage class bs -> bs_cy

    @Component(immediate = true)
    @Service
    public class BosanskiLanguage extends AbstractLanguage {

    public Locale getLocale() {
    return new Locale("bs");//change to bs_cy
    }

    public String getLanguage() {
    return "Bosanski";
    }

    public InputStream getFlagGraphic() {
    return FileUtils.getInputStream(getClass(), "bs.png");
    }

    public InputStream getMessageBundle() {
    return FileUtils.getInputStream(getClass(), "messages_bs-Cyrl-BA.properties");
    }
    }

  6. #6
    Join Date
    Mar 2013
    Posts
    6

    Default

    I know this is old but thought it was worth adding in, just in case others are looking.

    I was able to add a new language to my Spring Roo JSF project just by:
    1. Adding the image and link in the footer.
    2. Creating the associated messages_<xx>.properties file
    3. Adding in the language support to the faces config: (faces-config.xml)

Posting Permissions

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