3

My app supports both English and Arabic language. So, I placed strings in strings.xml files for both language separately. I need a formatted string, for that I used the format specifiers in the strings.xml file(see below string). I can place the format specifier correctly in the English language file but unable to place the format specifier correctly in the Arabic language file.

<string name="device_offline_message" formatted="false">%s is offline. Please make sure it is online to execute the action.</string>

In Arabic, I can't place the string at the end of the string. Even if I specify the formatter in the start of the text, the lint check shows an error in the java code like

Format string 'device_offline_message' is not a valid format string so it should not be passed to String.format

in the below line of code where I used the string

showToastAlertDialog(String.format(getString(R.string.device_offline_message), device.getShortName()));
Abbas
  • 3,529
  • 5
  • 36
  • 64
Madhan
  • 555
  • 5
  • 23
  • 1
    Use %1$s in arabic strings.xml. Ref: Check this http://stackoverflow.com/questions/17502824/whats-wrong-with-this-format-string – Raghavendra Oct 27 '16 at 11:23
  • @Raghavendra This is my arabic string. s$1%.غير متصل. يرجى التأكد بأنه متصل لتنفيذ العمل. When I place like this, I always get the java.util.UnknownFormatConversionException: Conversion: in the logcat. – Madhan Oct 27 '16 at 12:08
  • 1
    @Madan %1$s.غير متصل. يرجى التأكد بأنه متصل لتنفيذ العمل try this. I am not sure where exactly you want to replace the string though:) – Raghavendra Oct 27 '16 at 12:09
  • @Raghavendra, It's working fine. Thank s – Madhan Oct 27 '16 at 16:25

1 Answers1

3

use

<string name="device_offline_message" formatted="false"> %1$s is offline.  Please make sure it is online to execute the action.</string>

instead of

<string name="device_offline_message" formatted="false">%s is offline.  Please make sure it is online to execute the action.</string>

just like @Raghavendra said in the comment.

And make sure you have set up Android studio properly.

In android Studio 2, RTL support is not turned on by default, Configure it Manually:

  1. In your Computer, go to the [android-studio2.0]/bins/idea.properties

  2. add editor.new.rendering=true to the end of idea.properties

  3. restart your android Studio

More Information here: How to edit arabic string properly?

Vall0n
  • 1,601
  • 2
  • 14
  • 19
  • This is my arabic string. .غير متصل. يرجى التأكد بأنه متصل لتنفيذ العملs% – Madhan Oct 27 '16 at 11:51