How to test the android app language changed or not? - android

In my android app, I have 3 options for language selection.i.e; Hindi,English,French
Programmatically changed default language(English) to Hindi.
How to verify whether app language changed to Hindi or not.(programmatically)
please help

To check whether language changed or not there may be many ways to verify but simply you can assert page title or that drop down text with expected text.

When the language is changed, take the reference of any text or tile or any element placeholder or label, and verify the string by using equalsIgnoreCase("") method.

Related

How to change Locale without re-launching application?

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?

Android preference inputType phone default value is a decimal value instead of a string

I have an Android application using default values from the Preferences Android framework.
It all works fine except for phone numbers (defined with android:inputType="phone" in preferences.xml).
The phone numbers get treated as numeric value so if I go to the preferences screen to see the default values I see
3.3631241E10
for the value defined in preferences.xml as
android:defaultValue="+33631241234"
To avoid this problem, I have used values from strings.xml defining the default values in preferences.xml like this :
android:defaultValue="+33631241234
It works ... but I don't like it: that's a source of problem as I need to redefine the same phone number for each language used ! !
I must be doing something wrong as I haven't found anyone else with the same problem on internet however I don't see what I am doing wrong ! !
Any help would be really appreciated.
that's a source of problem as I need to redefine the same phone number for each language used
you don't - when the text is absent for a language the default is used - docs :
Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml.

Disable misspelling flag of specific words in app?

Our company's name always comes up as misspelled (the red underline) when typed into EditText fields in our app. Is there a way I can disable the misspelling flag for a specific word to avoid this nagging feature?
And before someone suggests android:inputType="textNoSuggestions", I would still like spellcheck to be available to that specific field, and only exclude our company name.
I have no idea if it'll work, but you can try putting android.text.style.LocaleSpan over each occurrence of the company name, using Locale.ROOT (which has no language) as the target locale.
(Most of the time you encounter a CharSequence in a text view it can be cast to Spannable. If it can't, just copy its contents into a SpannableStringBuilder.)

changing the language of app without changing the settings of device

I am making an android app in which i want to change the language of app on selecting a particular language in spinner without changing the language of device.I have made different string files for all language. Now what to do next??
Can anyone please help me over this?
thanks
Most simple way is just to change VM's locale, like:
Locale locale=new Locale("zh"); //Chinese
Locale.setDefault(locale); //set VM's default locale
Once I wanted to implement a multiple language feature for my application. Where that language was not even supported by android.
I made the appropriate strings for all the application and stored them in my resources.
Then I kept the language selection in my shared preferences, so that when user opens the app the next time, we can show the previously selected language. I implemented the code and language changing in my OnResume() function of Activity. the code was like:
if(SelectedLanguage.compareTo("ar")==0)
{
String text = getString(R.string.ar_Options);
tv_Options.setText(ArabicUtilities.reshape(text));
text = getString(R.string.ar_Minimize);
tv_Minimize.setText(ArabicUtilities.reshape(text));
}
else
{
String text = getString(R.string.en_Options);
tv_Options.setText(text);
text = getString(R.string.en_Minimize);
tv_Minimize.setText(text);
}
I hope you get the basic idea. In this way you don't have to change the lanuguage of your device and you can provide multiple languages for your application.

How to set different locales in android?

In my application, I need to display strings according to user locale selection. So, I put my strings.xml in values-en, values-ko, etc. How can I set locale us, australia i.e; values-en_US, values-en_AU? But it's throwing an error? Can any one tell me how to set these locales in my code?
Use res/values-en-rUS/ (replacing the _ with -r).
I am not clear with your question but if you are not sure as what name you need to for a specified locale refer to these links
http://developer.android.com/intl/de/reference/java/util/Locale.html
http://groups.google.com/group/android-developers/web/localizing-android-apps-draft
Android by default will take the resources from respective language that has been selected on the device/stimulator.
There is International Standard for Locale.....like values-en for English....values-ko for Korean...You cant modify the standard..It would work if you keep the folder name as values-ko.

Categories

Resources