Adding language code in the page adress – Multi-language url rewiting

Splash Forums PrettyFaces Users Adding language code in the page adress – Multi-language url rewiting

This topic contains 2 replies, has 2 voices, and was last updated by  vector_ever 5 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #27435


    I built my site to be Multi-language. I want the language code to be embedded in the address of page according to the locale. I have the following:


    I want to have it as the following:

    http://localhost:8080/Wirote/de/index — display German content
    http://localhost:8080/Wirote/en/index — display English content
    http://localhost:8080/Wirote/ar/index — display Arabic content

    To achieve this I followed the step in : multi-language url rewiting. Is it possible?


    <url-mapping id="base">    
        <pattern value="/#{localeManger.language}"/> 
     <url-mapping id="index" parentId="base">
        <pattern value="/index"/>
        <view-id value="/index.xhtml"/> 



    @ManagedBean(name = "localeManger")
    @SessionScoped // even I used Requestscoped instead
    public class LocaleManger implements Serializable{
        private Locale locale;
        private static final long serialVersionUID = 2756934361134603857L;
        public void init() {
        public Locale getLocale() {
            return locale;
        public String getLanguage() {
            return locale.getLanguage();
        public void setLanguage(String language) {
            locale = new Locale(language);

    Now when I run the project, I got only:


    also the page is stuck, so I can’t navigate to another using links in the index.xtml

    alternative I add the following to the index.xhtml:

            <f:viewParam name="locale" value="#{localeManger.language}"/>


    `<url-mapping id=”index”>
    <pattern value=”/#{locale}/index”/>
    <view-id value=”/index.xhtml”/>
    Now when I run the project, I get the following:


    But when I try to change the language, by clicking on English or Arabic language switcher, it doesn’t work correctly, the content of the page change, but the address page is not. But if I change it manually to

    http://localhost:8080/Wirote/en/index or

    it display the correct content in Arabic and English, but I need the address to be changed automatically not manually.

    How can I get the correct address related to current locale?


    Hi There,

    I believe your issue is related to the fact that you are likely using the JSF Page Navigation system — You need to issue a page redirect in order to change the URL after navigation using the language picker you’ve implemented.

    This page has a good explanation of the difference between Forward (the default) and Redirect (what you need).

    Hope this helps.

    Additionally, consider using Rewrite (the library PrettyFaces is built on) for internationalization:




    Your solution not clear enough to me, also it describes another case.

    Again I am not sure if I did it correctly When I run my project I still get : http://localhost:8080/Wirote/index.xhtml

    My properties ( files in the following location:


    But in the example they have another location:

    src/main/java/org/example/ ( it is in Java instead of resources)

    I mean instead of resource folder you have it in java package!

    The most importan property in the properties file is “language” which is resolve to language code

        src/main/resources/I18n/ .... language = en
        src/main/resources/I18n/ .... language = en
        src/main/resources/I18n/ .... language = de
        src/main/resources/I18n/ .... language = ar

    according to this I change the code to be:

    public class LocalizedConfig extends HttpConfigurationProvider{
       public Configuration getConfiguration(final ServletContext context)
          return ConfigurationBuilder.begin()
                   .where("path").transposedBy(LocaleTransposition.bundle("I18n.lang", "language"));
        public int priority() {
            throw new UnsupportedOperationException("Not supported yet."); 

    I know something is wrong but I don’t know what it is.

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.