maybe you are thinking that this is another dump question about language in URL, but I hope it is not! I’ve red many articles on this, but non of them was dealing with “sections of site” (described bellow).
I am programming a new application platform in laravel/php and I am still not 100% convinced where to put language slug.
There are many places where you can put it – some of them are better some are worse:
- example.com/en/article
- en.example.com/article
- example.com/article?lang=en
My personal choice is to put language after the domain – so the first option in above list.
But what if you are in some special secion like admin or api? where do you put language then?
- example.com/en/admin/dashboard
- example.com/en/api/v1/user/login
or
- example.com/admin/en/dashboard
- example.com/api/v1/en/user/login
(in frontend it is left the same: example.com/en/some-article)
what do you preffer? what are cons and pros? One thing is using language in first segments is far more easier to programm than when it have some variants…
EDIT: I am also using two lists of avalible languages to determine what languages are avalible for app/backend and for frontend (if the app is something like CMS). Eg. web can be only in english but app (cms) can be in czech, english, italian…
P.S. whould you recoment using only en, cs or do it in full power with cz-CZ, en-US ?
thanks for any thoughts!
J.
4
For your developer-facing API, you should obey the Accept-Language
header for the reason CodeCaster mentioned in the comments:
Translations are different representations of the same resource, so the resource identifier should remain the same.
However, for UI (i.e. anything where the user-agent is a web browser) using Accept-Language
to decide which language to render the page in is probably a bad idea, since it is effectively unchangeable (unless you’re in the 0.001% of users who knows how) and may not reflect your users’ actual language preference anyway. Using Accept-Language
to select the default language a user sees is a nice idea, but even Google recommends that you keep the content for each language on separate URLs.
As to your actual question: Where in the URL should the language fragment go? Well… It doesn’t really matter. There are no strict rules for this. It will largely depend on what is easiest for you to implement in your chosen framework.
Here is some additional reading:
- How should I structure my URLs for both SEO and localization? (Webmasters.SE)
- Working with multilingual websites (Google Webmaster Central blog)
3