Skip to content

Recent Posts

  • A Comparison In between The Java IDEs: Netbeans and Eclipse
  • Plane Constructions Structure
  • Why Ecommerce Web page Structure Providers Is Important for On the web Enterprises
  • Social Media Marketing and advertising is Attracting Offline Desire
  • Some Distinctions Between Android And J2ME

Most Used Categories

  • Technology (147)
  • Gadget (145)
  • Internet Marketing (143)
  • Android (141)
  • iOS (136)
  • Tec Business (97)
  • Web Design (44)
  • Apps (3)
  • Business (2)
  • Automotive (2)
Skip to content
cdr-inc

cdr-inc

Subscribe
  • Home
  • Technology
  • Internet Marketing
  • Web Design
  • Android
  • iOS
  • Gadget
    • Apps
    • Mobile
  • About Us
    • Advertise Here
    • Contact Us
    • Privacy Policy
    • Sitemap
  • Home
  • Android Builders Weblog: In step with-App Language Personal tastes

Android Builders Weblog: In step with-App Language Personal tastes

Jack SparrowNovember 26, 2022

Table of Contents

  • Construct to your multilingual customers
    • combine this selection for your app?
    • val appLocale: LocaleListCompat = LocaleListCompat.forLanguageTags(“xx-YY”) // Name this at the major thread as it’s going to require Job.restart() AppCompatDelegate.setApplicationLocales(appLocale) // Name this to get the chosen locale and show it for your App val selectedLocale = AppCompatDelegate.getApplicationLocales()[0]
    • NOTE: Those APIs also are backward appropriate, so despite the fact that the app is getting used on Android 12 or decrease, the APIs would nonetheless behave the similar, and no further assessments for OS variations are required for your code.
    • Further issues to maintain whilst migrating to the API
    • // Software technique to put a string in a SharedPreference non-public a laugh putString(key: String, worth: String) {     val editor = getSharedPreferences(PREFERENCE_NAME, PREFERENCE_MODE).edit()     editor.putString(key, worth)     editor.practice() } // Software technique to get a string from a SharedPreference non-public a laugh getString(key: String): String? {     val choice = getSharedPreferences(PREFERENCE_NAME, PREFERENCE_MODE)     go back choice.getString(key, null) }
    • // Take a look at if the migration has already been executed or no longer if (getString(FIRST_TIME_MIGRATION) != STATUS_DONE) {    // Fetch the chosen language from anywhere it used to be saved. On this case it’s SharedPref    // On this case let’s suppose that it used to be saved in a key named SELECTED_LANGUAGE   getString(SELECTED_LANGUAGE)?.let { it →       // Set this locale the use of the AndroidX library that can deal with the garage itself       val localeList = LocaleListCompat.forLanguageTags(it)       AppCompatDelegate.setApplicationLocales(localeList)       // Set the migration flag to be sure that that is completed simplest as soon as       putString(FIRST_TIME_MIGRATION, STATUS_DONE)   } }
    • What flexibility does the characteristic supply to the customers and builders?
  • Recap
    • References

Posted via Neelansh Sahai Android Developer Members of the family Engineer (on Twitter and LinkedIn)What you probably have a suite of customers who’re somewhat fluent in English, Hindi, and Spanish, and they have got a information app on their telephones and like to learn the scoop in Hindi? For his or her texting app, they like Spanish as they have got some family and friends who they textual content with in Spanish. However for ease of get entry to, they nonetheless favor their software to be in English. Now there are lots of such use-cases the place the customers may need their app languages to be other from their gadget language. Attention-grabbing!

Beginning with Android 13, now we have incorporated one of the crucial most-requested options from customers, In step with-App Language Personal tastes. It we could customers transfer app languages from Device settings, offering customers with higher regulate over their language alternatives for various apps, regardless of the gadget language.
A cellphone screen displaying App language preferences in system settings for the YouTube app

Construct to your multilingual customers

This weblog specializes in easy methods to combine the In step with-App Language Personal tastes API for your app to supply your customers the versatility to make a choice other languages for various apps.

1.    Customers can trade the language settings from gadget settings via settling on: 

Settings → Device → Languages & Enter → App Languages → [Select the desired App] → [Select the desired Language]

NOTE: Handiest the ones apps that experience opted in for the characteristic via specifying the locale_config.xml report (extra in this under), will seem in gadget settings.

A cellphone screen demonstrating finding the language settings from system settings by selecting Settings → System → Languages & Input → App Languages → [Select the desired App] → [Select the desired Language]

2.    In case your app already has an in-app language picker, you’ll be able to combine the In step with-App Language Personal tastes API to leverage the total platform reinforce. For pre-Android 13 customers, the gadget settings gained’t be visual, however builders can nonetheless supply an in-app language picker.

A cellphone screen demonstrating integrating the Per-App Language prefences API for an app which already has an in-app language picker

combine this selection for your app?

There are 5 steps that want to be adopted whilst running at the In step with-App Language Personal tastes characteristic, indexed right here →

 

1.    Create locale_config.xml report

Create a brand new report in values/xml/ listing and identify it as locale_config.xml. This report will have to comprise a listing of the entire locales which might be supported via the app. The record component will have to be a string containing a locale tag.

NOTE: The locale tags will have to practice the BCP47 syntax, which is most often {language subtag}–{script subtag}–{nation subtag}. The rest rather than that will likely be filtered out via the gadget and would possibly not be visual within the gadget settings.

locale_config.xml

<?xml model=“1.0” encoding=“utf-8”?>
<locale-config xmlns:android=“http://schemas.android.com/apk/res/android”>
    …

    <!– English –>
    <locale android:identify=“en”/>

    <!– Eastern (Japan) –>          
    <locale android:identify=“ja-JP”/>

    <!– Chinese language (Macao) in Simplified Script –>
    <locale android:identify=“zh-Hans-MO”/>

    <!– Chinese language (Taiwan) in Conventional Script –>
    <locale android:identify=“zh-Hant-TW”/>  
    …
</locale-config>

2.    Upload the locale_config within the AndroidManifest.xml

Specify this locale_config.xml report within the app’s AndroidManifest.xml

AndroidManifest.xml

<manifest>
    …
    <utility
        …
        android:localeConfig=“@xml/locale_config”>
    </utility>
</manifest>


After steps 1 & 2, your customers will have the ability to uncover and set their language choice to your app from gadget settings on units working Android 13 or upper. If your customers are on units working on variations less than Android 13, you’ll be able to supply an in-app language picker. Optionally, you’ll be able to additionally come with the similar language picker for your app for units working Android 13 or upper. When your app comprises an in-app language picker, it is necessary for the person’s personal tastes to be in sync between the gadget and the app. That is the place the AndroidX APIs come into the image. Learn directly to discover ways to create an in-app language picker.

Use the most recent model of AppCompat Library

def latestAppCompatVersion =  “1.6.0-rc01”

dependencies {
    …
    implementation “androidx.appcompat:appcompat:$latestAppCompatVersion“
    implementation “androidx.appcompat:appcompat-resources:$latestAppCompatVersion“
    …
}

4. Use AndroidX APIs

Use the APIs for your code to set and get the app locales.

MainActivity.kt

val appLocale: LocaleListCompat = LocaleListCompat.forLanguageTags(“xx-YY”)

// Name this at the major thread as it’s going to require Job.restart()
AppCompatDelegate.setApplicationLocales(appLocale)

// Name this to get the chosen locale and show it for your App
val selectedLocale = AppCompatDelegate.getApplicationLocales()[0]

NOTE: Those APIs also are backward appropriate, so despite the fact that the app is getting used on Android 12 or decrease, the APIs would nonetheless behave the similar, and no further assessments for OS variations are required for your code.

 

5. Delegate garage to AndroidX

Let AndroidX deal with the locale garage in order that the person’s choice persists.

AndroidManifest.xml

<utility
    …
    <provider
        android:identify=“androidx.appcompat.app.AppLocalesMetadataHolderService”
        android:enabled=“false”
        android:exported=“false”>
        <meta-data
            android:identify=“autoStoreLocales”
            android:worth=“true” />
    </provider>
    …
</utility>


Steps 3, 4, & 5 above exhibit the minimal parts had to create an in-app language picker.

And with this, your app can now reinforce locale switching.

Further issues to maintain whilst migrating to the API

Previous, builders needed to deal with the person’s personal tastes on their very own, both via the use of SharedPreferences, storing the information on a server, or different app good judgment. With the new APIs, there is not any want to deal with this one at a time. So if you find yourself the use of those APIs, AndroidX is already caring for the garage section, however what occurs when the app is opened for the primary time after a person updates their software to Android 13 or upper?

On this case, the gadget gained’t take note of the person’s personal tastes for the app language and thus it’ll map the app to the default gadget language. To steer clear of this, builders want to upload some one-time migration good judgment in order that their customers don’t must set the language once more after they replace the app.

// Specify the constants for use within the under code snippets

significant other object {

    // Constants for SharedPreference Document
    const val PREFERENCE_NAME = “shared_preference”
    const val PREFERENCE_MODE = Context.MODE_PRIVATE

    // Constants for SharedPreference Keys
    const val FIRST_TIME_MIGRATION = “first_time_migration”
    const val SELECTED_LANGUAGE = “selected_language”

    // Constants for SharedPreference Values
    const val STATUS_DONE = “status_done”
}

// Software technique to put a string in a SharedPreference
non-public a laugh putString(key: String, worth: String) {
    val editor = getSharedPreferences(PREFERENCE_NAME, PREFERENCE_MODE).edit()
    editor.putString(key, worth)
    editor.practice()
}

// Software technique to get a string from a SharedPreference
non-public a laugh getString(key: String): String? {
    val choice = getSharedPreferences(PREFERENCE_NAME, PREFERENCE_MODE)
    go back choice.getString(key, null)
}

// Take a look at if the migration has already been executed or no longer
if (getString(FIRST_TIME_MIGRATION) != STATUS_DONE) {

   // Fetch the chosen language from anywhere it used to be saved. On this case it’s SharedPref

   // On this case let’s suppose that it used to be saved in a key named SELECTED_LANGUAGE
  getString(SELECTED_LANGUAGE)?.let { it →

      // Set this locale the use of the AndroidX library that can deal with the garage itself
      val localeList = LocaleListCompat.forLanguageTags(it)
      AppCompatDelegate.setApplicationLocales(localeList)

      // Set the migration flag to be sure that that is completed simplest as soon as
      putString(FIRST_TIME_MIGRATION, STATUS_DONE)
  }
}

 

What flexibility does the characteristic supply to the customers and builders?

Right here are some things that may end up to be really helpful for you customers.

  1. All units working Android 13 or upper may have a commonplace position for customers to find and alter the language in their apps.
  2. Despite the fact that the gadget settings are restricted to the units working Android 13 or upper, the AndroidX APIs are backwards appropriate. Thus, there is not any requirement so as to add OS Model assessments for your code whilst construction to your multilingual customers.
  3. Builders don’t want to deal with configuration adjustments one at a time or concern about storing the person’s decided on language each time. The API handles configuration adjustments and retail outlets the language personal tastes for you.
  4. Works with different Android options like Backup and repair. If a person switches to a brand new software and restores the in the past sponsored up information, your app will retain the person’s final most well-liked language, thus offering your customers with a greater and extra seamless enjoy.

Recap

With that, maximum portions of the characteristic are lined. So let’s have a handy guide a rough recap on what we mentioned in lately’s learn.

  1. A snappy learn on what In step with-App Language Personal tastes be offering to multilingual customers and app builders.
  2. What finish customers will see on their units.
  3. migrate your app to the In step with-App Language Personal tastes APIs.
  4. A couple of issues that want to be looked after whilst migrating to the APIs to verify a greater person enjoy.
  5. Finally, the advantages that finish customers and builders can leverage from this selection.

References

  1. In step with-App Language Personal tastes
  2. Pattern App ( Compose )
  3. Pattern App ( Perspectives )
  4. In step with-App Language Personal tastes (YouTube Video)

Related Posts:

  • Smartphone Applications Advancement at a Glance
  • Spot the Ideal Android App Developers
  • Android Application Progress: A Beginner's Guide
  • Android Apps: What You Will need to Know About Them
  • Maximum Potent Language For Android App Building 2023
  • What Is the Part of Python in Synthetic Intelligence?
Android, Blog, Developers, Language, PerApp, Preferences

Post navigation

Previous: Reinterpreting The Lua Interpreter | Hackaday
Next: Your Previous Tech Does not Belong within the Trash. The way to Recycle Out of date Units for Unfastened

Related Posts

Plane Constructions Structure

September 24, 2023April 11, 2023 Jack Sparrow

Some Distinctions Between Android And J2ME

September 22, 2023April 11, 2023 Jack Sparrow

Top Patterns of and Supplies for Padlock Shackles

September 14, 2023April 11, 2023 Jack Sparrow

Recent Posts

  • A Comparison In between The Java IDEs: Netbeans and Eclipse
  • Plane Constructions Structure
  • Why Ecommerce Web page Structure Providers Is Important for On the web Enterprises
  • Social Media Marketing and advertising is Attracting Offline Desire
  • Some Distinctions Between Android And J2ME

Recent Comments

No comments to show.

Archives

  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
September 2023
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  
« Aug    

BL

Health
Copyright All Rights Reserved | Theme: BlockWP by Candid Themes.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT