1
I have a MVC
that I implement in my projects in PHP
. This supports multiple languages and by default gets the active/initial language from the browser.
However there are projects that require the functionality of modifying the language with a simple click.
The solution I understand best is by the URL or I mean:
p/auto language url: http://meuprojecto.com/[controller]/[action]
url p/force language/locale: http://meuprojecto.com/pt-PT/[controller]/[action]
.
As you can see, I use the LOCALE standard to obtain the language... Being that I implemented using the hyphen or underscore. This way whenever the framework detects this type of URL it modifies for the project the LOCALE initially obtained from the browser.
Having my solution, I would like to evaluate other ways of solving this problem.
My question is: what other mechanisms do you know within implementations in PHP
solved differently? I have been thinking about inserting support for the presence of a tag ISO 639-1
to identify the language but I think I’ll be complicating, or not?
It is unrelated to MVC.. But regardless, ISO3166-Alpha2 refers to country codes. I recommend using ISO codes for languages instead of countries, because how to determine, for example, the language of a bilingual country?
– Daniel Omine
@Danielomine did not understand why it has no relation with MVC. Thanks for the correction of the ISO because I was wrong and I corrected it. To say that by language it sounds good but LOCALE is actually more specific because I can identify pt-PT or pt-BR, en-GB or en-US for example. What for some implementations makes all the difference.
– chambelix
@Danielomine however my doubt, in adopting the ISO is why there are actually more comprehensive implementations that do not require as much specificity. and a url http://exemplo.com/pt. is much simpler than http://exemplo.com/pt-PT
– chambelix
ok, I imagined this. The problem of using only the language code is for the case of different countries. The code "pt" is Portuguese, however, the Portuguese of Brazil is different from Portuguese. About MVC, it is indifferent whether it uses MVC or not.. so it has no relation.
– Daniel Omine
locale code is based on the [language code]-[country code] structure both in 2 digits.. However, there are some exceptions such as "az-Cyrl-AZ", for example.
– Daniel Omine
As stated above, this is unrelated to the use of MVC. If I understand your problem, you can use some internationalization libraries (recommend to php-i18n).
– William Urbano
I know what an MVC is and I’ve placed the selection within the component I built to control the outputs with respect to the language within the component I created and that’s why I connected them. My question is simple if you know other ways to define a language besides the one I implemented. @Williamurbano thanks for your suggestion I will investigate.
– chambelix
@chambelix : Try to store the locale in your session through some URL that the user will access and that language will be set. This way there will be no need to include the locale in your URL.
– William Urbano