I’m trying to edit my android strings.xml file with arabic translations. However, I’m having issues. For example, I have something like this:
<string name="test">اختبار</string>
When I type something like %1$s to add a placeholder, the string with the placeholder is also mixed up.
What’s the right approach to do this? Thanks
Placeholders (ascii) in BiDi strings are tricky. If you know that this %1$s will eventually be substituted by a name in Arabic, it's manageable; but if the substitution can be English or mixed text, you need a long and careful QA to check all special cases.
Don't try to edit Arabic text in Android Studio text editor for file res/values-ar/strings.xml; use the Translations Editor instead.
The official guide https://developer.android.com/studio/write/translations-editor.html describes the this editor in great detail, but one little trick that it misses is the use of View/BiDi Text Direction menu. To work with Arabic strings, you want to set it to Right-to-Left.
This will not effect the Arabic column in your Editor, and not even the way the translation is displayed in the text box at the bottom:
But when you click the ... button for translation, you will get the translation in RTL:
Now you can understand how your placeholder(s) will look when replaced with actual data.
Related
Hello I have a question about arabic formatting how should I properly format this strings, it seems i can't manage this:
تحميل %1$s…
تم تحميل الكلمات. %1$d/%2$d!
This is in sublime text 2 - but i think that there is Left-to-Right order
EDITED:
In Eclipse this copied from Sublime Text gets messed up a little. I hire some person to translate from english to arabic strings.xml. He used Word editor but things get messed up when coping to eclipse and I suggested to changed it in Sublime Text, that I think will support it correctly like in Eclipse and is lighter editor. I see that in Sublime Text seems to be in Left-To-Right order which is also wrong.
* When I run app with this messed up special characters it seems to run correctly. Bu I have doubt whether some interpunction words hasn't also messed up and for example: Item 5/10 has been downloaded. will be Item has been downloaded. 5/10 or something like this.*
Need a preferred way to get someone english written strings.xml, get this translated, and then copied into /values-ar and working correctly?
Try adding a RIGHT-TO-LEFT MARK character (\u200F) at the start of your text.
similar type answered here
That is a sublime issue with Right-to-Left languages as listed here. You dont have to worry too much about it because it does not affect the results, your app will show it perfectly.
"To solve this problem, use the unicodeWrap() method, found in the BidiFormatter class, on every piece of text that you insert into a localized message."
Quoted from here https://developer.android.com/training/basics/supporting-devices/languages.html#FormatText
You have to use Arabic Font like:
Typeface face = Typeface.createFromAsset(this.getAssets(), "fonts/arabic_letters.TTF");
yourTextView = (TextView) findViewById(R.id.yourTextVIew);
yourTextView.setTypeface(face, Typeface.BOLD);
Let me specify the problem first.
My app is designed for text mainly in Hindi, and I want to target Android OS below 4.1, which doesn't support hindi characters(yes, I've tried various Hindi fonts, which don't work properly, or the desired outcome is not the expected one).
So, I've prepared icons with hindi text, and all works perfectly fine now.
The problem left with is, how can I specify hindi text for the launcher icon?
I've tried to specify hindi text by creating an image with hindi text, and left the application:label ="" and activity:label="" blank.
But the text doesn't appear in where the app name should have appeared, or apparently I didn't create the image correctly.
Any help in this regard would be appreciated :)
I hope you already have tried Krutidev (Hindi Font), if not you can try it.
Though it may late to answer now, but as i read this now, i would like to answer since I did the same in my application in the following way:
1. Just in application tag of your app's manifest, give app name as normal:
android:label="#string/app_name"
2. in resource file strings.xml, add a string 'app_name' with the name your want for your app. Be careful, what i did was: i typed the text using Google transliteration and i gave this in Hindi.
3. Then when you save your strings.xml, it will ask you to save this in proper encoding, then choose 'utf-8', and that's it.
I often read such messages. But what is the reason of the replacement? I only know that a space bar cannot be at the end of a string because it will be ignored and you will get the string without the space bar.
<string name="lorem">Lorem and a space bar </string>
But what about everything else? I don't see any visual difference between
<string name="loading">Loading…</string>
and
<string name="loading">Loading...</string>
have a look at this answer. This is just to use less characters if possible and there is no point making three dots if the appropriate character is available for this. It's good to use Unicode value in this case. You can also tell Lint to ignore this if you with.
Android Replace "..." with ellipsis character
The screenshot below displays my problem.
The first EditText shows a hint in Arabic which is shifted upwards, now the second EditText is just for reference which shows the English version completely fine. Same goes for the Button.
I have declared the string in strings.xml like this:
<string name="ar_login">دخول</string>
This is how I set the EditText's hint:
UserName.setTypeface(ArabicFont);
String hint = getString(R.string.ar_HintUserName);
....
UserName.setHint(hint);
UPDATE:
I used this, but of no use:
UserName.setGravity(Gravity.CENTER_VERTICAL);
But with this, Text moved a little down; but i guess its not generic:
UserName.setPadding(0,15,0,0);
With Padding, English words move to downwards.
UPDATE 2:
Originally arabic texts are separated; means they are shown letter by letter. So to join them, i was using this Arabic Reshaper. To Download Code, Check this link
Now when i reshape the arabic text and then set on TextView or as EditText's Hint, it got shifted upwords but without reshaping it is fine.
So i guess, whether i have to change the reshape class OR make my textview to not split the word. But dont know where to go?
I am still unable to find out why Android splits the arabic words into separate letters anyhow in my second edit I am providing a link which uses a class to rejoin the separated letters and form a word again.
In the reshape function, it was mistakenly appending \n at the end, just removing it solves the problem.
I am sure its problem with the font file which you are using.!
[Sorry I am not allowed to upload the screen shot as my reputations are lower :(]
For the layout, I was setting text in xml, and typeface in code. And I'm not setting any attributes like padding/gravity. But it was working fine for me.
So, I can assure you that using font file whose style matches your requirement will solve your problem.
Just to help you out with, but 'm not sure I got font file from DroidSansFallback.ttf
Just a guess :) ...,
What if the size of the Arabic font is lower? [If this is the case, then Gravity.CENTER_VERTICAL should have worked for you :( ]
May be this is the style of that font file. How about trying a different font file for Arabic text ?
I have a current Android app that uses i18n via resources. res/values-es/strings.xml and so on. When I test it on a device with the language set to Espanol it pulls the correct resources, from the values-es file, but the accent characters are way out of whack.
For example, I want to use the lowercase o with an accent (ó). I have tried with the actual character in the strings.xml file (using the character map on Ubuntu to create the string) and with the entity, in either case it comes out like some other character set accent I don't recognize:
The same character looks perfect WITHIN strings.xml when using many different text editors. And the file is UTF-8 (tried recreating it with the Android "wizard" tool in Eclipse to make sure).
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version">Versión</string>
</resources>
Now I've used French, and German before in other Android apps, with all sorts of accents, and haven't seen this problem, so I'm entirely confused at the moment. What am I doing wrong this time?
I finally solved this one. I was using a font and calling setTypeface earlier in the code. The font I'm using must not have the special characters needed for the other languages. I need to check to make sure my user's are using a locale that my font supports before setting the font.
I should have realized this and checked it earlier.
So the bottom line is this, if you get strange results with certain characters in different locales, make sure you're not using fonts that don't support those characters. Fall back to not using a font (don't call setTypeface) and test that way.
That diacritic is actually called a breve, common in many eastern european languages. I had the same problems before once. I even have a question here on SO. Since nobody solved the problem, it's worth the shot...
This isn't clear to me yet:
Does it happen only on this project? Did you try others? (maybe a project mistake)
Try including other language folders (try, say, values-fr). Do you have the same problem?
Did you try to build your app inside Eclipse? Did you try building manually on the command line?
Then, you could try:
Instead of the "ó" (here in PT we use the same), try \u00f3. Like: Versi\u00f3n. Do you get the proper latin small o with acute? Just to clear things.
Build your app using ant ($ ant release) manually on the command line. Report back the results.
This may help the guys here (who are much more experienced than I am) guess where the problem can be.
Best regards!
Check how the actual strings.xml file is stored.
In the file tree in Eclipse, right-click on the strings.xml file and select properties.
You will get a properties dialog for the file.
If not selected already, select the "Resource" line in the left column.
Check the "Text file encoding" area at the bottom.
It maybe selected as "default" or a specific encoding such as "UTF-8" selected.
Select the UTF-8 option. Save file. Clean & Build project (to re-gen resources) and then see if any changes.
See attached screenshot.
Suerte, Andrew
This is strange as it should not cause a problem. Maybe you should try to embed string into CDATA section, like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version"><![CDATA[Versión]]></string>
</resources>