• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue for loading language in controller

#1
Hi, i would like compile the meta hreflang tag dynamically and navigate the pages like in Joomla.
My site is in italian and english. Default language should be italian. My code:

Config/App.php
PHP Code:
public $defaultLocale 'it';
public 
$negotiateLocale true;
public 
$supportedLocales = ['it''en']; 

Controller Main.php
PHP Code:
<?php namespace App\Controllers\It;
use 
App\Controllers\BaseController;

class 
Main extends BaseController
{
public function 
index()
  {
    $data['title'] = 'My Site';

    $data['ita'] = lang('App.linkNav01', [], 'it'); // FIRST ITALIAN
    $data['eng'] = lang('App.linkNav01', [], 'en'); // AFTER ENGLISH

    echo view('home'$data);
  }


View main.php
PHP Code:
<link rel="alternate" hreflang="it" href="<?php echo base_url($ita);?>" />
<
link rel="alternate" hreflang="en" href="<?php echo base_url($eng);?>" /> 

The meta tag are ok but the site (in italian too) is always translate in english. If i change the order in controller like this:
PHP Code:
<?php namespace App\Controllers\It;
use 
App\Controllers\BaseController;

class 
Main extends BaseController
{
public function 
index()
  {
    $data['title'] = 'My Site';

    $data['eng'] = lang('App.linkNav01', [], 'en'); // FIRTS ENGLISH
    $data['ita'] = lang('App.linkNav01', [], 'it'); // AFTER ITALIAN

    echo view('home'$data);
  }


the site is always translate in italian. What happens? Why i have this behavior?

Thanks for help me!  Smile
Reply

#2
Because you need to check to see which language should be displayed first
then add it to the data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Thanks for reply. Can you explain better please?
Reply

#4
You should have a dropdown and allow the user to select the language or get the local setting.

Read this:

CodeIgniter 4 Language Localization
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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