• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subdomains based localization

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.

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

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

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


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.
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?).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.