Welcome Guest, Not a member yet? Register   Sign In
Subdomains based localization
#1

(This post was last modified: 12-11-2019, 12:23 PM by ARAmiss.)

Hello.
I have main domain.com and its subdomains en.domain.com, fr.domain.com, de.domain.com and others.
I need to build localization versions of main domain on subdomains. How can i do it?

There are only 2 codeigniter 4 official ways in docs:
1) https://codeigniter4.github.io/userguide...egotiation
2) https://codeigniter4.github.io/userguide...#in-routes

The first method has nothing to do with subdomains. The second method based on zero uri segment and it's also not my case.
Reply
#2

The simplest way to define language locale is to set it in BaseController:

Code:
$domain = $_SERVER['HTTP_HOST'];
$domain_paths = explode('.', $domain);

if (count($domain_paths) == 3)
    $locale = $domain_paths[0];
else
    $locale = $request->config->defaultLocale;

$request->setLocale($locale);

It's working. But there must be more than one action "set locale". For example, "get all locales", "get locale from cookie", etc.
So we need some Class.
Questions:
1) What is the best way to implement this: library, model or other? What do you advise?
2) Where the best to set locale? I think not Routes.php, and not App.php (maybe?).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB