Multiple_languge_support
//multiple languge ie aama hindi english bdhi languge aave(hindi languge ma bdhu hindi ma lkhelu aave)
//youtube vidio:How to make our app to supprt multiple languge?androi studio 23:8min
//aama main string ma right click karvu and open translation pr click karvu
//pche +-o aa 3 symbol mathi round vadu symbol pr click karvu and jetli languge joi te hoy ie select karve
//aa program ma 2 languge select kre che hindi and english
//hindi ma translate google translate mathi karvu vidio jovo
Step 1:xml
Step 2:java
Step 3:String.xml //jelti languge joi te hoy ae string ma add kre deve
Step 1:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demoproject.aalap.com.multiple.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="90dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signup"
android:layout_gravity="center"/>
<Button
android:id="@+id/changeLang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_gravity="center"
android:text="@string/changeLang"/>
</LinearLayout>
Step 2:activity_main.java
package demoproject.aalap.com.multiple;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadLocale();
setContentView(R.layout.activity_main);
ActionBar actionBar=getSupportActionBar();
actionBar.setTitle(getResources().getString(R.string.app_name));
Button changeLang=findViewById(R.id.changeLang);
changeLang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//show alertdialog to display list of languges,one can be selected
showChangeLangugeDialog();
}
});
}
private void showChangeLangugeDialog() {
final String[] listItem={"English","हिंदी"};
AlertDialog.Builder mBuilder=new AlertDialog.Builder(MainActivity.this);
mBuilder.setTitle("choose Languge.....");
mBuilder.setSingleChoiceItems(listItem, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(i==0){
//English
setLocale("en");
recreate();
}
else if(i==1){
//hindi
setLocale("hi");
recreate();
}
dialogInterface.dismiss();
}
});
AlertDialog mDialog=mBuilder.create();
mDialog.show();
}
private void setLocale(String lang){
Locale locale=new Locale(lang);
Locale.setDefault(locale);
Configuration config=new Configuration();
config.locale=locale;
getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
SharedPreferences.Editor editor=getSharedPreferences("Settings",MODE_PRIVATE).edit();
editor.putString("My_Lang",lang);
editor.apply();
}
public void loadLocale(){
SharedPreferences preferences=getSharedPreferences("Settings", Activity.MODE_PRIVATE);
String language=preferences.getString("My_Lang","");
setLocale(language);
}
}
Step 3:String.xml //aama main string ma right click karvu and open translation pr click karvu
//pche +-o aa 3 symbol mathi round vadu symbol pr click karvu and jetli languge joi te hoy ie select karve
//aa program ma 2 languge select kre che hindi and english
<resources>
<string name="app_name">Multiple</string>
<string name="welcome">Welcome</string>
<string name="email">Email</string>
<string name="password">Password</string>
<string name="login">Login</string>
<string name="signup">Do not have account?Sign Up</string>
<string name="changeLang">Change Languge</string>
</resources>
Step 3:String.xml
//hindi vadi String ma aatlu copy paste kre devu
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">विभिन्न</string>
<string name="welcome">्वागत हे</string>
<string name="email">ईमेल</string>
<string name="password">पारण शब्द</string>
<string name="login">लॉग इन करें</string>
<string name="signup">खाता नहीं है? साइन अप करें</string>
<string name="changeLang">भाषा बदलो</string>
</resources>
//youtube vidio:How to make our app to supprt multiple languge?androi studio 23:8min
//aama main string ma right click karvu and open translation pr click karvu
//pche +-o aa 3 symbol mathi round vadu symbol pr click karvu and jetli languge joi te hoy ie select karve
//aa program ma 2 languge select kre che hindi and english
//hindi ma translate google translate mathi karvu vidio jovo
Step 1:xml
Step 2:java
Step 3:String.xml //jelti languge joi te hoy ae string ma add kre deve
Step 1:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demoproject.aalap.com.multiple.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="90dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signup"
android:layout_gravity="center"/>
<Button
android:id="@+id/changeLang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_gravity="center"
android:text="@string/changeLang"/>
</LinearLayout>
Step 2:activity_main.java
package demoproject.aalap.com.multiple;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadLocale();
setContentView(R.layout.activity_main);
ActionBar actionBar=getSupportActionBar();
actionBar.setTitle(getResources().getString(R.string.app_name));
Button changeLang=findViewById(R.id.changeLang);
changeLang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//show alertdialog to display list of languges,one can be selected
showChangeLangugeDialog();
}
});
}
private void showChangeLangugeDialog() {
final String[] listItem={"English","हिंदी"};
AlertDialog.Builder mBuilder=new AlertDialog.Builder(MainActivity.this);
mBuilder.setTitle("choose Languge.....");
mBuilder.setSingleChoiceItems(listItem, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(i==0){
//English
setLocale("en");
recreate();
}
else if(i==1){
//hindi
setLocale("hi");
recreate();
}
dialogInterface.dismiss();
}
});
AlertDialog mDialog=mBuilder.create();
mDialog.show();
}
private void setLocale(String lang){
Locale locale=new Locale(lang);
Locale.setDefault(locale);
Configuration config=new Configuration();
config.locale=locale;
getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
SharedPreferences.Editor editor=getSharedPreferences("Settings",MODE_PRIVATE).edit();
editor.putString("My_Lang",lang);
editor.apply();
}
public void loadLocale(){
SharedPreferences preferences=getSharedPreferences("Settings", Activity.MODE_PRIVATE);
String language=preferences.getString("My_Lang","");
setLocale(language);
}
}
Step 3:String.xml //aama main string ma right click karvu and open translation pr click karvu
//pche +-o aa 3 symbol mathi round vadu symbol pr click karvu and jetli languge joi te hoy ie select karve
//aa program ma 2 languge select kre che hindi and english
<resources>
<string name="app_name">Multiple</string>
<string name="welcome">Welcome</string>
<string name="email">Email</string>
<string name="password">Password</string>
<string name="login">Login</string>
<string name="signup">Do not have account?Sign Up</string>
<string name="changeLang">Change Languge</string>
</resources>
Step 3:String.xml
//hindi vadi String ma aatlu copy paste kre devu
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">विभिन्न</string>
<string name="welcome">्वागत हे</string>
<string name="email">ईमेल</string>
<string name="password">पारण शब्द</string>
<string name="login">लॉग इन करें</string>
<string name="signup">खाता नहीं है? साइन अप करें</string>
<string name="changeLang">भाषा बदलो</string>
</resources>
Comments
Post a Comment