J
J
Jack Cooper2018-04-25 21:54:05
Internationalization and localization
Jack Cooper, 2018-04-25 21:54:05

How is localization by subdomains implemented?

Good evening everyone.
Please share how localization is implemented using subdomains?
For example, for the Russian language - ru.site.com, English - en.site.com and so on.
I can't find proper information. Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bkosun, 2018-04-26
@negmat

Something like this:
A single Document Root is installed for all subdomains, and then in the application:

$url_array = explode('.', parse_url($request->url(), PHP_URL_HOST));
$subdomain = $url_array[0];

...

$languages = ['en','de'];
if (in_array($langcode, $languages)){
    App::setLocale($langcode);
}

Examples:
https://kovah.me/en/laravel-5-localization-based-o...
https://github.com/LaurentEsc/Laravel-Subdomain-Lo...

M
Maxim Fedorov, 2018-04-25
@Maksclub

For example:
When entering the main domain, the language is determined in the middleware:
By this value, the middleware goes to The database looks to see if there is such a language in the system, and puts the value, for example, in a cookie/session and/or redirects to a subdomain with the desired location, then displays already localized content

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question