ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Multilingual templates and plugins

December 08, 2009 9:30am

Subscribe [4]
  • #1 / Dec 08, 2009 9:30am

    sambo

    80 posts

    Hi,

    I am researching my options for a multilingual site.  How would you go about if you want all of the following to be multilingual:

    - Content. I am thinking one weblog for each language because url titles must be translated.
    - Templates. I am thinking about either the Multi Language Module or the one from LG
    - Custom plugins.  There will be a lot of functionality delegated to custom plugins and they must be multilingual. I would like to be able to maintain the strings for the plugins the same way I will do it for the templates but I might not be able to.

    Best,
    Sammi

  • #2 / Dec 08, 2009 11:27am

    Ross1988

    59 posts

    can’t answer for the custom plugins, but there’s a very elegant solution i was able to implement with help from
    Can Berkol (http://www.biberltd.com/)

    http://expressionengine.com/wiki/Multi_language_approach/

    you can have different language URLs, even different templates for a specific language if required..

    the idea is

    {if language_code=="fr"}
    // do something for a french user
    {embed="french-templates/home"}
    {/if}
    
    // or
    
    {exp:weblog:entries weblog="latest_news"}
    {{language_code}_body} //etc
    {/exp:weblog:entries}

    then in your weblogs you have custom fields like:

    fr_body
    fr_summary
    en_body
    au_body

    etc etc.

    add your translated content, and you’re good to go

  • #3 / Jan 21, 2010 6:00pm

    biberltd

    54 posts

    Thanks Ross for naming me.

    Sammi for the text that is not generated by weblogs etc. what we do isn’t a very elegant solution but an easy and fast fix.

    In addition to the extansion/method that we are using as stated on the link that Ross provided, we create a language file i.e. lang.custom.php within the language folders of each language. This file holds i.e. an array called $L that holds site text.

    i.e. $L[‘jump’]= ‘jump’;

    Then on EE admin / templates / pereferences; we enable PHP (input) we put these lines of code at the beginning of the template

    <?php
    $include_path = $_SERVER['DOCUMENT_ROOT'].'/system/language/{language}/lang.custom.php';
    $default_path = $_SERVER['DOCUMENT_ROOT'].'/system/language/turkish/lang.custom.php';
    if(!file_exists($include_path)){
    include($default_path);
    }
    else{
    include($include_path);
    }
    ?>

    {language} variable is set before (if you apply the explained method) as global. So if language is set to English it outputs english.

    $include_path is the path to be included.
    $default_path is the path to the language file of your sites default language. In our case it is Turkish.

    So if {language} is set you call the custom language file located at user requested language folder. If that file does not exist (in other words if translation does not exist) you call the default file.

    Then within template we use this line of code to output the text we want.

    <?php echo $L['jump'];?>


    Is that helpful for a start?

  • #4 / Jan 21, 2010 6:22pm

    sambo

    80 posts

    Hi,

    thank you for spending your time on this.

    This sounds like an interesting approach. As you say it is maybe not very elegant since your have to enable php on all templates and the webmaster has to edit three different files to add/change language string.

    However - it is a working solution that might very well come in handy.

    For my current site I have done this:

    - content that is NOT supposed to exist in all languages is kept in separate weblogs
    - content that is supposed to exist in all languages is kept in weblogs with fields for each language.
    - I used the commercial Multi Language Module for localizing templates phrases
    - I have not found a way to have my plugins return a “language phrase index” for Multi language Module to turn into a localized string so I cheated.  Instead of plugins I create templates where PHP is allowed and just write my code in that template.  Shame on me - but it works and I can have the plugins return localized strings.

    Best,
    Sammi

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases