9

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.

Tchoupi
  • 14,560
  • 5
  • 37
  • 71
  • I'm programming with Hebrew, which is also R-T-L, and in my experience handling all the data within a database is a lot easier. However. It's true that most IDEs don't have native support for these languages. Why not try to handle the data inside a database? – Nadav S. Jul 19 '12 at 13:54
  • 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++. Are there any rules for this replacement? Maybe it can be scripted. – Adi Jul 19 '12 at 13:55
  • @NadavS. I'm trying to avoid database because I want to avoid this unnecessary step. If I need new translations when we implement new functionalities, I can just send my excel file to the localization company. I won't have to export my database to an excel file, send it to the company, then reimport again the file. Actually I just tried editing the same string in Navicat and I ran in the same issues. – Tchoupi Jul 19 '12 at 14:01
  • @Adnan I have to manually add placeholders in the strings. I don't think it can be scripted, because most of the time the parameters would be in reverse order (`%1` being on the right) but it depends on the meaning. I'll try notepad++, thank you for your suggestion. – Tchoupi Jul 19 '12 at 14:03
  • @MathieuImbert, oh sorry forgot to tell you. In notepad++ you have to choose `View`->`Text Direction RTL` – Adi Jul 19 '12 at 14:08
  • @MathieuImbert -Try this: (1) open original notepad (or closest editor on mac) (2) type %1 (3) change text direction by pressing `CTRL+SHIFT` (4) paste the arabic string (5) revert back to LTR by pressing `CTRL+SHIFT` again (6) type %2. That method sucks, I know, but somehow it worked for me when I used to write strings in Hebrew. I have no experience with Arabic, but these languages are pretty similar. Tell me if it works – Nadav S. Jul 19 '12 at 14:11
  • Change encoding of your Eclipse to support UTF-8. Then it should work!! – insomiac Jul 19 '12 at 14:55
  • @Aby It is already. The Arabic support works well in Eclipse, but mixing RTL and LTR languages seems to give unexpected results. – Tchoupi Jul 19 '12 at 15:06

3 Answers3

5

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.

Adi
  • 5,089
  • 6
  • 33
  • 47
  • Using RTL mode definitely makes things easier. But I actually run in a weird issue. Same as your screenshot actually. `2%` seems fine because its RTL, but shouldn't `%1` be also written `1%`? – Tchoupi Jul 19 '12 at 14:34
  • @MathieuImbert, yeah same thing happened to me first time. It LOOKS wrong (and wait till you copy it back to your IDE, it will be horrible) but it's actually fine. First time I did this I had to print my string `char` by `char` just to believe it's in the right order. Edit: actually it's a good idea, I'll update the answer. – Adi Jul 19 '12 at 14:42
  • Maybe you are right. Does `Mathieu is now following Best photos` translate as `Mathieu الآن يتتبع Best photos`? It looks to me as parameters are in reverse order. – Tchoupi Jul 19 '12 at 14:58
  • I just realized it only occurs if the string starts with a placeholder. The editor must assume the string is LTR. Inserting Arabic before gives expected results. `'الآن %1 الآن يتتبع %2'`. Weird... – Tchoupi Jul 19 '12 at 15:20
  • @MathieuImbert, yes, the translation is correct (well not exactly, it should be `يتابع` instead of `يتتبع`). But regarding the string you already have, yes. – Adi Jul 19 '12 at 17:36
  • Thanks for correcting it. I checked in Google Translate and you are right it didn't make sense. If you're interested, I might have found a solution. Check out UPDATE 2. If you know what's happening, I'll be happy to know. – Tchoupi Jul 19 '12 at 18:01
  • @MathieuImbert, now that you mention the numbers thing I've just remembered. Arabic numbers (what we call "English numbers") mixed with Arabic letters are the most problematic thing I've come across. As a matter of fact I remember doing things like replacing the numbers with Latin letters and then replacing them back again just to stop the RTL confusion. Congrats for finding an alternative. – Adi Jul 19 '12 at 18:08
3

@Adnan helped me realize and later confirmed that there are issues when mixing Latin numbers with Arabic text.

Based on that conclusion, the solution is simply to stop using %1, %2, %3, ... as placeholders. I will be using more descriptive keywords instead, for example {USER}, {ALBUM}, {PHOTO}, ...

This shows the expected result in the PHP file and it is easily editable:

'ar' => '{USER} الآن يتابع {ALBUM}'
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
0

I would prefer the original Notepad for this kind of task.

  1. Open Notepad, make sure you're in LTR mode
  2. Type %1
  3. Change mode to RTL by pressing CTRL + SHIFT
  4. Paste the arabic string into the editor.
  5. Revert back to LTR by pressing CTRL + SHIFT again.
  6. Type %2
  7. Select all with CTRL + A and copy with CTRL + C
  8. Paste into the IDE. It should look weird but execute as expected.

Reason for using Notepad: More complex editor such as Notepad++, Sublime, Coda (Mac), and some IDEs - in your case Eclipse may not use the correct encoding, and Notepad is simple yet works good for multilangual tasks.

Nadav S.
  • 2,429
  • 2
  • 24
  • 38
  • Thanks for describing the exact steps. It gives the exact same result as Adnan's solution. Parameters seem to be in reverse order. – Tchoupi Jul 19 '12 at 15:55