Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-04-03 12:16:54

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Multi lingual site, the simple way

EDIT: topic title has been changed,
I was looking for an easy simple way to deal with multi lingual site, you can find the code in the next page provided by Stef.

And this was my original qustion:

Hi, I will like to know please how to use different databases that shares the same images data please?

I got a website in English (root) and need to create an Hebrew version of it (root/he),
so yes I could use the ‘MLP’ plugin, but it’s too much and I need it to be simple.

For example to change the images directory in ‘Admin > Preferences > Advanced’ to ../images
If it’s a problem to let upload from one to also update the other then I can limit the upload to be in the main only.

Last edited by THE BLUE DRAGON (2012-04-08 11:39:18)

Offline

#2 2012-04-03 16:41:06

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Multi lingual site, the simple way

Hi Gil

Wouldn’t it be simpler if you just created a Hebrew section in your existing install?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2012-04-03 17:25:11

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Multi lingual site, the simple way

How that gonna work please?
I need the whole site to be in Hebrew.

I thought to just use “gbp_permanent_links” and create a link rule of he/section/category/title
but then, how do I ask if it’s “he” or not?

Offline

#4 2012-04-03 17:46:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Multi lingual site, the simple way

Hi Gil,
In your post above you wrote that “I got a website in English (root) and need to create an Hebrew version of it (root/he)”.

The way I understood it is that the Hebrew part will be very similar in content to the english one. It is very possible to create multilingual sites using txp without any plugins. Check out artareacyprus.com, a site I’ve put together for some friends.

The way the particular site works is that each section is carrying one of the languages.

If you want I can post here its basic txp elements.

>Edit re the url schema, you could use section/category/article

Last edited by colak (2012-04-03 17:53:11)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2012-04-04 19:40:16

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Multi lingual site, the simple way

So if I understand you right, you are using sections as languages, and categories as sections,
and then use if_section ?
If that’s the case then I can’t do that in the current site I’m working on cause I already using both category1&2 in each article and must use sections.
but if that’s wasn’t what you meant, then yes please share some cool code please :)

BTW: I’m giving ‘MLP’ another try, I just want the client to not need to get out from the Write tab.

And for my original question, is it possible to use different databases that shares the same images data please?
In case and I will choose to do it that way.

Offline

#6 2012-04-04 19:52:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Multi lingual site, the simple way

THE BLUE DRAGON wrote:

is it possible to use different databases that shares the same images data please?

Yes (ish). Later version of Txp have an ihu config variable which is the path to an image directory. If you set this up in both config.php files to point to the same directory it’ll serve the images from there. Its primary function is to do with serving static files and cookies from alternate domains — stuff that I don’t fully understand but some here (maniqui, Gocom, wet, etc) do.

So serving the files is relatively easy. The tricky part is keeping the databases in sync. That, I have no idea how to do.

My advice would be to leverage some of what colak is talking about. Or there’s always this


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2012-04-04 19:56:52

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Multi lingual site, the simple way

Thanks Stef, checking it out :)

Offline

#8 2012-04-04 20:11:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Multi lingual site, the simple way

Alternatively — and this is totally off the top of my head…

  • Introduce a custom field called Language or something (it could be a glz_cf radio / select list of available options)
  • Write articles and choose the language at write time
  • Use some cleverness to switch between them using <txp:article_custom language="he" />

The cleverness could be that you have a switcher in the top corner of your site which sets a cookie to ‘en’ or ‘he’. Read that at the top of every page and you’ll know which type of articles / content to serve. Or maybe use gbp_pl or htaccess to strip off something in the URL and present it to you as a variable which you can test to decide which content to display.

I’ve not really thought it through so it might not work at all, but then again…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2012-04-04 20:51:37

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Multi lingual site, the simple way

is it possible to use different databases that shares the same images data please?

Another idea: gocom has an intriguing unreleased plugin in his treasure trove called rah_swap that might be of help…


TXP Builders – finely-crafted code, design and txp

Offline

#10 2012-04-05 09:03:23

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Multi lingual site, the simple way

THE BLUE DRAGON wrote:

So if I understand you right, you are using sections as languages, and categories as sections,
and then use if_section ?
If that’s the case then I can’t do that in the current site I’m working on cause I already using both category1&2 in each article and must use sections.
but if that’s wasn’t what you meant, then yes please share some cool code please :)

It’s exactly what I meant. I also use sub-categories so as to help with the detection of language specific menus. Having one install makes the site easier to maintain. That is why I suggested it. I can still post the code here if you think that you can use it.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#11 2012-04-06 00:07:11

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Multi lingual site, the simple way

I think I ends up with a simple solution, using “gbp_permanent_links” to create a link rule of:
he/section/category/title
then use this PHP to check if there is /he/ in the url, and create a variable value base on the result:

<txp:php>
	global $variable;
//
	$url = $_SERVER["REQUEST_URI"].'/';
	$lang = '';
	$hebrew = strstr($url,'/he/');
	$japanese = strstr($url,'/jp/');
	$german = strstr($url,'/de/');
//	
	if($hebrew) {$lang = 'he';}
	if($japanese) {$lang = 'jp';}
	if($german) {$lang = 'de';}
//	
	$variable['lang'] = $lang;
</txp:php>
.
<txp:if_variable name="lang" value="he">
	Hebrew
<txp:else />
	English (default)
</txp:if_variable>

Is it a good easy way to do that?
I mean of course it will be better to put all the languages in an array and run it with a loop, which for this I will like to get your help please because I’m not familiar with the PHP syntax to do that.
but in general, is it a good simply way?
Maybe if possible the code also will modify the site_url tag and/or permlink tag, by adding the language to make our dev life easier.

Last edited by THE BLUE DRAGON (2012-04-06 09:54:09)

Offline

#12 2012-04-06 15:00:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Multi lingual site, the simple way

THE BLUE DRAGON wrote:

Is it a good easy way to do that?

Sure, it’ll work. As you say, a little refinement (untested) :

<txp:php>
	global $variable;

	$variable['lang'] = 'en';
	$variable['langName'] = 'English';

	$langs = array(
		'he' => 'Hebrew',
		'jp' => 'Japanese',
		'de' => 'German',
		'en' => 'English',
	);

	$url = serverSet('REQUEST_URI') . '/';

	foreach ($langs as $langKey => $langName) {
		if (strstr($url, '/' . $langKey . '/')) {
			$variable['lang'] = $langKey;
			$variable['langName'] = $langName;
			break;
		}
	}
</txp:php>

Maybe if possible the code also will modify the site_url tag and/or permlink tag, by adding the language to make our dev life easier.

I suppose you could alter the value of hu as well to add the laguage marker. Everything else is keyed off that. Not sure how successful that would be, but you could try.

Hope that helps.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB