How to add support to multi languages in android? - android

I would like to add support to different languages in my app. As I understand, Android uses the proper strings.xml file according to the operation languages of the device. But what If I want to allow users to change the language in the settings? What steps should I do? I thought of keeping the the user's language in the his document (Firebase cloud) but then if the user if logs out the app, the main page (login/sign up) will be in the default language (and not in his language).
I guess that there is a proper "flow" that I need to follow in order to add support to multi languages. Is it possible to share this flow with me?

you can go to res- values, then from the right click list create a new Values Resource File
from the window appears name the files strings and then select locale and add your language or country.. picture below to make it clear for you
then after that you can change the locale programmatically using these methods and let android system do the rest of work

Related

Can I use Google Translator to enable multi language in Android app?

I'm working on an Android app. I need to make it available in many languages.
Can we use Google Translate Plugin or translate API to get this work ?
Please check this link : https://www.w3schools.com/howto/tryit.asp?filename=tryhow_google_translate
You can see there's a drop down to get all the language list.
Can I use something like this in my Android app ?
If I can't use a this method, what's the best way to enable multi-language feature in an Android app ?
Every android app has a resource value "strings" (a list of values for string variables) to provide different languages.
<resources>
<string name="home_act_bottom_bar_home_item">Shop</string>
<string name="home_act_bottom_bar_cont_item">Contacts</string>
<string name="home_act_bottom_bar_cart_item">Cart</string>
</resources>
The application must have a new string res file for each language. When the application is launched, the OS detects current system language which was chosen by user in android settings and then try to find this language in res files. If the file we need exists (for example Russian) it will be used, if not - the system will start application with default strings res file(often English). You certainly may use different web-services to translate you "Strings" after application was launched, but it will need time, will make user experience worth (user will have to wait for translation and UI update), will make your code very complex. I suggest you to translate your App beforehand, and put translations to according string res files, it will make your app fast and code not so complex.
You can read official docs here: https://developer.android.com/training/basics/supporting-devices/languages

Multiple Language Support Android APP

I am very new for developing the multi-language oriented Android APP. This is the first time i am going to support my app in multi-support language app. I need some clarification for developing the multi-language support app. Already i have some ideas before initiate the development.
Single APK with Localization like will make the multiple String.xml and include it in inside of the app and based the member selection of language its automatically invokes and works.
All language strings values will retain in app server (back-end) and will raise the Rest-API request and get those values and change it inside of the entire app (all screens) if member click and change the language inside of the app.
Main concern is if anything needs to change in future then Idea2 is best way. We will just change in back-end side it will be appeared in client side. But if we are going Idea1 and wants to change then we need to put the new build only.
Which one is best approach and recommended way to develop?
You will need to create different String.xml depending the languages you want to target as JDenais says, in my app i have the following
for example the first arab string consist in the same as Strings.xml but with all in arab, now, you only need to call one string in your xml files and it will just select where to grab depending on the phone language. Or in default the language from where the app was downloaded by google play, in fact, they are all the same strings.xml , so you dont need to specify which one you want to pull the translated text from, just replicate your main strings.xml in your other strings.xml and then the phone will decide where to pull the data.
Also please read the official doc on how to accomplish this https://developer.android.com/training/basics/supporting-devices/languages
Also please check the language ISO Codes here
What is the list of supported languages/locales on Android?
All your texts should be packaged in the APK in different String.xml files. Forget about receiving texts from a backend. It would be a lot of extra work for limited gain and with added risks of failure.
The framework takes care of selecting the appropriate string.xml file and offers support for needed use cases like plurals.
right click the values folder and choose new-> values resource file -> locale -> choose the language you want and name it strings.
copy the strings from the original string file to the new file and change them to the new language just the strings
make sure that the view xml files have their text set as "#string/the_name of the string" not hard coded

How should my android app change its language, when user changes mobile phone language?

Within my app, I let user change the language when they install the app. Lets say they choose "English" while installing the app. But after that if they change the language of the phone to "French" how should my app receive it and change its language?
Assuming you use strings.xml to manage your string resources, Android natively supports localization:
https://developer.android.com/preview/features/multilingual-support.html
The idea is that you have distinct strings and values for each language you want to manage, then when the user changes the language in settings the app will automatically choose the correct file (or fall back to the default strings.xml if you haven't defined resources for the chosen language).
The app will automatically load its respective language strings files from the res/values directory after the application restarts. You could persist and compare Locale.getDefault().getLanguage() to check if the language has changed since the last restart.
It will try to get information about french in values (value-fr) if you didnt add the translations it will keep showing english

Translation tool

am wondering if is possible to use a feature on my app that can translate the app to other languages so the user can select through a list of languages so as he can read the app even if he doesnt speak English, thanks a lot
If you use the framework's localization facilities, this will happen automatically based on the user's language setting on their device
http://developer.android.com/guide/topics/resources/localization.html
Basically, instead of using string literals in your code (ie. txt.setText("Something") or android:text="Something"), you create these in your strings.xml file and use the automatically created reference id's.
res/values/strings.xml:
<string name="something">Something</string>
Then, you create alternate res/values folders for the other languages you support and create a similar strings.xml file there.
res/values-es/strings.xml
<string name="something">Algo</string>
Then your layouts and codes would have txt.setText(R.string.something) or android:text="#string/something".
You can do the same thing for drawable, layout, menu, etc.
"to use a feature on my app that can translate the app to other languages"
I do not think such feature exist from Google. But if you write the app according Google's localization guide then you can use our Nativer app, which is designed exactly for that. It takes you language resources - translates with a machine and then let's the crowd to correct it. All these happens in runtime - so you do not need to bother when the language translation finished by the crowd. You can find further info here transround.com
Peter

How to use multiple languages in android

I want to give my user an option to select his language and according to his selection i want to display language.
Can my android app support multiple languages. How to do that?
What you are referring to is termed Localization
You can do it under your resource folder. For example, let's say you want to have language support for France. For such cases, you can do it by creating a folder res/values-fr/strings.xml. In addition, you can have a folder called res/drawables-fr, as well.
You can check out more on these sites.
http://developer.android.com/resources/tutorials/localization/index.html
http://www.icanlocalize.com/site/tutorials/android-application-localization-tutorial

Categories

Resources