WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: doc on June 01, 2009, 12:25:46 AM

Title: Snippet: Language Switcher
Post by: doc on June 01, 2009, 12:25:46 AM
If you search for similar ones, please have a look at Language Matrix or the language switcher module from the authors Iceat and Luisehahne.

Regards Christian

Removed outdated version.
Title: Re: Snippet: Language Switcher
Post by: Stefek on June 01, 2009, 01:38:50 PM
Hello Christian.

The new features works great!

There is only a problem if you have some alterations in the page trees of the different (tested with 2) languages.

Example:

DE
- Start
- mein Test
-- erster Test
-- zweiter Test

- meine Ergebnise
-- bestes Ergebnnis
-- mittleres Ergebnis

- Preise und Ehrungen
       
EN
- Welcome
- my Test
-- firstTest

- my Results
-- best Result

- Awards


Up to firstTest/ersterTest everythig is going fine.

It means the snippet works only good if you have the same structure in all your languages.

 :|

The same Problem appears if you have the same structure and then you switch one of your pages to "hidden".

Regards,
Stefek
Title: Re: Snippet: Language Switcher
Post by: Stefek on June 01, 2009, 03:13:17 PM
Hello Doc.

I like (and will use) your snippet anyway.

It's very handy so far.

Thank you for your efforts!

Regards,
Stefek
Title: Snippet: Language Switcher (v0.30)
Post by: doc on July 20, 2009, 09:15:55 PM
Hi,

Martin (mr-fan) has send me a German and English README file for the code snippet: "Language Switcher". Therefore I decided to release the latest version in this thread.

Basics:
This snippets allows you to switch the current displayed page to another language. The snippets requires the same amount and order of pages in the page tree for each supported language (e.g. EN, DE).

For each language, one has to set-up an identical page tree (amount + order of pages). If a page does not exists in English, but in German, one needs to create a "dummy-page" for that missing English page. A "dummy-page" is a page without content and the visibility set to "NONE".

Example (from the README file):
Code: [Select]
(Container - German)    (Container - English)
DE.php                    EN.php (page name as you like, recommended: EN, DE, NL ...)
  - Startseite             - Home
  - Seite 1                - site 1
  - Seite 2                - no "site 2" exists (create dummy-page; visibility:= "NONE")

Using the Snippets:
Install the snippet via the backend. Then invoke the new function switchLanguage from the index.php file of your template (or a page/section of type code).
Code: [Select]
<?php
if (function_exists(&#39;switchLanguage&#39;)) {
   
switchLanguage(array(&#39;EN&#39; => 12, &#39;DE&#39; => 14));
}
?>
The example assumes that the English container page has the page_id 12, the German one 14.

Further information can be found in the Germand and English READM files located in the moduel folder: /modules/switch_language/help/.

Pros and Cons of the module:
 + does not need any further information to switch pages (e.g. tags, page_id)
 + function needs to be invoked once, thats it (invoke with ALL container pages like DE, EN, ...)
 + flag icons are created automatically
 - page tree (amount and order of pages) must be identical for ALL languages
 - if no page exists for a certain language, you have to create a dummy-page (no content, visibility: NONE)

Martin, thank you very much for the READMDE files.

Link to German forum thread: click here (https://forum.WebsiteBaker.org/index.php/topic,12726.msg91753.html#msg91753)

Regards Doc

P.S.: There exists another interesting solution worked out by the forum member FrankH: Easy Multilanguage Link (https://forum.WebsiteBaker.org/index.php/topic,14037.0.html) which requires some smaller core file modifications.

Note: Download removed as a newer version is available in this thread.
Title: Snippet: Language Switcher v0.40
Post by: doc on August 29, 2009, 08:12:21 AM
Hi,

as requested by the forum member mr-fan, I added IDs to the language flag icons created by the code snippet for better access and styling with CSS. The default flag output is as follows:

Code: [Select]
<a href="page.php" target="_self" title="DE">
<img id="flag_icon_de" class="flag_icon" src=".../images/DE.gif" alt="DE" />DE
</a>

Regards Doc

[gelöscht durch Administrator]
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on June 26, 2010, 11:34:35 AM
  Php Error with switch_language modul
« on: June 25, 2010, 05:03:19 PM »     

--------------------------------------------------------------------------------
I've already posted this topic in the modul forum but think it's more specific here

Hello,
I've just encoutereed a problem with the switch_language modul :

Notice: Undefined index: 692 in /home/xxxx/public_html/xxxxxx/xxxxx/modules/switch_language/include.php on line 170

This line is repeated 6 times from index 687 to index 692.

I have other multi languages websites wit non problem. There was no problem until (I suppose) I've installed calendar-v2 + calendar month + calendar month link. I deleted the 3 moduls + the swtich language then re installed the switch language but I have the same errors. The EN and FR pages are creaed equal.

An idea ?

Regards
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on June 26, 2010, 05:42:27 PM
I've updated the php code in the index.php (commented and then uncommented the php coe) and now it works like before.
Weird, but
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on January 23, 2011, 12:47:02 PM
Hello,

I'm using language switcher and the by default showing, I mean the flags.

How could I use this module to show the langusges in a drop down menu ?

Regards
Title: Re: Snippet: Language Switcher
Post by: kweitzel on January 26, 2011, 10:11:57 AM
It seems to me nobody is actively interested in this Module.

cheers

Klaus
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on January 27, 2011, 06:19:22 PM
It's weirf because it's used. And 'Doc' isn't part of ths forum anymore ?
Regards
Title: Re: Snippet: Language Switcher
Post by: kweitzel on January 27, 2011, 07:44:44 PM
The fact that it is in use does not mean, that anybody is interested in developing it anymore (unfortunately). And DOC decided not to participate.

cheers

Klaus
Title: Re: Snippet: Language Switcher
Post by: Stefek on January 27, 2011, 08:37:34 PM
Hello,

I'm using language switcher and the by default showing, I mean the flags.

How could I use this module to show the langusges in a drop down menu ?

Regards


Hello, you want to have the switcher with a combobox of HTML Element "select->option"?, like here?:
http://www.w3schools.com/tags/tag_select.asp
Without images?

Regards,
Stefek
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on January 27, 2011, 11:48:32 PM
Hello Stefek and thanks for your response.

Yes, I'd like a combo box (with the flags why not), but don't know what php code to assign and where.

Regards
Title: Re: Snippet: Language Switcher
Post by: Stefek on January 28, 2011, 12:04:27 AM
(with the flags why not)
Hello,
the problem with flags is, that some browsers doesn't support hem.

Regards,
Stefek
Title: Re: Snippet: Language Switcher
Post by: mylesk42 on January 28, 2011, 09:38:35 AM
If you know where to change the code to show a combo box (without flags), you're welcome !

Regards
Title: Re: Snippet: Language Switcher
Post by: D72 on July 05, 2012, 09:31:03 AM
I know, it's been a long time people actually used this topic.
But as the module is still working nicely, i do have a "simple" question about this module.
Language snippet (http://www.websitebakers.com/pages/code-snippets/various/language-switcher.php?searchresult=1&sstring=Language+Switcher)
How can i add a unique class/id to create a current menu item?
The code in my index is like:
Code: [Select]
<?php
    
if (function_exists('switchLanguage')) {
       
switchLanguage(array('EN' => 1'NL' => 2'CN' => 46), 
        
'<a href="[url]" target="_self" title="[lang_id]">[img] <!--[lang_id]--></a>');
 }
?>
I really would like to make use of it so people can see straight away which language is active.
Sure, they can see it in the content... but giving the current flag a class would be nice though.
Hope someone has a clue.
Title: Re: Snippet: Language Switcher
Post by: marmot on July 05, 2012, 09:18:19 PM
Hi,

Hope someone has a clue.
This ist not tested:
Insert code at line 83 of include.php so it looks like
Code: [Select]
if ($root_parent == $lang_id) $url.= '" class="curr_lang';
// create image or text links for the language switcher
This should add the class "curr_lang" to the link of the active language.

regards
Title: Re: Snippet: Language Switcher
Post by: D72 on July 05, 2012, 09:22:29 PM
Holy crap
Thats fast. I thought no one would read or respond hah
Ill test it tomorrow at the office. Looks promissing.
Thanks marmot so far.

Hi,

Hope someone has a clue.
This ist not tested:
Insert code at line 83 of include.php so it looks like
Code: [Select]
if ($root_parent == $lang_id) $url.= '" class="curr_lang';
// create image or text links for the language switcher
This should add the class "curr_lang" to the link of the active language.

regards
Title: Re: Snippet: Language Switcher
Post by: D72 on July 06, 2012, 09:12:49 AM
Sorry Marmot, the snippet doesn't work. Thanks though for your contribution!
Title: Re: Snippet: Language Switcher
Post by: marmot on July 06, 2012, 10:00:48 PM
Hi,

sorry that first try didn't work.
Maybe you want to give this one an other chance and make lines 76 - 84 look like this:
Code: [Select]
// build image link if exists
$img = '';
$curr_lang = '';
if (stristr($page_tree[$root_parent][0]['link'],PAGES_DIRECTORY.'/'.$lang_id.'/') !== false) $curr_lang = ' curr_lang';
if (file_exists(dirname(__FILE__) . '/images/' . $lang_id . '.gif')) {
$img = '<img id="flag_icon_' . strtolower($lang_id) . '"' .
' class="flag_icon'.$curr_lang.'" src="' . WB_URL . '/modules/switch_language/images/'
. $lang_id . '.gif" alt="' . $lang_id . '" />';
}
this adds class "curr_lang" to the <img> tag instead of the <a> tag. Thought this makes more sense. This time I made a fast test and it worked for me.

regards
Title: Re: Snippet: Language Switcher
Post by: D72 on July 09, 2012, 09:48:37 AM
ah, that is just great. Thanks in a million Marmot!
Title: bugfix
Post by: dfens on January 11, 2013, 02:13:20 PM
here is a bugfix which really fckd me up , randomly loosing pages in the tree after moving them around: :evil:

in include.php line 140

replace
Code: [Select]
$temp[$row['root_parent']]['sub'][] = str_replace($row['root_parent'] . ',', '', $row['page_trail']);
with

Code: [Select]
$temp[$row['root_parent']]['sub'][] = preg_replace('/^' . $row['root_parent'] . ',/', '', $row['page_trail']);
so a page trail like 6,126,140 won't be 12140 but 126,140

have fun
Title: Re: Snippet: Language Switcher
Post by: CodeALot on July 15, 2014, 11:51:28 AM
Hello Stefek and thanks for your response.

Yes, I'd like a combo box (with the flags why not), but don't know what php code to assign and where.

Regards


I too would like to use this snippet with a drop-down-menu. No need for flags, no need to show the current language (I mean... that would be obvious looking at the page itself, right? :) ) - Anyone?
Title: Re: bugfix
Post by: CodeALot on July 15, 2014, 01:37:27 PM
here is a bugfix which really fckd me up , randomly loosing pages in the tree after moving them around: :evil:

You rock. Thanks!
Title: Re: bugfix
Post by: CodeALot on July 17, 2014, 05:33:43 PM
here is a bugfix which really fckd me up , randomly loosing pages in the tree after moving them around: :evil:

Seems I replied too soon... It still isn't working right. Let's say I have 4 main pages, each with a subpage.
(1, 1A, 2, 2A, 3, 3A, 4, 4A)

I'm on 1A. I click the language switch, and I'm sent off to 3A in the other language. As if the Switch Language is ignoring Page-position.

All structures are exactly the same, all the same pages, same order etc. And still... it's not working.

But as with so many things about WB, the author has left the building, and nobody seems to give a @#$#@ anymore. Guess I'll change my language switch to a dumb "go the homepage of that other language" option. :-((
 
I'll leave the light on, in case someone walks by who has a clue how to fix my little problem. There's beer in the fridge. Make yourself at home.
Title: Re: Snippet: Language Switcher
Post by: Gast on July 17, 2014, 06:03:21 PM
i use the multi_linguale module from here
http://www.WebsiteBaker.org/forum/index.php/topic,27345.msg188623.html#msg188623

works without problems
Step 1:  build your page tree in the main language
Step 2: build a page tree or a part of the page tree from the sub languages
Step 3: select your "target" page (from the main language)  in the select field "page code"

works without problems for me with a flaggs menu
Title: Re: Snippet: Language Switcher
Post by: cwsoft on July 17, 2014, 06:36:14 PM
Hi,

But as with so many things about WB, the author has left the building, and nobody seems to give a @#$#@ anymore.
Well the author is still around, but indeed doesn't give a @#$#@ anymore, as a WB core replacement and a similar module exists, which makes this snippet obsolete. No big user base, no further development :wink:

Cheers cwsoft
Title: Re: Snippet: Language Switcher
Post by: CodeALot on July 18, 2014, 10:19:14 AM
i use the multi_linguale module from here
http://www.WebsiteBaker.org/forum/index.php/topic,27345.msg188623.html#msg188623

works without problems
Step 1:  build your page tree in the main language
Step 2: build a page tree or a part of the page tree from the sub languages
Step 3: select your "target" page (from the main language)  in the select field "page code"

works without problems for me with a flaggs menu

Thanks for the pointer, but I can't find anywhere how to use it...  :-D

I installed it, in the page settings screen I now see a new option to set a Page code, should that point to the same page but in the other language?
Does that mean I can 'only' use two languages?

Your help is much appreciated!
Title: Re: Snippet: Language Switcher
Post by: Gast on July 18, 2014, 12:29:25 PM
Quote
Does that mean I can 'only' use two languages?
there are no limits, i use it with 8 different languages in one project, no problems

for example

english is your main language, you have a page tree like your post (1, 1A, 2, 2A, 3, 3A, 4, 4A) in all languages. sub languages are german, french etc
open your german page 3A, go there to the pages setting and select your english target page (main language page 3A). do the same for the other sub languages and for every page in your page tree

use this code in your template index.php for the flag menu
Quote
<div id="lang_menu"><?php if(function_exists('language_menu')){ language_menu('png'); } ?>
</div>

this code build a menu like this
Code: [Select]
<div id="langmenu">
        <a href ="page_link" title="lang_name" >
        <span><img class="default" src="page_lang.gif" alt="lang_name" title="lang_name" />
        </span></a>
        <a href ="page_link" title="" >
        <span><img class="default" src="page_lang.gif" alt="lang_name" title="lang_name" />
        </span></a>
        <a href ="page_link" title="" >
        <span><img class="current" src="current_lang.gif" alt="lang_name" title="lang_name" />
</span></a>
</div>

it builds a menu with flags for every language. a language tree must have (minimum) 1 page to show the flag in your flag menu. if you not select a target page, the flag link goes to the start page from this language

Title: Re: Snippet: Language Switcher
Post by: CodeALot on July 18, 2014, 01:44:46 PM

english is your main language, you have a page tree like your post (1, 1A, 2, 2A, 3, 3A, 4, 4A) in all languages. sub languages are german, french etc
open your german page 3A, go there to the pages setting and select your english target page (main language page 3A). do the same for the other sub languages and for every page in your page tree

Thanks, I'm on it. :) 216 pages to do.... Bweeh! LOL But at least it's possible. Now let's hope WB will behave... It is known to have some problems handling large amounts of pages....

Thanks again!