Welcome Guest, Not a member yet? Register   Sign In
2 Languages on my site: how to start ?
#21

[eluser]yannyannyann[/eluser]
I would like to know now how to automatically apply my language setting to all links I have ?

Do i have to do add current_language() function each time I add a link ?
Or is there another way to do it with config or helpers ?
Code:
<?=anchor(current_language().'/photo','Go to the Photo Category');?>

As a reminder I this is contained in my MY_url_helper Class :
Code:
function current_language()
{
   $CI =& get_instance();
   if(strlen($CI->uri->segment(1)) != 2){
      return $CI->config->item('default_language');
   }
   else{
      return $CI->uri->segment(1);
   }
}



.. And for sure if current_language == french I would like to display this link :

Code:
<?=anchor(current_language().'/photo','Aller à la catégorie Photo');?>

I remember that I saw that there is a possiblity to use this kind of syntax below, where the text is replaced by another text defined in a language file (in my case French or English) :

Code:
<p>{Photo title}</p>

I just don't remember how this method works. Any help would be great :)
#22

[eluser]TheFuzzy0ne[/eluser]
For URLs, you can set the base_url variable, with the appropriate base_url:
Code:
// Assuming the short_lang config variable has been set to something like "fr" or "en".

$this->config->set_item('base_url', base_url() . $this->config->item('short_lang) . '/');

For loading words/phrases from the language file you've loaded, use lang() in the language_helper.
#23

[eluser]pistolPete[/eluser]
Code:
<p>{Photo title}</p>
This syntax can be used with the Template Parser Class.
#24

[eluser]yannyannyann[/eluser]
Quote:This syntax can be used with the Template Parser Class.
That's what I was looking for ! thanks


Code:
// Assuming the short_lang config variable has been set to something like "fr" or "en".

$this->config->set_item('base_url', base_url() . $this->config->item('short_lang) . '/');
Where should I define this ? In my model ?
#25

[eluser]TheFuzzy0ne[/eluser]
It's probably best if you define it in your configuration file. It will need to be defined dynamically, as it's dependant on the URI.
#26

[eluser]yannyannyann[/eluser]
hmmm I've added this line to my model :
Code:
$this->config->set_item('base_url', base_url() . current_language() . '/');

My problem is now:

if I am on www.mysite.com/fr/media/my-media-title and I click on "English version" I get this URL in repsonse :
www.mysite.com/fr/en/media/my-media-title (so it the rewriting of the base_url is maybe not the best solution ?)
#27

[eluser]ayukawaa[/eluser]
I think rewriting of the base_url it's the best solution because it changes all urls and you don't have to remember anything more when dealing with this.

So, do you want to change the behaviour of ONE url? Use
Code:
&lt;?=substr(base_url(), 0, -3))?&gt;
instead of base_url() when calling for ANOTHER lang.

That simply strips the last 3 chars from string.

^_^
#28

[eluser]TheFuzzy0ne[/eluser]
I'm not sure what's adding that extra bit, but whatever it is should probably be removed, as it's clearly adding the wrong language identifier for starters.
#29

[eluser]yannyannyann[/eluser]
But how should I proceed if I don't use :
Code:
&lt;?=substr(base_url(), 0, -3))?&gt;

Is there another way ?

What's about the MY_language_helper class on CodeIgniter ?
Could this do the job ?

As a reminder I need to have
- 2 languages always switchable through a link
- fr is my main language (so www.myweb.com is french)
- en is secondary language (so www.myweb.com/en )
#30

[eluser]TheFuzzy0ne[/eluser]
How about a function called lang_url() which will return the base_url with the appropriate short code appended to it? Then you're free to use lang_url() or base_url() as you please.

EDIT or maybe better yet. Just modify the base_url() function to accept an extra parameter, which specifies whether or not to add the short lang to the end.




Theme © iAndrew 2016 - Forum software by © MyBB