Multi Language Support

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
peteburgess
Posts: 18
Joined: Thu 9. Nov 2006, 20:29

Multi Language Support

Post by peteburgess »

Hello,

So far I have found three options for multi-language support. After researching this for awhile I also found them here:

http://faq.phpwcms-docu.de/content/14/3 ... -site.html

Is there any thing better? I mean is there any way to setup the site w/o creating two or more separate versions of the site for each language? I understand that you wouldn't have to with this way: http://forum.phpwcms.org/viewtopic.php?t=6574F but I need the navigation to change as well. The other two ways require separate sites per language:

http://forum.phpwcms.org/viewtopic.php?t=6553

http://forum.phpwcms.org/viewtopic.php?t=3278

Any ideas? Thanks for any help.
peteburgess
Posts: 18
Joined: Thu 9. Nov 2006, 20:29

Re: Multi Language Support

Post by peteburgess »

Anybody? :o
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Re: Multi Language Support

Post by pepe »

peteburgess wrote:...
I mean is there any way to setup the site w/o creating two or more separate versions of the site for each language?
...
How should it be possible, to have two or more language versions of your original...
whithout producing just that neccessary versions :?: :roll: :?:

But you know, that you will do it inside one single installation of phpwcms, or don't you???
peteburgess
Posts: 18
Joined: Thu 9. Nov 2006, 20:29

Re: Multi Language Support

Post by peteburgess »

Yep I assuming it would be within the same phpwcms installation. Crazy to have two separate ones (or more for more languages) for a single site. I was just seeing if there were more options and/or ideas of how to achieve this. I worry about this being a mess when it comes to being compliant with future wcms upgrades. As well as not being too much of a learning curve to in house updating for clients. Even-though I am not too concerned the latter would be much of a problem but something to keep in mind.
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Multi Language Support

Post by juergen »

Fresh in from playground:

Yesterday I saw http://forum.phpwcms.org/viewtopic.php?f=12&t=16845 this little beauty and I decided to remake the language switch:

My own howto for a site by site language switch, perhaps this may be done a little bit better, but for me so far ok:

from oliver Masterchief['phpwcms']:

Code: Select all

<?php

// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------

        
// set allowed languages
// set $phpwcms['allowed_lang'] in conf.inc.php
// $phpwcms['allowed_lang']      = array('en', 'de', 'fr', 'es');
$language_default                       = 'de';
$language_current                       = $language_default;
$language_cookie_duration       = 60*60*24*365; // 1 year

if(isset($_GET['lang'])) {
        $language_current = strtolower( substr($_GET['lang'], 0, 2) );
        $_SESSION['phpwcmsFrontendLanguage'] = $language_current;
        setcookie('phpwcmsFrontendLanguage', $language_current, time()+$language_cookie_duration, '/' );
} elseif(isset($_SESSION['phpwcmsFrontendLanguage'])) {
        $language_current       = $_SESSION['phpwcmsFrontendLanguage'];
} elseif(isset($_COOKIE['phpwcmsFrontendLanguage'])) {
        $language_current       = $_COOKIE['phpwcmsFrontendLanguage'];
}
if(!in_array($language_current, $phpwcms['allowed_lang'])) {
        $language_current       = $language_default;
        $_SESSION['phpwcmsFrontendLanguage'] = $language_current;
        setcookie('phpwcmsFrontendLanguage', $language_current, time()+$language_cookie_duration, '/' );
}

// init language replacements
$language_regexp                = array( 'search' => array(), 'replace' => array() );

// set all language replacements now
foreach($phpwcms['allowed_lang'] as $lang) {

        $language_regexp['search'][$lang]       = '/\{'.$lang.'\}(.*?)\{\/'.$lang.'\}/is';
        $language_regexp['replace'][$lang]      = $lang == $language_current ? '$1' : '';

}

$content['all']                 = preg_replace($language_regexp['search'], $language_regexp['replace'], $content['all']);
$content["pagetitle"]   = preg_replace($language_regexp['search'], $language_regexp['replace'], $content["pagetitle"]);

?>
this is inside : /include/inc_script/frontend_render/ named it switch_Language.php

In conf.inc.php:

Code: Select all

$phpwcms['allowed_lang']      = array('en', 'de', 'fr', 'es');
with all those langs you need.

in your template:

Code: Select all

[PHP]
$url = "http://".$_SERVER['HTTP_HOST']. "/index.php?".$_SERVER['QUERY_STRING'];

echo "<a href=\"".$url."&lang=de\"><img src=\"picture/flag_de.gif\"></a>{SPACER:5x25}";
echo "<a href=\"".$url."&lang=en\"><img src=\"picture/flag_eng.gif\"></a>{SPACER:5x25}";
[/PHP]
whereever you need to have this .. flags I took into /picture

In content

each article:

Code: Select all

{DE} Bla bla bal{/DE}{EN}blu blu{/EN}
kind of self explaining.. I think

Thats all.. a very nice solution.. but remember there will be cookies for each lang, b4 you resignate testing this .. try different browsers ..

//EDIT : I run this on a site with the shop, try to get the shop also in 2 langs, kind of diificult for the moment...be back with solution if there is one ...
peteburgess
Posts: 18
Joined: Thu 9. Nov 2006, 20:29

Re: Multi Language Support

Post by peteburgess »

I like your solution DF6IH and thank you very much for posting.

Right now I think pepe's solution might be the best solution for the site I am working with. After reviewing it again, I feel it would work fine and also should be compatible with future upgrades since it is pretty much a redirect script for the corresponding page. Plus it gives me the ability to have the navigation translated as well. This can be achieved by having duplicate main categories for each language and then of course duplicate templates for each language. Make the navigations start from the ID of the main language category and it should be all set. (if that makes any sense lol if not, I can explain further) So I think this might be the best configuration. Thanks again and thanks pepe.
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Re: Multi Language Support

Post by marcus@localhorst »

Hi,
here is my strategy of a current multilingual site.
It's a hackfree, cookiefree, programming free way, that hopefully not conflicts with further multilanguage concept of phpwcms.

I've setup a structure in Admin like this:
+ Home (root)
++ Home (de)
++ Home (en)
++ Home (ru)
++ Home (zh)

for each language I need to setup an own template
since phpwcms 1.3.x (?) you can setup and reference a custom setting file which overwrite config/phpwcms/conf.template_default.inc.php.
(this file hold global dateformats and some formating stuff)
take a look at this file and take a look to template/inc_settings/custom_settings.php and you will see.

You can choose this custom file where you setup you template (for each language) or when you setup your categories [Home(de)]
so for Home(de) I choose the de.template/inc_settings/de.custom_settings.php for Home(ru) template/inc_settings/ru.custom_settings.php etc.

in these files I just enable the language relevant options and set a new variable so it looks like this:

Code: Select all

$template_default['language']		= 'de';
// date and time formatting
$template_default['date']['language']		= 'DE';         // DE=German, IT=Italian, FR=French
$template_default['date']['long']			= 'l, j. F Y';  // (Monday, 1. October 2003)
$template_default['date']['medium']			= 'D, j. M y';  // (Mon, 1. Oct 03)
$template_default['date']['short']			= 'Y/m/d';      // (2003/12/25)
$template_default['date']['article']		= 'Y/m/d';      // (2003/12/25)
$template_default['time']['long']			= 'H:i:s';      // 15:25:45
$template_default['time']['short']			= 'H:i';        // 15:25
thats the basic - the $template_default['language'] variable is now globally for each language available and can be used for custom programming.
then I setup my german basic site and when finished copying the whole german structure to the other language and set the custom_settings in template or structure to the right file.

the languageswitch on site looks like this:

Code: Select all

// index-de is the alias of each root
<div id="languagebox">
 [ID index-de]DE[/ID] [ID index-en]EN[/ID]
 [ID index-fr]FR[/ID] [ID index-es]ES[/ID]
 [ID index-ru]RU[/ID] [ID index-zh]CN[/ID]
</div>
the only thing that need to be programmed is a redirection to the right structure when switching language and I hope my idea is not so far away from olivers?! but I'm not shure. I imagine to set aliases in categories to other categories, to get an easier access in backend to related (other language) categorie - same in frontend.
but this is a basic idea that I need to figure out for a current project.

the {DE}Inhalt{/DE}{EN}Content{/EN} may work for smaller site with no complex content/text - but for bigger sites it's a pain in the ass I think, because of WYSIWYG Editors and linebreaks and loosing overview in longer texts.

yo, I hope you can follow me.
at the moment my solution works very well and the only thing I really need to figure out is the redirection to related cat when switching language and there is no logical connection between the language nodes in category setup and so new categorys and articles need to setup seperatly for each language - but that's the price in any multilanguage site ;-)

tell me what you think about that idea in general (Maybe Oliver can give some hints).

best wishes
marcus
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Multi Language Support

Post by juergen »

Hey Marcus, you are right.. ;)

I just thougt about the article aliases and building a switch with these as well ...

The {DE}-Tags iI described above are from a special Version and should not be used, Oliver said that they are out now... so Version switch will be .[DE]....[/DE] [EN],,,

will correct this in the upcomming holidays
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Re: Multi Language Support

Post by sustia »

Hi DF6IH, I've done all the things you describe, but with the [IT]bla bla bla[/IT], [ENG]bla bla [/ENG], etc. seems that it doen't work, while it works with the {IT}bla bla bla{/IT}...

I'm using the latest SVN version.

Thanks.
Campeones del mundo!
Vegetables!
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Multi Language Support

Post by juergen »

Hey sustia,

once in a while on a single version ( I would call the Fulvio Version) [] was {}, I mailed Oliver and now its back to [].. no matter ... we could have taken {[EN]} :mrgreen: , its only a qusetion of replacement ;)
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Re: Multi Language Support

Post by sustia »

Ok, anyway it works, great job.

Finally it's not more necessary to insert a level of the site for every language :D

Thanks.
Campeones del mundo!
Vegetables!
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Multi Language Support

Post by juergen »

hmm yes .. there aare pros and cons for such a solution ...
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Yes, of course..this solution allows to have a more orderly structure.
The problem could be that all the section must be translated or must have different templates, in order to implement or not such solution in the differents sections of the site.
Campeones del mundo!
Vegetables!
mmartin
Posts: 1
Joined: Mon 26. May 2008, 21:10

Re: Multi Language Support

Post by mmartin »

DF6IH wrote:Fresh in from playground:

Yesterday I saw http://forum.phpwcms.org/viewtopic.php?f=12&t=16845 this little beauty and I decided to remake the language switch:

My own howto for a site by site language switch, perhaps this may be done a little bit better, but for me so far ok:

from oliver Masterchief['phpwcms']:
...
this is inside : /include/inc_script/frontend_render/ named it switch_Language.php
...
How do I activate the scrip - it is in the template\inc_script\frontend_render\disabled\ folder - certainly it is not used there. Do I have to include it somewhere?
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Multi Language Support

Post by flip-flop »

Copy the file from
/template/inc_script/frontend_render/disabled/lang_replace.php
to
/template/inc_script/frontend_render/lang_replace.php

Have a look: http://code.google.com/p/phpwcms/source/detail?r=109
Simple frontend_render script to replace "non-active" language from current code. Wrap strings in
[de]Deutsch[/de] or [en]English[/en]. Only active language will be processed. To link against "new"
language set a ink anywhere in your document "index.php?mydoc&lang=de".
And a short description: http://forum.phpwcms.org/viewtopic.php?p=101091#p101091
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
Post Reply