Wednesday, October 4, 2023
Alternative Way
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
Alternative Way
No Result
View All Result

Android library for in-app language changes support in your app

Gordon James by Gordon James
October 3, 2021
in World Tech Code
0 0
0
Home World Tech Code

As any user, you may want to view your app in a language that is different from what the device is currently using. An app that can change its language on the fly is an easy choice for those who want to use it and for someone who wants to distribute it globally to anyone, regardless of the device language setting. This article is devoted to an Android library that can be used to implement in-app language changes support.

The Android library that provides a simple way for your app to change its language at runtime. You can change the language in your app without restarting it (even if the device changes its locale). In-app language changes support in your app: ➤ It is locale independent ➤ It has a simple API ➤ It has a compact size ➤ It is simple and easy to use ➤ It can save and load language translations, and supports static, dynamic and bundled translations ➤ It can specify the device’s locale at runtime ➤ It can change the language of your app in the same activity ➤ It can change the language of your app in

Location Library

Android library with a header image to support language changes in your application.

  • To change the language of an application
  • Default language on first start-up
  • Working with string sources in XML and programmatically
  • Support of RTL language
  • Harmonisation of behaviour on the platform

Try it on Google Play

Starting with version 1.2.9, there will be a transition from JCenter to MavenCentral.

// build.gradle (project)
allprojects {
repositories {
mavenCentral()
/* . */
}
}

Gradle

Implementation of ‘com.akexorcist:localization:1.2.10’.

(Optional) You can exclude androidx.appcompat:appcompat if your project does not use AppCompat.

implementation (‘com.akexorcist:localization:1.2.10’) {
exclude group : ‘androidx.core’, module : ‘core’
}

A custom application class is needed, which is an extension of LocalizationApplication.

Class MainApplication : LocalizationApplication() {
/* … */
override fun getDefaultLanguage() = Locale.ENGLISH
}

Or not, by using the LocalizationApplicationDelegate with additional code as shown below

Class MainApplication : Application() {
private val localizationDelegate = LocalizationApplicationDelegate()

override fun attachBaseContext(base : Context) {
localizationDelegate.setDefaultLanguage(base, Locale.ENGLISH)
super.attachBaseContext(localizationDelegate.attachBaseContext(base))
}

override fun onConfigurationChanged(newConfig : Configuration) {
super.onConfigurationChanged(newConfig)
localizationDelegate.onConfigurationChanged(this)
}

override fun getApplicationContext() : Context {
return localizationDelegate.getApplicationContext(super.getApplicationContext())
}

override fun getResources() : Resources {
return localizationDelegate.getResources(baseContext, super.getResources())
}
}

For the activity, expanded from LocalizationActivity.

Class MainActivity : LocalizationActivity() {
/* … */
}

Or with LocalizationActivityDelegate with additional code

Open the class CustomActivity: Activity(), OnLocalChangedListener {
private trap localizationDelegate = LocalizationActivityDelegate(this)

public override fun onCreate(savedInstanceState : Bundle ?) {
localizationDelegate.addOnLocaleChangedListener(this)
localizationDelegate.onCreate()
super.onCreate(savedInstanceState)
}

public override fun onResume() {
super.onResume()
localizationDelegate.onResume(this)
}

override fun attachBaseContext(newBase : Context) {
applyOverrideConfiguration(localizationDelegate.updateConfigurationLocal(newBase))
super.attachBaseContext(newBase)
}

override fun getApplicationContext() : Context {
return localizationDelegate.getApplicationContext(super.getApplicationContext())
}

override fun getResources() : Resources {
return localizationDelegate.getResources(super.getResources())
}

fun setLanguage(language : String ?) {
localizationDelegate.setLanguage(this, language !!)
}

fun setLanguage(locale : Locale ?) {
localizationDelegate.setLanguage(this, locale !!)
}

val currentLanguage : localization
get() = localizationDelegate.getLanguage(this)

// Just the change locale event method override
override fun onBeforeLocaleChanged() {}
override fun onAfterLocaleChanged() {}
}

Then prepare the multilingual content in a string resource.

Public method on Locality Activity

It has only 4 public methods.

fun setLanguage(language : String)
fun setLanguage(language : String, country : Strinng)
fun setLanguage(locale : Locale)
fun getCurrentLanguage() : The line is

setLanguage Sets the language to be changed.

For example

setLanguage(th) // Language : Thailand
setLanguage(th, TH) // Language : Thailand, Country : Thai
setLanguage(Locale(th, TH)) // Language : Thailand, Country : Thai
setLanguage(s) // Language : English
setLanguage(s), GB // Language : English, Country : UK
setLanguage(s), US) // Language : English, Country : United States
setLanguage(Locale(s, US)) // Language : English, Country : United States
setLanguage(Locale.KOREA) // Language : Korean, Land: Korea
setLanguage(Locale.KOREAN) // Language : Korean
setLanguage(Locale.CANADA_ENCH) // Language : French, Land: Canada

getLanguage Gets the current language as a local string.

And two additional breaking methods.

fun onBeforeLocaleChanged()
fun onAfterLocaleChanged()

This overloaded method is useful when you need to know when the language has changed.

If setLanguage is called. Current active activities are recreated to apply the new language.

Previous actions in the backstack are not immediately transferred to the new language. Until it becomes active again.

You must call setTitle(resId) or getActionBar().setTitle(resId) in onCreate(onSavedInstanceState : Bundle) to apply the new language.

Class MainActivity : LocalizationActivity() {
override fun onCreate(savedInstanceState : Bundle ?) {
/* … */
setTitle(R.string.main_activity_title)
}
}

Status change processing

The activity is recreated when the language is changed, which is the normal behavior when changing the configuration in Android. All actions or fragments that store data must process state changes.

Language change in fragment

The language of the fragment depends on the activity. Therefore, no additional code is needed in the fragment.

Service

For normal use it is sufficient to extend the LocalizationService

SimpleService class: LocalizationService() {
/* … */
}

Or you can use the LocalizationServiceDelegate with additional code

abstract class CustomService : Service() {
private val localizationDelegate : LocalizationServiceDelegate by lazy {
LocalizationServiceDelegate(this)
}

override fun getBaseContext() : Context {
return localizationDelegate.getBaseContext(super.getBaseContext())
}

override fun getApplicationContext() : Context {
return localizationDelegate.getApplicationContext(super.getApplicationContext())
}

override fun getResources() : Resources {
return localizationDelegate.getResources(super.getResources())
}
}

Broadcast receiver

BroadcastReceiver is an abstract class. Therefore we cannot make a LocalizationBroadcastReceiver for you.

In this case, you must convert the context in onReceive(context:Context, intent:Intent) to a localized context using Context.toLocalizedContext() before using it.

SimpleBroadcastReceiver class: BroadcastReceiver() {
override fun onReceive(context : Context, intent : Intent) {
val localizedContext = context.toLocalizedContext()
/* . */
}
}

Changing the language via the library may cause the application to fail if released with the Android App Bundle with language source optimization enabled.

To solve this problem, use the Additional Languages API in the Play Core library to load an additional language earlier.

Learn more about the additional language API: https://android-developers.googleblog.com/2019/03/the-latest-android-app-bundle-updates.html

If you don’t want to implement this feature in your code, simply ignore the language source optimization by adding the Android App Bundle configuration to your application’s build.gradle file.

android {
/* … */
bundle {
language {
enableSplit = false
}
}
}

Normally, ProGuard rules are not needed for this library.

But if you want to exclude this library from obfuscation and reduction. You can also paste this code into the proguard-rules.pro file

-backup class com.akexorcist.localizationactivity.** { * ; }
-dontwarn com.akexorcist.localizationactivity.**

GitHub

https://github.com/akexorcist/Localization

This source has been very much helpful in doing our research. Read more about multi language library android github and let us know what you think.

Frequently Asked Questions

How do I change the default language in Android Apps?

The Android’s operating system was developed by Google, which is the main reason for its success. It has a lot of apps that can be used for a variety of purposes and all these apps are available to the users in many different languages. The only thing that the users have to do in order to use apps in different languages is to select a particular language as the default language for the app. Most of the applications on your Android device are written in the default language that you set during the initial language configuration of the device. However, you can always change this language to another language of your choice, using the settings menu. Let’s see how this can be done. We can change the default language of the device by changing the locale. However, for this, we first need to know the locale supported by our application, the locale that is supported (if any) by the device, and a few other attributes that we need to take care before actually making the change. We can do this by using the android.provider.Locale class.

How can I add locale language in Android?

Also called “localization”, adding locale language in Android is easy to do by yourself. It’s a good idea if you are about to release your app or game to an international market. In this article, you’ll find some useful methods and tools to start your localization project. Android devices are popular in various countries, and some apps support multiple languages. So, how can we add a locale language in Android? The first step is to add the locale language into AndroidManifest.xml. Android locales are defined by the android:locale attribute on the element for a given provider in the manifest. For example, to add Japanese as a locale, use the following code: How do I make my Android multilingual?

There are two ways to get your Android multilingual. The first one is to buy a phone that supports multilingual, such as the Samsung Galaxy S9, which is available in three languages, English, Korean, and Chinese. The second way is to install a language pack yourself, which is what we will be covering in this tutorial. (website name) will be using a Samsung Galaxy S10 as an example, but if you have an older phone, the process will be mostly the same. We’ve all been there: you get a new Android phone and you can barely use it, because you can’t read any of the interface text. If you’re lucky, you can change the language settings and get back to normal—but if you’re not, you have to hope for a future update or root your phone just to switch languages. We’ve got some good news for you: there is a hidden way to change the language of every application on your phone, no rooting required. All you need is ADB, Android’s developer tools.

Related Tags:

multi language library android githubandroid multi language app example githubhow to create multi language app in androidandroid change language without restarting activitychange app language programmatically in androidhow to change whole app language in android programmatically,People also search for,Feedback,Privacy settings,How Search works,change app language programmatically in android,how to change whole app language in android programmatically,programmatically change language in android application github,multi language library android github,programmatically change language in android application github java,android multi language app example github,how to create multi language app in android,android change language without restarting activity

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
ShareTweetShare
Gordon James

Gordon James

Next Post
🥇 Linux CD command  What is it? + Parameters ▷ 2021

🥇 Linux CD command  What is it? + Parameters ▷ 2021

  • Trending
  • Comments
  • Latest
How To Get Free Internet On Android Without Service

How To Get Free Internet On Android Without Service

March 10, 2022
🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

October 3, 2021

Fix: Notifications not working on Nova Launcher

October 3, 2021
How to Fix OpenVPN Connected but Not Changing IP Address

How to Fix OpenVPN Connected but Not Changing IP Address

October 3, 2021

Setting Up Directory Sync Between On-Premises Active Directory with Microsoft 365 Azure AD

0
🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

0
🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

0
🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

0
Image2

The 3 Qualities of a Good Sports Betting Site

September 12, 2023
Image1

From Casino Chips to Cryptocurrency: The Evolution of Payment Methods

September 8, 2023
Image1

The Most Effective Online Casino Guide for Online Gambling in the World

August 30, 2023
Image3

Around the Globe

August 23, 2023

There's always an alternative Way!
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use

© 2022 - Alternative Way

No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Travel News

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
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