Showing posts with label hebrew. Show all posts
Showing posts with label hebrew. Show all posts

Monday, March 16, 2009

Flex Right to Left – for the Hebrew man

here is some cowboy programming for handling the text direction in flex. i found that the simplest way is to extend the text UI component (i.e. mx:TextArea or mx:TextInput) with my own class with some instrumentation.

amazingly enough, selecting the right font family is all it takes to have the UI component type the correct order in words. the font i used was Ariel.



this.setStyle("textAlign","right");
this.setStyle("fontFamily","Arial");

it gets a little bit trickier when setting or retrieving the text from the component, so I've added a set and get methods, that crudely check for the first character. if its Hebrew, i flip the order of words.

the setter and getter look like this:



public function getText():String{
return LanguageUtil.getLocalazedText(this.text);
}

public function setText(s:String):void{
this.text = LanguageUtil.getLocalazedText(s);
}

the language utility I'm using is actually the following method:



public static function getLocalazedText(message:String) :String {
var c:int = message.charCodeAt(0);
if(c>1487 && c<1515){
var resArray:Array = message.split(" ");
var resLine:String = "";
for(var i:int = resArray.length; i>0; i--){
if(i != resArray.length){
resLine += " ";
}
resLine += resArray[i-1].toString();
}
return resLine
}else{
return message;
}
}

i haven't tested this on Mac yet. but for windows it seems to be ok.

hee haw