MVC and dynamic language change

1

I have a MVC myself that I implement in my projects in PHP . This supports multiple languages and by default they get the active / initial language from the browser.

However, there are projects that require the language modification feature with a simple click.

The solution I understand best is by the URL ie:

url for automatic language: http://meuprojecto.com/[controller]/[action]

url to force language / locale: http://meuprojecto.com/pt-PT/[controller]/[action] .

As you can see I use the LOCALE standard to get the language ... Being implemented using the hyphen or the underscore. This way, whenever the framework detects this type of URL, it modifies the locale initially obtained from the browser for the project.

Having my solution, I would like to evaluate other ways to solve this problem.

My question is: what other mechanisms do you know within implementations in PHP solved differently? I have thought of inserting support for the presence of a ISO 639-1 tag to identify the language but I think I'm complicating it or not?

    
asked by anonymous 29.05.2015 / 11:52

2 answers

2

The most elegant layout I've ever encountered for PHP is in CakePHP, module i18n .

Basically, you define the whole system with internationalization functions like this:

__("MinhaString")

"MyString" is understood as a resource key. All keys can be extracted using an automatic procedure like this .

After that, files can be translated with the help of a tool like Poedit .

    
17.08.2015 / 21:28
1

You would be creating another medium, which would even make sense. But it would still be an extra job and for any other person and for SEO purposes it could have side effects.

What I can recommend would be the implementation of cookies to store and capture the locale according to what the user wants. It would be faster, you can manipulate by javascript too, for example, and it would make your code more readable.

    
17.08.2015 / 20:55