# Help with Extension

**URL:** <https://www.ruby-forum.com/t/help-with-extension/118766>\
**Category:** Radiant CMS\
**Created:** [October 30, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/help-with-extension/118766 "2007-10-30T18:58:47Z")\
**Posts on this page:** 3\
**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:** [October 30, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/help-with-extension/118766/1 "2007-10-30T18:58:47Z")

</div>

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](http://example.com/en/tech/intro_to_radiant)  
 → [example.com/jp/tech/intro\_to\_radiant](http://example.com/jp/tech/intro_to_radiant)  
 → [example.com/kr/tech/intro\_to\_radiant](http://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.

---

<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 30, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/help-with-extension/118766/2 "2007-10-30T19:24:33Z")

</div>

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.

---

<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 31, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/help-with-extension/118766/3 "2007-10-31T20:08:02Z")

</div>

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/](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/](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.
