[ColdBox 3.6.0] Url localization

I would like to create different language version of my app.

What is the best approache to create localized version?

I should use this type of routed url?

www.myapp.com/

www.myapp.com/en/

www.myapp.com/fr/

www.myapp.com/it/

So I should use my route to check which langage to choose? I should create a route for every language I’d like to support?

i would not create a route for every language.

put the value in a particular spot in your string and make that a convention among all your routes. maybe put it at the end so you can default the value.

You might also add to your default routing to specify the language and add a Request Decorator to evaluate the language variables:

In config/Routes.cfm:
//Language-Specific Routing
addRoute(pattern=“:lang/:handler/:action?”);

Then in a request decorator configure() method, set the the language variable at either the request level to control your i18n content selection.

I haven’t tested so I’m not sure of the above effect on the default route (:handler/:action?) so you may need to add an additional variable to set the ‘en’ default.

HTH,
Jon

That said, a more elegant solution, IMHO, might be to configure language-specific subdomains (i.e. - en.mysite.com) and evaluate the language based on the CGI.SERVER_NAME variable. Then your :lang variable won’t create conflicts in your routing. I went this way with a recent client that has an affiliate business model and, once I configured the web server to handle the wildcard and set the wildcard DNS, I didn’t have to worry about it. There are pros and cons to this method, of course. You then might have a request decorator function, called in configure(), that looks something like this:

private void function setLanguage(){
    var controller = getController();
    var domain = CGI.SERVER_NAME;
    var subdomain = listFirst(domain,".");
    var language = controller.getWireBox().getInstance("Language”);

      if(!isNull(language.findByCode(subdomain))){

        //if the subdomain is a valid language code, do your language processing here

      } else

        //set your language defaults here

      }
}

Another solution could be to set the ses base url at the first request as your default languiage and when a user choose another languiage you should fire the sesbaseurl to the desired routed url.

Something like this:

`


 <cffunction name="preProcess" access="public" returntype="void" hint="Executes before any event execution occurs" output="false" >
                <cfargument name="event">
                <cfargument name="interceptData">
                <cfscript>
                
                        // set the base URL according to domain or whatever strategy you like.
                        arguments.event.setSESBaseURL("http://" & cgi.http_host & "/en/");
                
                </cfscript>
        </cffunction>

`

then you should change the url to “fr” or “es” when user click a button…