Multi Language selection

Permalink 1 user found helpful
Hello,

In my site i want to give two option of the language
1) English
2) Danish

Default Language is Danish,but when the user clicks English it will have all the site in english.

From many post which i have read there are saying to include the define("LOCALE", 'da_DK'); in site.php file and base.php file

But this will work for one language. But i want to make this selection dynamically can i do that.
for example
if(lang=Eng)
define("LOCALE", 'en_UK');
else
define("LOCALE", 'da_DK');

Can you please let me know were should i place the code and in which file
If that is possible then how can i achieved it. Please help me it very urgent
May be this would be silly question for some scholar person
Thanks

 
dendeffe replied on at Permalink Reply
dendeffe
I'm wondering about this as well. I'm new to C5, but can't really see how switching languages would work for the labels (in the PHP files) throughout the site.

You can't redefine the LOCALE, right? You should be able to do something like
Localization::setLocale('nl_NL');
pvernaglia replied on at Permalink Reply
pvernaglia
I think if use echo_t in the php files it will put in the correct language prompts
dendeffe replied on at Permalink Reply
dendeffe
Do you have a code example somewhere for this? Where should the echo_t be placed?
Ale replied on at Permalink Reply
I'm building a site that also has few different languages. My site structure looks like this:
root (redirects to first childpage)
   fi
   en
   etc...

I solved the problem by adding some logic to site.php (which definately isn't the best place to add code to...):

$lang = substr($_SERVER['PHP_SELF'],11,2);
define('LANG', $lang);
switch($lang) {
   case 'fi': {
      define('LOCALE', 'fi_FI');
      setlocale(LC_ALL,'fi_FI.UTF-8');
      break;
   }
   case 'en': {
      define('LOCALE', 'en_US');
      setlocale(LC_ALL,'en_US.UTF-8');
      break;
   }
   default: {
      define('LOCALE', 'fi_FI');


Basically that is kinda "dumb" way to check what comes after the /index.php/ and set locale according to that. Before trying this out I tried to add a page event that checked the current page's path and set the locale according to that, but it seems that the locale cannot be set that late in the application flow. However, I haven't tried the Localization::setLocale('xx_XX') which could do the job inside the page event...

When user is logged in, the dashboard and editing locale is set by the default value in switch case.
dendeffe replied on at Permalink Reply
dendeffe
Localization::setLocale('nl_NL');
is fictional code :) It's how it's done in SilverStripe, another CMS I use a lot.

Will look into you solution, although it hacks core files.
Ale replied on at Permalink Reply
Ok, I see :)

Considering the files in /concrete folder are THE core files, the site.php isn't necessarily a core file, as it contains user set variables and settings.
olacom replied on at Permalink Reply
olacom
I tweak your code to make it compatible to any url including the DIR_REL if one is specified.

// Including the DIR_REL and the Domain, the two language character en, fr, es, etc.
$length_rel = strlen(DIR_REL);
$sitelang = substr($_SERVER['REQUEST_URI'],$length_rel+1, 2);
define('LANG', $sitelang);
switch($sitelang) {
   case 'en': {
      define('LOCALE', 'en_US');
      setlocale(LC_ALL,'en_US.UTF-8');
      break;
   }
   default: {
      define('LOCALE', 'fr_FR');
      setlocale(LC_ALL,'fr_CA.UTF-8');
      break;
   }


http://www.yourdomain.com/en

OR

if your concrete is install under a subfolder DIR_REL('/subfolder');
http://www.yourdomain.com/subfolder/en...
it will detect the language too.
thuic replied on at Permalink Reply
thuic
Please help.

I am trying to implement your code, but without success.
My site is bilingual (Croatian / English) with the following tree.

Root
+hr
+en

On all pages I have EN and HR links to second level directories /hr/ and /en/… (<a title="Home" href="/en/">EN</a>), but switching do not change translations.

When switching language by hardcoding default language in site.php: define('LOCALE', 'hr_HR') or define('LOCALE', 'en_US'), I can see translations immediately.
olacom replied on at Permalink Reply
olacom
Working fine with 3 languages on my side, i've just use it for a client that as a website with ENGLISH / FRENCH / SPANISH

Can you paste your code here ?
thuic replied on at Permalink Reply
thuic
Thank you for fast reply,

site.php code is:

// Including the DIR_REL and the Domain, the two language character en, hr.
$length_rel = strlen(DIR_REL);
$sitelang = substr($_SERVER['REQUEST_URI'],$length_rel+1, 2);
define('LANG', $sitelang);
switch($sitelang) {
   case 'en': {
      define('LOCALE', 'en_US');
      setlocale(LC_ALL,'en_US');
      break;
   }
   default: {
      define('LOCALE', 'hr_HR');
      setlocale(LC_ALL,'hr_HR');
      break;
   }


Links code is:
<p style="text-align: right;"><a title="Naslovnica" href="/hr/">hr</a> : <a title="Home" href="/en/">en</a></p>
thuic replied on at Permalink Reply
thuic
S O L V E D!

Sorry, I didn't clear cache proprely.

Thank you one more time for helping me and for great code, the only one I find working on C5 forum.
olacom replied on at Permalink Reply
olacom


Envoyé de mon iPhone

Le 2011-03-09 à 10:12 AM, Concrete5 Community <discussions@concretecms.com> a écrit :
olacom replied on at Permalink Reply
olacom
Perfect! :-)
suso replied on at Permalink Reply
Hi!

Sorry for awakening an old post but i need this functionality and just cant get it. I have tried everything, even instead of the switch with "if's" but yet doesnt do it. I even printed using an "echo" the variable sitelang, and it doest grab correctly the languages such as "es", "en", etc... but then Concrete just grabs the language thats defined on the default option of the switch.

I suppose that this tweak depending on which language you click, the whole concrete translates into that language, correct? i mean the dashboard, login, etc...core files.

Thanks!
PatrickHeck replied on at Permalink Reply
PatrickHeck
I think the best option for you would be to wait for the core update in august wich will contain an extended internationalization support.http://www.concrete5.org/about/blog/core-roadmap/internationalizati...
suso replied on at Permalink Reply
No! :( Cant i have a solution till this is out? This tweak explained here should work! i dont understand why it doesnt...
PatrickHeck replied on at Permalink Reply
PatrickHeck
My preferred solution so far was to install a seperate C5 installation for every language. It's not really elegant, but it works fine. You can also reduce the overhead by symlinking to a shared "theme", "language" and "concrete" directory.
But apart from that you can always download the latest C5 Version directly from GitHubhttps://github.com/concrete5/concrete5... .