My project isn't showing any portuguese characters. When I try to type a word like "Não" it returns Não".
The funny thing is that when I get the string from res/string.xml, it shows the word correctly.
Any idea why?
Things I've tried so far and did not work out:
File -> Settings -> Editor -> File Encondings, I've changed everything to UTF-8 and others, rebuild/cleaned the project, and it kept the same.
EDIT:
I can upload a video on youtube showing it, if it helps with the solution!
There goes an image of what is happening:
My file build.gradle had this line:
compileOptions.encoding = 'ISO-8859-1'
Because of that I wasn't able to change anything. Now it's fixed. :)
This is really hard to explain why is it is, I had same with russian characters, but only on SOME devices. I've just checked to do same as you on Genymotion and it displays correctly... From my investigation it is up to each device how to display given characters, but also I assume it could happen because Android knows how to works with Resources, but doesn't with Strings from code. When you create folders for different languages you don't say that default must be English. So system gonna detect and display. I'm not sure 100%, but this is what I understood from doc.
Anyways, for using String object in TextView from code and displaying foreign (from English) languages we have just 2 options:
1) Add .ttf file for particular text/Unicode
2) html format
Example for first option:
String s="(Mouy t'ngai) (១ ថ្ងៃ)";
TextView text_view1 = null;
text_view1 = (TextView) findViewById(R.id.textView2);
Typeface font= Typeface.createFromAsset(getAssets(), "khmerOS.ttf");
text_view1.setTypeface(font);
text_view1.setText(s);
// you can use different type of .ttf like
TAU_BHON.TTF
molten.ttf
arialuni.ttf
Example of Second option:
tv.setText(Html.fromHtml("\\u27A1");
Source.
P.S. If I missed something, please fill free to notice that.
Related
I'm implementing an app in Hebrew, and I like it to be user-friendly in such way that at the first time the user logs on, there will be a question "Are you a male or a female?". After answering this question, I want most of the strings to be gender-dependent
(E.g. in Hebrew the question "Would you like some coffee?" will be
תרצה לשתות קפה?
for a male, and -
תרצי לשתות קפה?
for a female)
Meanwhile my app supports English and Unisex-Hebrew Locales, so I'm using String resources (like R.string.somevalue) and I know how to handle values-he and values-en.
Let's say I can ask for is_male() and is_locale_hebrew() at anytime, I saw this answer but it won't help my case since there are a hell lot of strings in my working-already app and I want the solution to add only xml files (hopefully) with the less needed change in my "Activity"s code.
I thought maybe overloading the parser that looks for the xml files will do the magic, but I have no clue where to start from.
My question divides into two parts:
A. How can I implement gender-dependnt String-resources?
B. (Opt) Some of the string-resources are good as unisex right now, is there any option to avoid copying those resources to the 2 new gender-dependent files and just add a default behavior of "if you don't find a string resource at values-he-male search for it in values-he"?
Thanks in advance!
Re'em
Same question for me. I plan to have (in addition to the default string.xml in English) iw (for male) and iw_fe (for female).
When the user selects his/her gender, I will change the locale (Set Locale programmatically )
As for using default values in Hebrew, I am still clueless. For now I will simply copy the Hebrew XML and change the required entries, leaving all the rest intact.
HTH
Noam
<string name="message">هذا المجلد يحتويى على %1$s ملفات. الرجاء التأكد قبل الحذف. الملفات المحذوفة غير قابلة للإسترجاع.</string>
I wanna put "%1$s" in an arabic string, but as you can see here, word, notepad++, utraedit, all failed to get the right string. how you guys edit arabic string?
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.
This is a source of frustration when editing mixed-direction text. What counts is the logical order of the text, not how any of the editors display it. When you finally format the string at run time in the app, the %1$s will be replaced by whatever string you pass to the formatting method. The only thing that matters is how the string will be rendered after the substitution.
The easiest thing to do is to write the message without the %1$s, then position the insertion caret, paste in the format code, and simply ignore how the editors screw up the bidi analysis. (The screw-up is because the editors are using a left-to-right base level. In some editors, you can set the base flow to right-to-left, but then the xml markup ends up being unreadable.)
When I work with RTL text and I need to put a place holder(%1$s) or LTR words, I just write it in MS Word and copy to the IDE.
It works for me in Eclipse and Android Studio.
All you need to check is that the components that displays that string like TextView has the right gravity.
You can try in Activity..
String formatedString = String.format("%1$s", getString(R.string.your_string));
I'm new to Android. When I add a button/views in Graphical layout it adds the label text this way- android:text="Button" . Why doesnt it add "android:text="#string/my_label" and add a string resource in string.xml file. Can't it be done automatically in eclipse?
I have searched a lot but I have not get any automated way to add a string to the resource file But This will save your time a lot IMHO.
Select a String, click Refactor --> Android --> Extract Android String.
Thanks to Brent Hronik. CTRL-1 on Windows works fine.
Because you don't have to use the #string resource. The purpose of the #strings resource is to make it easier to change elements about your code. For example, if you are using your application title in mutliple places, let's say in every dialog box, then if you change the title you would have to change it in all the instances that the app title is being display. So in this instance the #string/App_Title could be set to "My Program" and all of the dialog boxes can reference that. If you change the title to "Hello World" then all of these are changed. The #strings resource, while eclipse tries, doesn't have to be used for every string. Not using it is the equivalent to hard coding the value. There are plenty of reasons for and against using #string for everything.
I am not sure if there is a setting in eclipse that will automatically add a string to the resource file when the control is added.
(EDIT: Based on other users CTRL+1 is the short cut to do this.)
You can add the string to the strings.xml by clicking command and 1(on a mac, assume it would be control 1 on a Windows or Linux box) simultaneously. This will add the resource to strings.xml and then open that up in the editor.
Thanks Siddiq Abu Bakkar! I didn't think it would be there.
On Eclipse (and Windows) the shortcut is:
Alt+Shift+A (release all and then press) S
When you use Eclipse for first time it's not easy understand how to use these kind of "complex" shortcuts.
I can't vote and i can't comment answers yet (missing reputation as i'm a new user)
But i confirm :
1) hard type the string in your code like
mydlg.setTitle("hello guys");
2) select your string (e.g : "hello guys")
3) press Alt + Shift + A then press S
a dialog will appear to let you add a new string into resources. Everything should be already filled into that dialog box.
I wrote a big app with thousands of string in the code.... very bad idea, because now I want to translate each string.... big problem.
Copying all strings to the strings.xml takes a long time.
Eclipse has an option to take all selected strings and put them into messages.properties.
Does this work similiar like strings.xml? When, why all people use strings.xml.
Or should is use eclipse to seperate each string and than I should copy them to string.xml?
All people are using strings.xml because this is the normal way to do it on Android. You don't have to manage the load of the strings, to call any locale function in your script.
You can see the documentation here : http://developer.android.com/guide/topics/resources/index.html
BTW, you can easily transform your eclipse generated file to an strings.xml file after the extraction.
In Eclipse you can use the shortcut keys Alt + Shift A, S to extract an inline string in to the strings.xml file via a popup dialog - might be a bit easier than doing it by hand. And as the others say, yes you should ALWAYS use the strings.xml file so that you only have to look in one place when you want to change a string, instead of having to search through all your code.
For Android Platform:
I need to put Hebrew Character ₪ and some more like אורנג in string to check with the incoming data in java file. When I put this character It shows an error like "Some characters can not be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding". These values are coming from SQLite database. Please see the attached snap. How can I solve this? Kindly give me some useful suggestions. Looking forward to hear from anybody who has a suggestion for me. Thanks.
Please open your eclipse.ini file from your eclipse folder with Note Pad and put the following permission into that.
-Dfile.encoding = UTF-8
Some more options as well:
For setting the encoding on a per WorkSpace basis, use Preferences->General->Workspace
To set the encoding on a per project basis open project properties and change to UTF-8
Hope this one help.
I think you'll need UTF-8 encoding for that.
These things are a little bit confusing. Reading this might clear some of the mist around encodings and character sets.
I think this may useful to you.
Keep this hebrew word in string.xml file. You can retrieve as
in String.xml
place hebrew word here
In java code:
String s=getString(R.string.hebrew_word);
Use this string as you want..