I want to use some Arabic letters in card view as text in my android app, how to achieve this. Anyone please help me.
Simply copy paste an Arabic string in your string.xml file. The access that string variable through resources. For example put this in your string.xml
<string name="message">هذا المجلد يات المحذوفة غير قابلة للإسترجاع.</string>
And put this in your code, now mystring variable should be Arabic.
String mystring = getResources().getString(R.string.message);
Read here and here more suggestions
Basically what I am trying to do is,
I start with MainActivity(activity_main) go to SettingActivity(activity_setting) & change my locale from given options(like french, english, dutch etc.)
So what I have done till now is...
OnClick of language name it re-create SettingActivity(activity-setting) & change it's string values according to language selected.
What I really want is Without re-creating Activity, All string values should be applied according to that selected language.
All suggestions & Answers are greatly appreciated.
Thank you in Advance.
Simply change the language property first.
Then call a new function that sets all strings displayed in the UI to the right language.
Pseudocode:
TextView myTextView = (TextView) findViewbyId(R.id.tv1);
myTextView.setText(yourCustomGetLocaleFunction("some id of the string you want to display", "some language name"));
But that's a bad approach. You should let Android handle the language of your app. Just localize the strings.xml file (you can load strings from the file from code).
Edit:
To change the language of your app for the moment, you can use the Code from this solution:
How to change android app language without changing phone language?
I have a arabic strings.xml file. I also have an English one.
In my settings activity, I want to be able to change the language used by the user. Like, is there a method like setStringResource(string.xml-ar)?
duplication of Load language specific string from resource?
check this one out.
Of course you must use Locale.AR or something like that for Arabic resource file.
Keep your language specific xml strings in the necessary directories under resources
And change the locale as required
String language = "en";
String country = "US";
Locale locale = new Locale(language , country);
this is my first question :)
I'm developing an application that stores animal species in a database. The app must be multilanguage, so I tought to take advantage of using strings.xml resource files.
The idea is to store the english name of the species on the db, for example "cat", "dog" etc.. and then display to the user the actual translation, based on an xml like this (for italian):
<string name="dog">Cane</string>
<string name="cat">Gatto</string>
The problem is that R.string contains the name dog and cat, but they are actually int, so I'm searching a way to use the "dog" string to be used to compare the R.string.dog translated value.
I'm almost sure that my design is terribly wrong, but don't know what the correct way to doing this kind of work, since the app is now in a very early stage of development.
Thank you
EDIT with example
This example illustrates the problem:
Database data:
row1: id="1", value="dog"
row2: id="2", value="cat"
String file strings.xml:
<string name="dog">Dog</string>
<string name="cat">Cat</string>
String file strings-it.xml:
<string name="dog">Cane</string>
<string name="cat">Gatto</string>
My problem is: the user want to insert a specie in his native language (eg. "Cane"), and I want to search in the DB for its existence before inserting.
I should loop for every row on the DB (where values are stored in english), get the the translation of each row (eg: I found cat, then I translate to "Gatto") and compare with the user input.
Is it possible to do that?
If you have a string name you want to use, you can use getIdentifier() to get the string id. As an example, to find R.string.cat:
Resources res = getResources();
int stringId = res.getIdentifier("cat", "string", packageName);
In the above example, if there is no R.string.cat found, it will simply return 0. It's an easy test to see if a string exists.
Alternatively, you can get an array of all the string ids in your R.java by using something like:
Field[] fields = R.string.class.getFields();
int[] ids = new int[fields.length];
for(int i=0;i<field.length;i++)
ids[i] = field[i].getInt(null);
Of course, that will also look for any strings that you don't really intend as translations, such as dialog/window titles, label/button captions, etc. I wouldn't advise it in the general case. If I had to do it, I'd prefix the "translation" strings with something so I could easily tell what is what, something like "entry_cat".
Note that we're using reflection, and if you have a lot of strings, it could slow you down. If you are going to loop through R.java, I'd advise only doing it on start-up, and saving the values in some sort of array/list.
First read this.
http://developer.android.com/training/basics/supporting-devices/languages.html
You can create value folder with many language's i.e janapee,dutch etc
you can find out value folder inside the res folder in your project. and create new value folders.
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
JUST TRANSLATE YOUR WORDS BY GOOGLE TRANSLATOR IN ANY LANGUAGE AND PUT INSIDE THE STRING.XML FILE .
Well, first of all, start reading this here:
Suppose that your application's default language is English. Suppose
also that you want to localize all the text in your application to
French, and most of the text in your application (everything except
the application's title) to Japanese. In this case, you could create
three alternative strings.xml files, each stored in a locale-specific
resource directory:
res/values/strings.xml Contains English text for all the strings that
the application uses, including text for a string named title.
res/values-fr/strings.xml Contain French text for all the strings,
including title. res/values-ja/strings.xml Contain Japanese text for
all the strings except title. If your Java code refers to
R.string.title, here is what will happen at runtime:
If the device is set to any language other than French, Android will
load title from the res/values/strings.xml file. If the device is set
to French, Android will load title from the res/values-fr/strings.xml
file. Notice that if the device is set to Japanese, Android will look
for title in the res/values-ja/strings.xml file. But because no such
string is included in that file, Android will fall back to the
default, and will load title in English from the
res/values/strings.xml file.
I have an Android application which I wrote for english language now I want to convert it to farsi/persian language. I want to know how can i type persian text for the TextView text.How can i maintain both the english and persian String.xml.please help.
cheers
Zolf
Locale locale = new Locale("fa-IR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getApplicationContext().getResources().updateConfiguration(config, null);
where do i put this code,now i put this code in the OnCreate and it does not change the text of the TextView to persian
For showing correct form of Persian characters use this solution.
Update
And for changing current resources that is loaded in your UI:
tf = Farsi.GetFarsiFont(this);
tvTitle01 = (TextView) findViewById(R.id.tvTitle01);
tvTitle01.setTypeface(tf);
tvTitle01.setText(Farsi.Convert(tvTitle01.getText().toString()));
Android has built-in mechanism of localization.
http://developer.android.com/guide/topics/resources/localization.html
you can create the different folder of values as per language and can keep different string.xml file for each language. Example:
res/values/strings.xml
Contains English text for all the strings that the application uses, including text for a string named title.
res/values-fr/strings.xml
Contain French text for all the strings, including title.
res/values-ja/strings.xml
Contain Japanese text for all the strings except title.
If your Java code refers to R.string.title, here is what will happen at runtime:
If the device is set to any language other than French, Android will load title from the res/values/strings.xml file.
If the device is set to French, Android will load title from the res/values-fr/strings.xml file.