Introduction
The localization is using the alternate resources to the particular region target or locale. For the example, we might provide the localized language strings for the various countries in the input for the resources folder. Android is using the resources appropriate for the device's locale at the runtime without any code changes. For more details, refer here.
Let’s start
Step 1
Open Visual Studio->New Project->Templates->Visual C#->Android->Blank app.
Select Blank app. Give the Project Name and Project Location.
Step 2
Open Solution Explorer-> Project Name-> Resources. Create values folder for the various languages. Here, I created English, Tamil, Hindi, Spanish, Swedish.
Step 3
Open Solution Explorer-> Project Name-> Resources-> Layout-> Main.axml. Design the page for the language changes options. Here, I created Check box and textview.
Step 4
Open Solution Explorer-> Project Name-> Resources -> values-en. Declare the string id and the values for English.
English
XML
- <string name="TxtWelcome">Welcome to New Technology</string>
Tamil
XML
- <string name="TxtWelcome">புதிய தொழில்நுட்பத்திற்கு வரவேற்கிறோம் </string>
Hindi
XML
- <string name="TxtWelcome">नई प्रौद्योगिकी में आपका स्वागत है</string>
Spanish
XML
- <string name="TxtWelcome">Bienvenido a la nueva tecnología</string>
Swedish
XML
- <string name="TxtWelcome">Välkommen till ny teknik</string>
Step 5
Open Solution Explorer-> Project Name->Resources-> MainActicity.cs and add namespace.
- using Android.Util;
- using Java.Util;
Step 6
Declare the button and Checkbox variables. Afterwards, go to Oncreate() and give the code given below.
C# code
- <policies>
- <inbound>
- <base />
- <cache-lookup vary-by-developer="false" vary-by-developer-groups="false">
- <vary-by-header>Accept</vary-by-header>
- <vary-by-header>Accept-Charset</vary-by-header>
- </cache-lookup>
- <rewrite-uri template="/resource" /> </inbound>
- <outbound>
- <base />
- <cache-store caching-mode="cache-on" duration="3600" /> </outbound>
- </policies>static string LanguageCodevalue; CheckBox ChkEnglish, ChkTamil, ChkHindi, ChkSwidesh, ChkSpinesh; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);
- <CheckBox>(Resource.Id.ChkEnglish); ChkTamil = FindViewById
- <CheckBox>(Resource.Id.ChkTamil); ChkHindi = FindViewById
- <CheckBox>(Resource.Id.ChkHindi); ChkSwidesh = FindViewById
- <CheckBox>(Resource.Id.ChkSwidesh); ChkSpinesh = FindViewById
- <CheckBox>(Resource.Id.ChkSpinesh); ChkEnglish.Click += ChkEnglish_Click; ChkTamil.Click += ChkTamil_Click; ChkHindi.Click += ChkHindi_Click; ChkSwidesh.Click += ChkSwidesh_Click; ChkSpinesh.Click += ChkSpinesh_Click; }
Step 7
After implementation Oncreate() to Create Checkbox, proceed, as shown below.
- private void ChkSpinesh_Click(object sender, System.EventArgs e) {
- ChkEnglish.Checked = false;
- ChkTamil.Checked = false;
- ChkHindi.Checked = false;
- ChkSwidesh.Checked = false;
- ChkSpinesh.Checked = true;
- LanguageCodevalue = "sp";
- this.Recreate();
- }
- private void ChkSwidesh_Click(object sender, System.EventArgs e) {
- ChkEnglish.Checked = false;
- ChkTamil.Checked = false;
- ChkHindi.Checked = false;
- ChkSwidesh.Checked = true;
- ChkSpinesh.Checked = false;
- LanguageCodevalue = "sv";
- this.Recreate();
- }
- private void ChkHindi_Click(object sender, System.EventArgs e) {
- ChkEnglish.Checked = false;
- ChkTamil.Checked = false;
- ChkHindi.Checked = true;
- ChkSwidesh.Checked = false;
- ChkSpinesh.Checked = false;
- LanguageCodevalue = "hi";
- this.Recreate();
- }
- private void ChkTamil_Click(object sender, System.EventArgs e) {
- ChkEnglish.Checked = false;
- ChkTamil.Checked = true;
- ChkHindi.Checked = false;
- ChkSwidesh.Checked = false;
- ChkSpinesh.Checked = false;
- LanguageCodevalue = "ta";
- this.Recreate();
- }
- private void ChkEnglish_Click(object sender, System.EventArgs e) {
- ChkEnglish.Checked = true;
- ChkTamil.Checked = false;
- ChkHindi.Checked = false;
- ChkSwidesh.Checked = false;
- ChkSpinesh.Checked = false;
- LanguageCodevalue = "en";
- this.Recreate();
- }
Step 8
Press F5 or Build and Run the Application.
Finally, we successfully created Xamairn Android app.