I would like to create a multilingual android application.
Is there a way to detect what language the user prefers?
Is there a recommended way to manage multiple languages on Android or should I reinvent the wheel?
1. What language are Android apps written in? The majority of Android apps are written in Java and Kotlin. In some cases, programming languages like C, C++, and Basic are also used.
Java was the default language to write Android apps since the Android platform was introduced in 2008. Java is an object-oriented programming language that was originally developed by Sun Microsystems in 1995 (now, it is owned by Oracle).
Yes, there is a recommended way to manage multiple languages
Multilanguage support is easy done for android. Create a new values directory for the language with the suffix of the language code. For german: values-de or french: values-fr than copy your string.xml into that and translate each entry. Thats all you need.
Do android support multiple languages?
Providing you follow the recommendations, detecting which language the user prefers is automatic.
Have a read of this:
http://developer.android.com/guide/topics/resources/localization.html
In Activity file
public boolean onOptionsItemSelected(MenuItem item) { String languageToLoad="en"; switch (item.getItemId()) { case R.id.eng: languageToLoad = "en"; break; case R.id.hn: languageToLoad = "hi"; break; case R.id.te: languageToLoad = "te"; break; case R.id.ta: languageToLoad = "ta"; break; case R.id.ka: languageToLoad = "kan"; break; case R.id.ml: languageToLoad = "ml"; break; case R.id.mr: languageToLoad = "mr"; break; default: break; } Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getResources().updateConfiguration(config,getResources().getDisplayMetrics()); }
In res\menu\menus.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.connect.OrderProcess"> <item android:title="Language" app:showAsAction="never"> <menu> <item android:id="@+id/eng" android:title="English"/> <item android:id="@+id/hn" android:title="Hindi"/> <item android:id="@+id/te" android:title="Telugu"/> <item android:id="@+id/ta" android:title="Tamil"/> <item android:id="@+id/ka" android:title="Kannada"/> <item android:id="@+id/ml" android:title="Malayalam"/> <item android:id="@+id/mr" android:title="Marathi"/> </menu> </item> </menu>
AND Create folder and file
res\values\string.xml (English)
res\values-hi\string.xml (Hindi)
res\values-kan\string.xml (Kannada)
res\values-te\string.xml (Telugu)
res\values-ta\string.xml (Tamil)
res\values-ml\string.xml(Malayalam)
res\values-mr\string.xml (Marathi)
In string.xml (Hindi)
<resources> <string name="email">ईमेल</string> <string name="password">पासवर्ड </string> </resources>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With