5

I need to process some language files. Most of them are in left-to-right languages, but some are in right-to-left languages. Processing the right-to-left languages ir problematic.

I have read a localizedString variable from a file.

If I print it reads correctly (first line in the attached picture). However, when I run this line:

    outputString = '"' + stringKey + '" = "' + localizedString + '";\n'

The arabic text gets out of order (second line).

enter image description here

I cannot even paste it here properly, upon pasting it gets out of order.

How can I automatically keep the proper order without knowing the language in advance?

I guess I could do what's explained in this SO answer, but that would break left-to-right languages. I'm looking for an automatic way of doing this regardless of the language.

Note: I'm using Python 2.7.6

Community
  • 1
  • 1
Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92
  • I don't see how the approach used in that linked answer would necessarily break LRT languages. Is `localizedString` a unicode string or a byte string? If a byte string, what is its encoding? If a unicode string, does it contain any of the order-switching characters mentioned in that other post? It's not clear to me from your screenshot what the actual order of characters is in the source string. – BrenBarn Apr 18 '15 at 05:31

1 Answers1

2

IMO, you could just simply concat them.

let the display problem to the edit itself. You may need convert it to .doc or .odt if you want to use it in desktop environment. Or just recompile vim with +rightleft options. However, you language file processing program can keep simple and elegant.

yegong
  • 739
  • 1
  • 7
  • 15
  • It turns out you are right. Even though it showed incorrectly when printing or viewing the file, the actual file encoding was fine and reading the localized `.strings` file in Xcode produced the desired results. – Ricardo Sanchez-Saez Apr 19 '15 at 02:06