Help with Extension

Hi everyone,

Apologies that this is a long post. A while back, I had spoken about my
idea for a simple language bar.

Background
For a site I’m building, there are a number of technical articles. Some
(not all) of these have been translated into other languages (not all
languages). So, what I wanted to achieve was to have a simple language
bar that included links to translations of the same article with
minimal effort.

Current Solution
I have come around to the idea that the whole site should be organized
with each language site being put under the root. So, under the home
page, there is “en” for English, “jp” for Japanese and so on. Each
language site is set up as having the exact same structure. I require
the slug for the page to be the same for translated articles. So,
‘intro_to_radiant’ would be the slug even if the exact URLs are:
example.com/en/tech/intro_to_radiant
example.com/jp/tech/intro_to_radiant
example.com/kr/tech/intro_to_radiant

Now, I’ve created a couple of tags that render the language bar by
iterating through the languages and changing the language base in the
URL. If find_by_url finds the language article, a link is rendered to
it.

Further, this is in a snippet and can be rendered quite neatly with
minimal effort.

Problems
OK, here’s the problem. Right now, I have 2 tags - one is something
like <r:site:lang_each> and the other is <r:site:langlink> – one
iterates over each of the languages in the list and the other renders
the link if it exists.

[1] The problem is that my <r:site:lang_each> iterates over each of the
languages without knowing if the translation exists. On the other hand,
the <r:site:lang_link> renders a link only if it exists. If I use a
list to render the links to the translations, it shows one bullet for
each iteration of the lang_each. I don’t know what to do.

[2] The other way would be to iterate over the possible languages in the
link tag itself (call it something else) and render the full language
bar. This affects how I can style it (things like separators, etc.)

Any ideas what I can do?

Cheers,
Mohit.
10/31/2007 | 1:57 AM.

Hello again. Wisdom comes minutes after you click on ‘Send’ asking for
help.

Silly me! What I needed to do was learn how to write a <r:teao:if_lang>
tag.

It’s been a good day. I’ve learnt how to:

  • write an iterator tag <r:teao:each>
  • write a conditional tag <r:teao:if_lang>
  • find the URL of the current page in an extension

And this is what the final snippet now looks like (gee, I like the 3Rs -
Radiant, Radius, Ruby):
This page is available in: <r:teao:each>
<r:teao:if_lang>

  • <r:teao:nulink /></r:teao:if_lang>
    </r:teao:each>

I know that the names of the tags need to be changed. If anyone is
interested in these tags, just get in touch.

Cheers,
Mohit.
10/31/2007 | 2:22 AM.

Just to complete this thread, here are a couple of examples of the
simple language bar on a site that’s under trial and design right now.

This shows links to 2 translations that exist:

http://tec.onghu.com/en/news/t-news-tron-show-2008/

This shows links only to the article itself because there isn’t any
other translation:

http://tec.onghu.com/cn/articles/ims_reference/

All this is rendered automatically through a snippet that’s part of the
layout and is based on the convention I’d described earlier.

At this point, I’d also like to express a word of thanks for the person/
people who created the copy_move extension. Getting the content aligned
like this would have been extremely tenuous if I had to do it myself!

Cheers,
Mohit.
11/1/2007 | 3:02 AM.