Snippet: Language Switcher

doc

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:

<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]

doc

#4
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):

(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).
<?php
if (function_exists('switchLanguage')) {
   
switchLanguage(array('EN' => 12'DE' => 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

Regards Doc

P.S.: There exists another interesting solution worked out by the forum member FrankH: Easy Multilanguage Link which requires some smaller core file modifications.

Note: Download removed as a newer version is available in this thread.

Stefek

Hello Doc.

I like (and will use) your snippet anyway.

It's very handy so far.

Thank you for your efforts!

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Stefek

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
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

doc

#1
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.