In my site [currently being tried out at 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.
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.
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
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, …]
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
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.
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.
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.
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
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).
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.
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.