Search

A new extension, “Language Redirect” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

For an automatic global language menu (modify only the language part of the URL) you can use something like this.

<xsl:template name="automatic-language-menu">
    <xsl:param name="supported-language-codes" select="/data/events/language-redirect/supported-language-codes/item"/>
    <xsl:param name="current-language-code" select="/data/events/language-redirect/current-language-code"/>
    <ul id="language-menu">
        <xsl:for-each select="$supported-language-codes">
            <li>
                <xsl:if test=". = $current-language-code">
                    <xsl:attribute name="class">active</xsl:attribute>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test=". = $current-language-code">
                        <span><xsl:value-of select="."/></span>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="{$root}/{.}/{substring($current-path,string-length($current-language-code)+3)}"><xsl:value-of select="."/></a>
                    </xsl:otherwise>
                </xsl:choose>
            </li>
        </xsl:for-each>
    </ul>
</xsl:template>

Hi klaftertief,

Thank you for your extension, it seems very interesting for the website I would like to developp (in both french and english). Unfortunately, I’m just new with Symphony and I don’t understand how to install the extension (it works with other extension but not with this one). I follow what is said in the manual but the extension isn’t showing up in the admin part under “system > extensions”. Is it normal ? How can I do to install your extension. Thank you in advance !

Amandine

Hello Amandine,

when an extension doesn’t show up in the list of extensions it’s usually either a problem with access rights or with wrongly named extension folders. I changed the name of the extension folder/github project sometime ago and it should be language_redirect. This would be my first guess.

And thanks for trying out the extension. Feedback appreciated.

Jonas

Yes ! Thank you a lot, it works with the folder name “language_redirect”. I’ve been able to install it and I now try to figure out how it works. I’ll let you know some feedbacks then. Thank you : )

Amandine

Very good ! It works fine for displaying the menu and the right url of the pages. But I wonder how to add content in both english and french on the admin part. Have you got any ideas ?

You’ll have to be a little more specific there I think, two ways I interpreted your question could be…

  • You can change the language for each author under the Authors menu option.
  • If you wanted two languages to be input into a sections entries, you’ll need to use two fields in your section.

I hope one of these answers helps a little…

You can add the Language Field or a Select Box field with static or dynamic options to sections with content in different languages and filter your entries using the $url-language and/or $url-region parameters. This way you have each entry in a separate language.
Or you could add copies of individual fields to your sections and do the filtering in the XSLT. An example would be the name or caption field of an image section.

For static contents like page names or interface strings i usually create a dictionary section or dynamic datasource and use a template in a translation utility to translate those strings. I can post some code snippets tomorrow.

My answer would be an elaboration of designermonkey’s second interpretation.

Thank you very much for your advices, I have now a better idea of how to organize the section. As I’m just a newbie in Symphony, I’ll try and I’ll let you know then. Great idea as well about the “dictionary” section. Thank you : )

It’s all working well ! It’s a good combination to use both “language Redirect” and “Language Field”. Thanks a lot !! : )

Would someone be willing to demo the .htaccess method to pass $url-language to everypage?

Thanks,

Andy

The extension adds a ruleset like

### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de)-?(gb|us|de|ch)?/(.*/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end

just before the frontend rewrite ruleset. This way you have access to the $url-language and $url-region parameters on pages with URIs that start with something like /en/ or /en-gb/ or /de-de/.

Does this answer your question?

Is there a way to dynamically input the supported languages from the fields in a section? Authors with no access to the admin parts, cannot enter the supported languages by hand, also they already exist anyway in my section…

Is there a way to dynamically input the supported languages from the fields in a section?

No, this is out of the scope of the extension.

In general, the support for multi language content requires the management of the content in the backend (e.g. with a language field) and the the knowledge which language version to display. This extension is made for the latter and requires a developer to add the supported languages by hand in the preferences.

Wouldn’t it be possible to have the extension listen to a datasource that outputs the available languages based on the language fields? Or on the DS-param?

I only have one entry per langauge so to me that makes sense, maybe its different in other setups?

The extension adds a set of rewrite rules with the supported languages in the .htaccessfile when you save the preferences. The rewrite rules could be generalized to support an unlimited number of languages. But then you have to be careful with choosing your page handles. Have to think about it.

I see u use the Method: getBrowserLanguages in the class.lang.php from symphonies toolkit, thisone matches both 2 letter languages, as 5 letter language and locale codes like

'en-us'

I found this very inconvenient. besides ugly url handles, it also obliges the admin to set all possible en-whatnot versions, because one can not expect that browsers start their preflist with ‘en’, and then continue with;

en,en-au,en-bz,en-ca,en-ie,en-jm,en-nz,en-ph,en-za,en-tt,en-gb,en-us,en-zw

In fact safari wrongfully only send the first language accept header, being often en-us.

So better would be to not only match identical pairs, but just any language code before the dash. In order to acheiev this I have hacked the core and removed

(?:-w+)

from the match pattern. However, it would be better if this function was replicated in your extension.

The rewrite rules could be generalized to support an unlimited number of languages. But then you have to be careful with choosing your page handles. Have to think about it.

Finishing this off with such rules, and joining advising people to create a selection field from a static (or dynamic from iana) list of 2 letter xml language codes (no locale) would make this a killer extension.
This would also solve the problem of the node with languages supplied for your navigation doenst contain the languages in full words…

I am pulling in the language codes via their event xml made into an xml page that feeds a xml-selectbox. So now in my entries you just select from the available languages in a dropdownlist. The full language names are missing ofcourse, but I could match them up with the available items, from an xml file with languages and their codes.

then again I could just use that list for a selectbox, and still feel it would be better the extension then takes its languages from the entries. or rather the rewrites don’t need languages.

I have some nice svg ideas for worldmap country and language selection too, if you’d even go further…

Thanks for your help works well looks like it will do the trick.

Is there a way to add a default redirect to the .htaccess file so if no langauge is specified in the URL it redirects to a default:

mysite.com/en/apage

Hopefully this is easy I hust have a fear of .htaccess files.

Andy

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details