3

I am working on language mutation of frontend of our app for Iranian market, but currently we got stuck with issue with mixing europian numerals and units with persian texts. For example our desired format for one text is:

Result: <value>s (e.g. Result: 50s)

But when I try to compose this string in javascript, number 50 is before text (after in persian language) like this

50 :persiantext s

Is there any solution how to mix these things together, or it doesn't even make any sense to mix it and it all should be in persian?

Thank you for all help/suggestions.

DSDev7
  • 91
  • 1
  • 8
  • You will need to post a bit more context, is that in HTML? But, I will take a guess and say its something with `direction: rtl` and `direction: ltr` on the style of the element. – C14L May 09 '16 at 16:59

2 Answers2

2

Use placeholders in your text and then replace it with the number. If you have

Result: {$d}s

for english, and

{$d}s :نتیجه

for persian, then you can replace {$d} with 50 and get the correct text in both cases.

There are a few libraries, which could help replacing variables like Underscore or Lodash (though they use a slightly different syntax for the variables), see template function.

JSchirrmacher
  • 3,243
  • 2
  • 19
  • 27
1

When concatenating mixed RTL/LTR text you should use corresponding Right-to-left and Left-to-right marks (as shown in this Java question - String concatenation containing Arabic and Western characters).

 myArabicString + "\u202A" + englishNumberAndText + "\u202C" + moreArabic

Alternatively most RTL languages have native numbers that flow RTL too. To use that approach you will need to write own code to replace each individual digits - similar to code in convert numbers from arabic to english.

Mixing in Latin punctuation like ":" and "!" need to be done carefully - you may need to wrap it to RTL/LTR marks - but make sure to review results with people who actually know how text should look like.

Side note: you may want to check out JavaScript equivalent to printf/string.format if you need a lot of formatting.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • Thank you very much for your answer. I think it was best among all answers, however another answer already gave us exatly what we wanted till we wait for translator/native speaker to tell us better instructions because of what you said, that we should be careful about mixing punctuation and other stuff. Thanks a lot again – DSDev7 May 10 '16 at 09:04