<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));
Related
Generally, I'm trying to save some text from edittext in android studio to string and than later write it to pdf using pdf stamper and send it via e-mail. I'm using default encoding UTF-8 because I cannot (or don't know) to change it since it's hard-coded. User will eventually enter some of these characters. What is the best way to make this characters visible or to prevent user from typing those characters?
Thanks :)
Use special characters and set it to text view like how u set & :- &
or use Html within TextView :-
#For example (< Android Nougat):
myTextView.setText(Html.fromHtml("č"));
#For example (>= Android Nougat):
myTextView.setText(Html.fromHtml("č", Html.FROM_HTML_MODE_COMPACT));
try this,
myTextView.setText(Html.fromHtml("č"));
You can save it to xml as
<string name="random">" č,ć,đ,ž"</string>
and you it later by string name
I want to find all hard-coded strings in my code to move them into strings.xml file for future localization. Such as :
Toast.makeText(context,"Hardcoded text",LENGTH_SHORT).show();
I using Android Studio.
Go to Analyze > Run Inspection By Name... (Ctrl+Alt+Shift+I)
and type:
Hardcoded Text to find the hardcoded strings in
the .xml files;
Hardcoded Strings to find the hardcoded strings in the .java files.
Run it against the whole project, and you should get an inspection results panel that will show the hardcoded text instances.
This answer hasn't getting to me any result.
Nonetheless, for future searches :
In Android Studio 1.2.2 added new Option Hardcoded strings(not a Hardcoded text) and this getting to me perfect searches result.
After android studio 1.2.2 It seems pretty easy way to do it,
Go to Analyze
Run Inspection by name
Type : HardCoded Text
And then by selecting appropriate module's option you can get all hard coded Strings in your whole project.
Tip : Short key : Ctrl + Alt + Shift + I
It seems it has been already answered here, isn't it relevant for your problem ?
Edit : just don't forget to check "File mask(s)" box in the window after having typed "Hardcoded text", and select *.java, if you want to search in Java files.
And after you found all your hardcoded strings, this may help you to transfer them to XML.
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.
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.