# Handling multiple languages

**URL:** <https://www.ruby-forum.com/t/handling-multiple-languages/114234>\
**Category:** Radiant CMS\
**Created:** [September 10, 2007, 10:18am UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234 "2007-09-10T10:18:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 10:18am UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/1 "2007-09-10T10:18:15Z")

</div>

Hi Everyone,

In my site [currently being tried out at [http://tec.onghu.com](http://tec.onghu.com) ] that is  
powered by Radiant, I have a number of articles and news pieces. For  
some of them, translations in other languages exist. In those cases,  
when I display the article, I would like to show a link to the same  
article in a different language.

So, if I have the article in English, Thai and Chinese, and you are  
viewing the English version, I’d like to also show in the “Language  
Bar”, the option to “View this article in [Thai] | [Chinese]”. If  
you’re viewing it in Thai, it would show “View this article in [English]  
| [Chinese]”

Do you have any recommendation on how I should go about this? I don’t  
think this exactly maps to the ‘Language Redirect Behaviour’ but if it  
does, I’d like to be corrected.

Thanks,  
Mohit.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/2 "2007-09-10T15:58:34Z")

</div>

Interesting problem. No, the language-redirect behavior/extension  
reads the preferred language sent by your browser and sends the user  
to a whole different subsite based on that language. Multiple  
language support in Radiant is still very nascent; we’d love to hear  
some ideas or see some unique solutions.

Sean

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 4:10pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/3 "2007-09-10T16:10:36Z")

</div>

Hi Sean,

This is what I have in mind for it right now. I didn’t want to propose  
anything in the first email so that I wouldn’t bias people 🙂

Given the Rails philosophy, this ‘workaround’ assumes a few things -  
let’s call it convention over configuration 😃

1. I was thinking that it should be possible to maintain a list of  
languages that are currently available in the system. I’m not sure what  
would be the best place for this (either the DB or YAML or config or  
something) but let’s not get bogged down by that yet. So, we have a  
file that has a list of languages that are supported = [TH, EN, CN, MY,  
ES, JP, KR, …]

2. Now, we ensure that every article that is created in a different  
language has the same name in every language but it is in a different  
‘subsite’ so to speak. So, you have  
/hello\_world \<- main english site (primary language)  
/es/hello\_world \<- Espanol  
/my/hello\_world \<- malay  
/…/hello\_world

3. When we render a page, first we extract the base name of the page  
[hello\_world] above. Then, when we render the ‘language bar’ for a  
page, we go through the list of supported languages and try to look for  
/th/hello\_world, /cn/hello\_world, /my/hello\_world, … and  
/hello\_world (for the main site)  
If the find URL succeeds, we render a link for it.

4. Additionally, we could have a piece of JavaScript that checks to see  
if the name that you are adding exists in another language when you add  
it in - and alerts you if it does. That gives you a visual check if 2  
articles have similar names or if you expected that this is a  
translation for another article and you got the name slightly wrong.

What do you think? I have no idea what kind of performance constraint  
this might impose.

That’s my first thought. Now I have to think of going about  
implementing it if it seems like the way forward.

Cheers,  
Mohit.  
9/10/2007 | 10:08 PM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 6:16pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/4 "2007-09-10T18:16:03Z")

</div>

The scheme described by Mohit below addresses the selection of the  
language, but we still need to store the translations.

```
 Given the simple tree structure of Radiant pages, i don't think 

```

that  
duplicating the pages in different languages is a good idea. A solution  
could be:

```
 - define different page parts for the language versions. For 

```

example,  
have the parts “body\_en”, “body\_fr” and “body\_es”. Or just “body”,  
“fr”,  
“es”. They could be “special parts” or not.

```
 - let Radiant choose the correct part, using the method described 

```

by  
Mohit or by other means

```
 - i don't like the idea of duplicating the tags (structure) of the

```

page, so there must be a way to define a page template and then connect  
that  
page to the translations in the different parts. One solution could be  
to  
define \<trans(late)\> tags that are used like:

```
 <r:trans id="select_child">Please select a child:</r:trans>
 <r:children:each> ... </r:children:each>

In this case the page is defined in english, and the translations 

```

are  
stored in the page parts and indexed by the translation id. Maybe  
replace  
the tags by some other syntax sugar like the “\_”, “$” or other  
symbol.

```
 - the translation of dates etc. must be also handled. For this and

```

more things it would be wise to take a look to how things arte done in  
other  
Rails i18 plugins like Globalize.

```
/AITOR
```

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/5 "2007-09-10T16:42:40Z")

</div>

i need a good multi-language facility also and would be happy to help  
implement if this idea is the way fwd.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/6 "2007-09-10T20:00:19Z")

</div>

Mark, Aitor,

Thanks for your mails. Actually, my needs are simpler - that’s where  
the idea started out. In my case,

Aitor - I agree that it seems a bit of a waste to duplicate the tags,  
but I’m not sure if there will be different tags for different  
languages. Also, there may be multiple parts to a page each of which  
may need to be in a different language. In my case, there are  
differences that come in due to:  
[1] Each language is probably maintained by a different person.  
[2] Each language may have a separate set of articles - there is no  
guarantee that every article will exist in English. It’s likely that  
there are some articles that are present in only one of the languages.

A lot may depend on how similar/ different the multiple language sites  
are.

I think there are still a few unresolved issues :-S

Cheers,  
Mohit.  
9/11/2007 | 1:59 AM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 10, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/7 "2007-09-10T23:08:49Z")

</div>

On 9/10/07, Aitor Garay-Romero [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> - define different page parts for the language versions. For example,
> 
> ```
> 
> have the parts “body\_en”, “body\_fr” and “body\_es”. Or just “body”, “fr”,  
> “es”. They could be “special parts” or not.

I agree with this, some weeks ago I spent some time thinking about it.

The dafult language could be the browsers one, or other after selected  
by the user.

## – Sylvestre Mergulhão - Free Software Development

[http://mergulhao.info](http://mergulhao.info)  
[http://www.euemeu.com](http://www.euemeu.com)

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 11, 2007, 10:29am UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/8 "2007-09-11T10:29:52Z")

</div>

For this idea we also need “parts” for layouts and snippets, since they  
must be translated too.

/AITOR

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 10, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/9 "2007-10-10T14:21:18Z")

</div>

I guess I mist this when posted, but this is really cool. Thanks !

On 9/13/07, Loren J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the user to switch. The default is the browser language…the README  
> upon the current cookie value for language,  
> |
> 
> ```
> <h4>FranÃ§ais</h4>
> <h4>Deutsche</h4>
> <r:matches value="en" default="true">
> 
> ```
> 
> > > > “es”. They could be “special parts” or not.
> > > 
> > > * * *
> > 
> > Radiant mailing list  
> > Post: removed\_email\_address@domain.invalid  
> > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
met vriendelijke groet,

Peter B.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/10 "2007-09-17T13:25:29Z")

</div>

I’m a little late to the discussion, but here is the solution I  
recently implemented for a client based on similar needs:

[http://svn.fn-group.com/radiant\_extensions/language\_switch](http://svn.fn-group.com/radiant_extensions/language_switch)

I think it may be useful as-is but at least should be worth  
referencing. There is some hackery involved with using the cookies to  
store the current language preference and a set of tags for allowing  
the user to switch. The default is the browser language…the README  
reads thus:

= Language Switch

This extension creates a set of tags and page routing which responds  
to a cookie stored language variable that is  
settable and resettable through the “language” query parameters (e.g.  
[http://yoursite.com/your\_page?language=en](http://yoursite.com/your_page?language=en)).

When this parameter isn’t present the language selected will be based  
upon the current cookie value for language,  
or if this value is also blank then the default acceptable languages  
in the client’s browser will be responded to.

= Full text sample/text code (no, there is no Bulgarian sample  
content… that’s to show that the default work 🙂

## Language Switcher
English | Spanish | French | German | Bulgarian | Reset
## Content

#### Español

Diez soldados estadounidenses murieron a causa de bombas en carreteras y al estrellarse un helicóptero en Irak, mientras cinco británicos fueron secuestrados en el Ministerio de Hacienda iraquí, dijeron el martes las autoridades.

#### Français

Ces dernières semaines, le Brésil s’est d’ailleurs souvenu de la répression qui avait enrayé une vague de violence, il y a un an à Sao Paulo, avec un très lourd bilan : 493 morts en à peine six jours. Entre les 12 et 19 mai 2006, le Premier commando de la capitale (PCC), l’un des gangs mafieux les plus puissants d’Amérique latine, avait orchestré une série d’attaques contre les forces de l’ordre, semant la terreur parmi les 11 millions d’habitants de la ville.

#### Deutsche

Die Innenminister von Bund und Laendern beraten heute und morgen ueber den Poli zeieinsatz waehrend des G8-Gipfels in der kommenden Woche in Heiligendamm. Bis zu 16.400 Polizisten sollen waehrend des Treffens der Staats- und Regie rungschefs der fuehrenden Industriena tionen zum Einsatz kommen. Wie nah Glo balisierungsgegner dem Tagungsort kom men duerfen, ist noch unklar. Gestern wurde der zwoelf Kilometer lange Zaun um das Gelaende geschlossen. Fuer eine Woche duerfen nur die Bewohner und besonders Berechtigte in das Gebiet.

#### English (default)

Is new software a key component to growth or essential to your new business idea? Rapid prototyping and constant evaluation can insure you only build exactly what need; nothing more, nothing less.

### Browser Languages

Thanks,

Loren J.

> **[Resume - Loren Johnson](https://docs.google.com/document/d/1WfJomBItrSA281MMFbYpavEKLMkQAfG9pz0or0X5lBU/edit?usp=sharing)**
>
> LOREN JOHNSON 575-779-9996 | lorenjohnson@gmail.com | github.com/lorenjohnson | linkedin.com/in/johnsonloren EXPERIENCE Senior Software Engineer	April 2020 - Current Hylo.com – Terrans Collective Working full stack in Node, GraphQL, React, and...

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 10, 2007, 4:00pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/11 "2007-10-10T16:00:49Z")

</div>

Peter,

I’m glad this looks like something you can use. Let me know how it  
goes. The extension was developed for a client whose translated site  
has not yet been put into production so this extension is somewhat  
untested. It works and hopefully your purposes won’t reveal any dark/  
sharp corners.

Good Luck,

Loren

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 10, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/handling-multiple-languages/114234/12 "2007-10-10T19:46:23Z")

</div>

No problem, thanks for the headsup anyway

if I run into something I will try to fix it and mail you the patch.

Peter.

On 10/10/07, Loren J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Good Luck,
> 
> > > 
> > 
> > Post: removed\_email\_address@domain.invalid  
> > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
met vriendelijke groet,

Peter B.
