Welcome Guest, Not a member yet? Register   Sign In
Localization for an app
#1

[eluser]Maglok[/eluser]
I am writing an application that will need to be in two languages. I got some ideas on how to do it, but have never done it. So I figure I'd explain how I plan to do it, so that anyone that has done it can yell at me and explain how it can be done easier.

I am going to create two subdomains, both with a index.php and a constant that defines the language and base_url. Thus the english and the dutch (the two languages) versions of the website have two different entrypoints (the customer wanted it that way).

I then figure I should replace any strings in the application with variables and write a config file that is basically a huge list that I can reference. One for english the other for dutch. Depending on the language constant it will read either dutch or english.

I figure getting a constant from the config file (the dictionary if you will) and then putting it on the place of the String.

I just don't think using the syntax "echo $this->config->item('variable')" is the best way, any way to make that easier? To the tune of echo $text['balbla'] or something?

As far as I know CI 1.7.2 doesn't come with localization options.
#2

[eluser]Georgi Budinov[/eluser]
See this here - http://ellislab.com/codeigniter/user-gui...guage.html
Actually you are very close to the implementation of the localization in CodeIgniter. The difference is that you do not need two index.php and two entry points.
The problem you want to escape, still exists though Sad - retrieving constants is still pretty much the same -> $this->lang->line('some_label'); which is annoying for me, too.
#3

[eluser]Georgi Budinov[/eluser]
Actually I have never thought of doing something to eliminate that calling to $this->lang->line(). I quickly looked at the language class -> you can pass that language array to the view like this -
Code:
$this->load->view('some_view', array('lang'=>&$this->lang->language));

And then use the $lang variable in the view like $lang['some_label'].
#4

[eluser]Maglok[/eluser]
I still need a way to detect the language setting though. The customer kinda wants both to enter through a different subdomain into the same CI app. No simple language uri segment thus. Sad

This is interesting though. So I could make like a few, for different pages. I could also throw the entire array of lang for that page in a local array to not have to load the entire 'dictionary'?

Am I making any sense? Tongue

EDIT: I made this post when you replied. Well I of course pass more then the lang to the view so I'd have to add it to the array of data I pass. Like uhm so:

$data['lang] = $this->lang->blabla
$this->load->view('somepage', $data)
#5

[eluser]Georgi Budinov[/eluser]
Yes of course ... just note the '&'. The language array could be huge so this could be good optimization. About you subdomain language problem ... you can parse the $_SERVER['SERVER_NAME'] global variable and see what is the needed language, no uri segment Smile
#6

[eluser]Maglok[/eluser]
True yes. Smile

Though it would have been either subdomain OR uri, not both true.

Though this way I could just plop down the index.php on 1 of the subdomains and the entire app on the other then reference that subdomain as the place where CI is. Starting to get a good idea here, yes. Smile Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB