Jump to content

mixed multi-language output – RTL and LTR


ngrmm
 Share

Recommended Posts

the website has several languages: english, german, … (left-to-right) and arabic, farsi (right-to-left)
englisch is the default-language but only some parts/fields are translated. everything works fine.
if a text-field has no translation, the default-language will be shown instead.

BUT there is a problem:
when user-language is arabic (rtl) i just want to set "dir=rtl" or a class on those div's with arabic-language output.

i tried it this way. But got an error. I thinks it's because the second field is from another $page.
Anyway this isn't the best way because $rtl and $langclass should be unique.

Whats the best way to solve this problem?

	$userLang = $user->language->name;
	$userId = $user->language->id;

	$page->of(false); // turn off outputFormatting (if it's not already)

	// get unformatted textfields
	$body = $page->body->getLanguageValue($userLang);
	$otherPageTitle = $otherPage->title->getLanguageValue($userLang);
	
	// check if user lang is rtl
	if($userLang == 'fa' || $userLang == 'ar') {
		
		// check if var translation exists
		if(!$body == '') { $rtl = "dir='rtl'"; $langclass = "rtl"; }
		// no translation: output default
		else { $body = $page->body->getLanguageValue('default'); }

		// check if var translation exists
		if($otherPageTitle != '') { $rtl = "dir='rtl'"; $langclass = "rtl"; }
		// no translation: output default
		else { $otherPageTitle = otherPageTitle->getLanguageValue('default'); } 	

	}

	echo "<div class='$langclass' $rtl >$body</div>";
	echo "<div class='$langclass' $rtl >$otherPageTitle</div>";

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...