Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:50:46+00:00 2026-05-15T09:50:46+00:00

I’m having problem with language mappings. The way I want it to work is

  • 0

I’m having problem with language mappings. The way I want it to work is that language is encoded in the URL like /appname/de/mycontroller/whatever

If you go to /appname/mycontroller/action it should check your session and if there is no session pick language based on browser preference and redirect to the language prefixed site. If you have session then it will display English. English does not have en prefix (to make it harder).

So I created mappings like this:

class UrlMappings {
    static mappings = {
        "/$lang/$controller/$action?/$id?"{
            constraints {
                lang(matches:/pl|en/)
            }
        }
        "/$lang/store/$category" {
            controller = "storeItem"
            action = "index"
            constraints {
                lang(matches:/pl|en/)
            }
        }
        "/$lang/store" {
            controller = "storeItem"
            action = "index"
            constraints {
                lang(matches:/pl|en/)
            }
        }
       
        
        "/$controller/$action?/$id?"{
            lang="en"
            constraints {
            }
        }
        "/store/$category" {
            lang="en"
            controller = "storeItem"
            action = "index"
        }
        "/store" {
            lang="en"
            controller = "storeItem"
            action = "index"
        }
        
    
      "/"(view:"/index")
      "500"(view:'/error')
    }
}

It’s not fully working and langs are hardcoded just for now. I think I did something wrong. Some of the reverse mappings work but some don’t add language.

If I use link tag and pass params:[lang:’pl’] then it works but if I add params:[lang:’pl’, page:2] then it does not. In the second case both lang and page number become parameters in the query string. What is worse they don’t affect the locale so page shows in English.

Can anyone please point me to the documentation what are the rules of reverse mappings or even better how to implement such language prefix in a good way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:50:47+00:00Added an answer on May 15, 2026 at 9:50 am

    The biggest problem you have to deal with is having no prefix for English. Most of your mapping seems totally ok. I would recommend you to work with named mappings.

    But first I would recommend you to work with filters for setting a language parameter for every user.

    def filters = {
        languageCheck(controller: '*', action: '*') {
            before = {
                if( params.lang == null) {
                    redirect( controller: params.controller, action: params.action, params:[ "lang": request.locale.language.toString() ] + params )
                }
            }
        }
    }
    

    If a user with missing language parameter enters your site the language is set by the filter and he is redirected to the controller with language parameter. Be careful if you are using a security framework which is also redirecting. You can only redirect once. In that case you have to exclude those urls or controllers from the filter.

    Now we will look at your mapping problem. Since Grails 1.2 there are so called Named URL Mappings. E.g.

    name storeCategory: "/$lang/store/$category" {
            controller = "storeItem"
            action = "index"
            constraints {
                lang(matches:/pl|en/)
            }
        }
    

    Inside your GSP you can refer to your named mapping with

    <g:link mapping="storeCategory" params="[lang:'en', category:'new']">Category</g:link>
    

    This should solve your problem. You can find all about named mappings in the Grails Reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.