Page i18n

Simple internationalization for pages and lists

#1. Features

  • Internationalized pages with no corehacks required.
  • Based on category trees with alternative language branches.
  • Built-in friendly URLs/SEO solution.
  • On-the-fly language selection.

#2. Installation


1. Install the plugin.

2. Configure the list of available languages in Admin => Config => pagi18n, separating ISO codes with |.

3. Add following rules to the top of your URL transformation (either via Admin => Other => URLs or by editing datas/urltrans.dat):

list	c=*	{pagi18n_cat_url()}
page	al=*	{pagi18n_url()}

4. Add these rewrite rules to your .htaccess:

# Categories
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ list.php?c=$1-$2-$3-$4-$5 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ list.php?c=$1-$2-$3-$4 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ list.php?c=$1-$2-$3 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/$ list.php?c=$1-$2 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/$ list.php?c=$1 [QSA,NC,NE,L]

# Pages with aliases only
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\-]+) page.php?al=$6_$1 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\-]+) page.php?al=$5_$1 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\-]+) page.php?al=$4_$1 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\-]+) page.php?al=$3_$1 [QSA,NC,NE,L]
RewriteRule ^(en|ru)/([a-zA-Z0-9_\-]+) page.php?al=$2_$1 [QSA,NC,NE,L]

where (en|ru) is your language codes separated with pipe sign.

These rules assume that max. level of category nesting is 4. If you have more, you can add rules for them after studying the above example.

5. Add language selector tags in header.tpl, use LANG_ROW block for rows within the language selector, e.g.:

<div id="lang">
	<!-- BEGIN: LANG_ROW -->
		<a href="{LANG_ROW_URL}" class="{LANG_ROW_CURRENT}" title="{LANG_ROW_NAME}">{LANG_ROW_CODE}</a>
	<!-- END: LANG_ROW -->
</div>

6. Configure your category structure and start adding pages (see below).
 

#3. Usage


#3.1. Making category tree


To enable i18n on a part of your category tree or the entire category tree, you need to use a special naming scheme for it. Category codes consist of parts, containing language information, parent category codes and currrut category code. The parts are imploded with hyphen into full code of category. Alternative language subtree is absolutely the same, but it has a differrut language root.

Here is an example category tree available in 2 languages (English and Russian). Each line represents a category, starting with path numbers, then follows the code and displayed title in parenthesis.

1 en (English)
1.1 en-articles (Articles)
1.1.1 en-articles-tech (Technical)
1.1.2 en-articles-fiction (Fiction)
1.1.3 en-articles-economy (Economy)
1.2 en-news (News)
1.3 en-goods (Goods)
1.3.1 en-goods-food (Food)
1.3.1.1 en-goods-food-fruits (Fruits)
1.3.1.2 en-goods-food-fast (Fast Food)
1.3.1.3 en-goods-food-cakes (Cakes)
1.3.2 en-goods-computers (Computers)
2 ru (Русский)
2.1 ru-articles (Статьи)
2.1.1 ru-articles-tech (Технические)
2.1.2 ru-articles-fiction (Художественные)
2.1.3 ru-articles-economy (Экономика)
2.2 ru-news (Новости)
2.3 ru-goods (Товары)
2.3.1 ru-goods-food (Еда)
2.3.1.1 ru-goods-food-fruits (Фрукты)
2.3.1.2 ru-goods-food-fast (Фаст-фуд)
2.3.1.3 ru-goods-food-cakes (Пирожные)
2.3.2 ru-goods-computers (Компьютеры)

The links to such categories would look like http://yoursite.com/en/goods/food/

Language part is not restircted to category root, so you could use something like

4.3.1 news-en-world (World)
4.4.1 news-ru-world (Мир)

or even

4.3.1 news-world-en (World)
4.3.2 news-world-ru (Мир)

Basically, replacing hyphen with slash gives you a hint on how the URL will be formed.
 

#3.2. Adding internationalized pages


To add a page, click "Submit new entry" just as you used to do. Select the exact category you want to add the page to. Fill in the form as usually. The only unusual thing required is that besides selecting a category with correct language, you MUST specify page alias (e.g. my_cool_page) and put the language code suffix at the end of it (e.g. my_cool_page_en). The suffix will be used to detect language of the entry. Aliases consist of latin symbols, hyphens and underscores.

Once you have added a page, the alternative translation for it should be added to the similar category for another language and the alias for the translation should be exactly the same except for the language suffix (e.g.
my_cool_page_ru).

Links to alternative pages will look like:
http://yoursite.com/en/somecat/my_cool_page
http://yoursite.com/ru/somecat/my_cool_page

All the rest works as usually. But make sure you add translated versions of a page to all available languages, or your visitors will encounter errors when selecting the language of non-existing entry.


1. pieter  2009-03-13 03:37
Thanks Trustmaster. This is what we and cotonti needed.
2. fedai  2009-03-16 19:22
Fatal error: Call to undefined function pagi18n_cat_url() in /home/tsnet/public_html/system/functions.php on line 4359
3. Mr G.  2009-03-27 16:38
Is there any possibility to use this plugin to change news language on index page?
4. tensh  2009-03-31 14:44
Thank you for this plugin!
5. ez  2009-10-31 02:49
Just Brilliant... :D
The url transformation is also new for me... great stuff you guys
6. jbra  2012-08-10 20:00

When I goto page it shows this: http://www."domain".com/online/ru/articles/my_page_en

in URL but I get a nopage found error 404. And when I click the russian link on the home page it just refreshes screen.

Please help...

7. jbra  2012-08-21 15:43

Any help with previous post??

Only registered users can post new comments