Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle arabic string in PHP with Eclipse

I am currently working on the localization of a website, which was first in english only. A third party company did the translations, and provided us with an excel file with the translations. Which I successfully converted to a PHP array that I can use in my views. I'm using Eclipse for Windows to edit my PHP files.

All is fine, except that I need to add variables in my strings, ex:

'%1 is now following %2'

In arabic I was provided with strings like this one:

'_______الآن يتتبع _______'

I find that replacing __ with %1 and %2 is incredibly difficult because the arabic part is a right to left string, and the %1, %2 will be considered left-to-right, or right-to-left, and I'm not sure . I hardly have the results I expect with the order of my param, because %1 will sometimes go to the left of the string, sometimes on the right, depending on where I start to type. Copy-pasting the replacement strings can also have the same strange effects.

Most of the times I end up with a string like this one:

%2الآن يتتبع %1

The %1 should be at right hand site, the %2 at the left hand site. The %1 is obviously considered right-to-left string because the % appears on the right. The %2 is considered left-to-right.

I'm sure someone as this issue before. Is there any way it can be done easily in Eclipse? Or using a smarter editor for arabic issues? Or maybe it is a Windows issue? Is there a workaround?

UPDATE

I also tried splitting my string into multiple strings, but this also changes the order of the parameters:

'%1' . 'الآن تتبع' . '%2'

UPDATE 2

It seems that changing the replacement string makes things better. It is probably linked to how numbers are handled in Arabic strings. This string was edited in Eclipse without any problem. The order of the parameter is correct, the string is handled correctly by PHP:

'{var2} الآن يتتبع {var1}'

If no other solution is found, this could be a good alternative.

like image 726
Tchoupi Avatar asked Jul 19 '12 13:07

Tchoupi


1 Answers

Being an Arabic speaker I get lots of localization tasks. Although I haven't faced this problem in particular but I've had many left-to-right/right-to-left issues while editing. I've had success working with Notepad++.

So here's what I usually do when I want to edit Arabic text

  1. Open empty Notepad++ *
  2. Set encoding to UTF-8 (Encoding -> Encoding in UTF-8)
  3. Enable RTL mode (View -> Text Direction RTL)
  4. Paste your strings

And here's a screenshot showing how I'm editing your string

enter image description here

*: for some reason, whenever I open an already existing file things go bananas. So maybe I'm being superstitious, but this has always worked for me.

Update: First time I did this I was skeptical because the strings looked wrong, but then I did this:

print_r(str_split($string));

and I saw that they're indeed in the correct order.

like image 181
Adi Avatar answered Oct 10 '22 14:10

Adi