Form in multiple languages

Permalink
Hi everybody,

I would like to add a form to my multilingual website. But I can't find an option to change the language of the default strings in the form block. So for example the Submit button always says submit and the error messages are also always in English. That's fine for the English part of the website, but not for the Dutch. Can anyone tell me how I could make this work?

Thanks!

 
FernandoCordeiro replied on at Permalink Reply
FernandoCordeiro
I think you would need to change the Block's code, but I'm trying to find a better way to do this right now, as I make websites in Brazilian Portuguese and multilingual websites (No matter what or how many languages, I'll always need pt_BR). I'll let you know as soon as I have a more elaborate answer which will work for multilingual.


Ok, I think I found it:

On the controller.php:

value="'.t('Submit').'"


This gets the TRANSLATION. So for some reason it appears as "Enviar" ("Submit" in pt_BR) for me right now, but it was appearing as "Submit" on my Laptop, so I'd love to know WHY this happens.

Since both my Windows are in English, and I log with the same credentials from both, I suppose this is happening because my Browser is in portuguese on this computer, but I'm not really sure. I don't know in which language it is on my laptop.


Anyways, I think we could either just leave it alone, as it seems like it will work in most cases. I'll see which results I can get from friends with computers in another languages, and I'll tell you.

If you have access to a computer in dutch, just try accessing the site and see if the button works, and then please give me an update.



Note: I think it may only translate to languages you have installed on your C5, so some info on this would be really helpful. Anyone?
pieterbeulens replied on at Permalink Reply
Nope, it doesn't seem to be the browser language: I just tried on a Dutch laptop and it still says Submit.

I downloaded and installed the Dutch language pack, and when I now select Dutch from Sitewide settings - Multilingual, it does show the correct word in the form. But when I go to the English contact form, it also says "Versturen" (which is Dutch for Submit). So, that's not the way it supposed to work, I'd say.

Any other suggestions?

Note: Concrete5 team, why can't we type in the word for the submit button when inserting the form? Sometimes you'll want submit, but sometimes you'll want something like subscribe, or send, or whatever. This would make internationalization of this block easier as well.
PatrickHeck replied on at Permalink Reply
PatrickHeck
Unfortunately the t() function does not work with the internationalization add-on. That means than only the language set in your site.php will be used as translation target by default. To get it to work you need to change the function. The add-on "language manager" does that for example:
http://www.concrete5.org/marketplace/addons/language-manager/...

See this discussion for more information:
http://www.concrete5.org/marketplace/addons/internationalization/fo...
pieterbeulens replied on at Permalink Reply
Hmm strange that there is a multilingual add-on, but it doesn't do all the work. Unfortunately, I'm working on a site with no budget, so I can't spend the 30 dollars. It's also quite pricy for only translating a couple of text strings, which should work out of the box with the multilingual add-on in my view.

Thanks for you help though.
PatrickHeck replied on at Permalink Best Answer Reply
PatrickHeck
A hack that I sometimes use is switching the locale based on the path. You need to have a structure like domain.com/en, domain.com/nl, domain.com/de... Then in your site.php you replace
define('LOCALE','nl_NL');

with
$sitelang = substr($_SERVER['REQUEST_URI'],strlen(DIR_REL)+1, 2);
switch($sitelang) {
   case 'en': {
      define('LOCALE', 'en_US');
      break;
   }
   case 'nl': {
      define('LOCALE', 'nl_NL');
      break;
   }
   default: {
      define('LOCALE', 'de_DE');
      break;
   }
}


Please keep in mind that this can still be overridden by the user language you defined in the dashboard. So strings can be in a different language depending if you are logged in or not.

Patrick
FernandoCordeiro replied on at Permalink Reply
FernandoCordeiro
This one is perfect for me.

Now just one thing I didn't check (yet):

I need to install all languages I use in my website content, right?


Now this will become a pain: Finding the translations. Only installed Pt-BR so far and took me a pretty long time to find it...
PatrickHeck replied on at Permalink Reply
PatrickHeck
I agree Fernando, the lack of a current central repository for all language files is a big disadvantage. But I think the guys in the Translation Group are working on this.
Meanwhile check mygengo:http://mygengo.com/string/p/concrete5-1...
FernandoCordeiro replied on at Permalink Reply
FernandoCordeiro
I got the mygengo files that I need and I'll edit them to complete anything that I notice is missing.

Now I'll just hope for a central repository, preferrably with an option to install the languages from within the Dashboard. :D
pieterbeulens replied on at Permalink Reply
Perfect, that did the trick! This was all I needed. Thanks for the help.
wasabili replied on at Permalink Reply
wasabili
Mmhh unfortunately I have the URL a little different like this:
http://www.domain.com/index.php/en/contact/...

And your hack doesn't work. I tried to change the first line into:
$sitelang = substr($_SERVER['REQUEST_URI'],strlen(DIR_REL)+2, 2);

But that didn't helped. Can some one help me?
Thanks
wasabili replied on at Permalink Reply
wasabili
Mmhh unfortunately I have the URL a little different like this:
http://www.domain.com/index.php/en/contact/...

And your hack doesn't work. I tried to change the first line into:
$sitelang = substr($_SERVER['REQUEST_URI'],strlen(DIR_REL)+2, 2);

But that didn't helped.
Can some one help me?
Thanks
PatrickHeck replied on at Permalink Reply
PatrickHeck
Yes, try this:
$locales = array(
         "en" => "en_US",
         "es" => "es_ES",
         "fr" => "fr_FR",
         "it" => "it_IT",
         "de" => "de_DE",
         "zh" => "zh_CN",
         "ar" => "ar_AW");
$regexp = '/^'.preg_quote(DIR_REL,'/').'\/(index.php\/)?([^\/$]+)/';
preg_match($regexp,$_SERVER['REQUEST_URI'],$match);
if (isset($locales[$match[2]])) {
   define('LOCALE', $locales[$match[2]]);
} else {
   define('LOCALE', 'de_DE');
}


taken from:http://www.concrete5.org/marketplace/addons/internationalization/fo...
onemhz replied on at Permalink Reply
onemhz
I try to override Dashboard default language
and I found perfect solution for multilangual site

@PatrickHeck's code work perfect with some corrections

before code you must add
define('DIR_REL', '');

and remove
} else {
   define('LOCALE', 'de_DE');


then in site template header place this:
if (defined('LOCALE')) {
Config::save('SITE_LOCALE', LOCALE);
}

(solution from @Asseco)http://www.concrete5.org/community/forums/internationalization/how-...
AND
<html lang="<?php echo LANGUAGE?>" xmlns="http://www.w3.org/1999/xhtml">

all that works perfect :)
enjoy
adrianspeyer replied on at Permalink Reply
adrianspeyer
thanks for this works like a charm!
Hypocrite replied on at Permalink Reply
Hypocrite
Has anyone had problem with this with 5.5.x version?

I have this in my site.php:
$length_rel = strlen(DIR_REL);
$sitelang = substr($_SERVER['REQUEST_URI'],$length_rel+1, 2);
define('LANG', $sitelang);
switch($sitelang) {
   case 'en': {
      define('LOCALE', 'en_GB');
      setlocale(LC_ALL,'en_GB');
      break;
   }
   default: {
      define('LOCALE', 'fi_FI');
      setlocale(LC_ALL,'fi_FI');
      break;
   }
 }


And a page url like this:
http://domain.fi/en/joining/

But the form always defaults to Finnish.
PatrickHeck replied on at Permalink Reply
PatrickHeck
Hey Hypocrite,

maybe your DIR_REL is set to an invalid value? Try to output it using
echo DIR_REL;


Also, please note that you should never user "LC_ALL" because it will bring you big trouble with some addons (and possibly core functions). This is because of the number conversion from LC_NUMERIC, that might replace the decimal separator.

See this:http://php.net/manual/de/function.setlocale.php#108326...

Best
Patrick
Hypocrite replied on at Permalink Reply
Hypocrite
Thanks got it working by adding DIR_REL to the site.php.