<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>In-App-Language · MangoDriod</title><link>https://md.eknath.dev/tags/in-app-language/</link><description>In-App-Language updates from MangoDriod</description><language>en-us</language><atom:link href="https://md.eknath.dev/tags/in-app-language/index.xml" rel="self" type="application/rss+xml"/><lastBuildDate>Wed, 25 Nov 2026 09:45:04 +0530</lastBuildDate><item><title>Implementing In-app and pre-locale language selection in Android</title><link>https://md.eknath.dev/posts/android/implementing-in-app-language-selection-android/</link><guid isPermaLink="true">https://md.eknath.dev/posts/android/implementing-in-app-language-selection-android/</guid><pubDate>Sun, 14 Jan 2024 16:13:00 +0530</pubDate><category>android</category><category>localization</category><category>in-app-language</category><description>
One of the essential features for a globalized app is the ability to provide users with the option to choose their preferred language within the application. In this blog post, we will guide you through the process of implementing in-app language selection in an Android app.
Step 1: Create Locale String Resource Create a string resource file for each respective locale by navigating to res &amp;gt; new &amp;gt; Android Resource File . Select Locale and create a string.xml file. Copy and paste the translations of your app content into these files.</description><content:encoded><![CDATA[<p><img loading="lazy" src="https://md.eknath.dev/img/blogger/blog-post-1.png"></p>
<p>One of the essential features for a globalized app is the ability to provide users with the option to choose their preferred language within the application. In this blog post, we will guide you through the process of implementing in-app language selection in an Android app.</p>
<h2 id="step-1-create-locale-string-resource">Step 1: Create Locale String Resource</h2>
<p>Create a string resource file for each respective locale by navigating to <code>res &gt; new &gt; Android Resource File</code> . Select Locale and create a <code>string.xml</code> file. Copy and paste the translations of your app content into these files.</p>
<h2 id="step-2-configure-locale-preferences">Step 2: Configure Locale Preferences</h2>
<p>In the <code>res/xml</code> folder, create a new file called <code>locales_config.xml</code> and specify the locales of your choice. for example look at the following code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#75715e">&lt;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;locale-config</span> <span style="color:#a6e22e">xmlns:android=</span><span style="color:#e6db74">&#34;http://schemas.android.com/apk/res/android&#34;</span><span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;locale</span> <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;en&#34;</span> <span style="color:#f92672">/&gt;</span> //English
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;locale</span> <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;ta&#34;</span> <span style="color:#f92672">/&gt;</span> //Tamil
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;locale</span> <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;hi&#34;</span> <span style="color:#f92672">/&gt;</span> //Hindi
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;locale</span> <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;ml&#34;</span> <span style="color:#f92672">/&gt;</span> //Malayalam
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/locale-config&gt;</span>
</span></span></code></pre></div><h2 id="step-3-add-resourcesproperties-file">Step 3: Add resources.properties file</h2>
<p>Switch to project view and in the <code>res</code> folder, create a new file called <code>resources.properties</code> and specify the default locales of your choice, this will be the fallback locale if the requested one is unavailable, for example look at the following code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-kotlin" data-lang="kotlin"><span style="display:flex;"><span>unqualifiedResLocale=en
</span></span></code></pre></div><h2 id="step-4-update-module-gradle-file">Step 4: Update Module Gradle File</h2>
<p>The list of language tags needs to be added to <code>resourceConfigurations</code> make sure you add all the language tags, have shared the updated code below as per my sample app:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-kotlin" data-lang="kotlin"><span style="display:flex;"><span>android {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">..</span>.
</span></span><span style="display:flex;"><span>    androidResources {
</span></span><span style="display:flex;"><span>        generateLocaleConfig = <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">..</span>.
</span></span><span style="display:flex;"><span>    defaultConfig {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">..</span>.
</span></span><span style="display:flex;"><span>        resourceConfigurations.plus(listOf(<span style="color:#e6db74">&#34;ta&#34;</span>, <span style="color:#e6db74">&#34;en&#34;</span>, <span style="color:#e6db74">&#34;hi&#34;</span>, <span style="color:#e6db74">&#34;your-language-tag&#34;</span>))
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h2 id="step-5-manifest-configuration">Step 5: Manifest Configuration</h2>
<p>You can let the device handle the locales, for that we are going to use a service called <code>androidx.appcompat.app.AppLocalesMetadataHolderService</code> with the following configuration, you can just copy paste the following code</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#f92672">&lt;application</span> <span style="color:#960050;background-color:#1e0010">...</span><span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;service</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;androidx.appcompat.app.AppLocalesMetadataHolderService&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">android:enabled=</span><span style="color:#e6db74">&#34;false&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">android:exported=</span><span style="color:#e6db74">&#34;false&#34;</span><span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&lt;meta-data</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">android:name=</span><span style="color:#e6db74">&#34;autoStoreLocales&#34;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">android:value=</span><span style="color:#e6db74">&#34;true&#34;</span> <span style="color:#f92672">/&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;/service&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/application&gt;</span>
</span></span></code></pre></div><h2 id="step-6-implement-locale-selection-function">Step 6: Implement Locale Selection Function</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-kotlin" data-lang="kotlin"><span style="display:flex;"><span><span style="color:#66d9ef">fun</span> <span style="color:#a6e22e">localeSelection</span>(context: Context, localeTag: String) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">Build</span>.<span style="color:#a6e22e">VERSION</span>.SDK_INT <span style="color:#f92672">&gt;=</span> <span style="color:#a6e22e">Build</span>.<span style="color:#a6e22e">VERSION_CODES</span>.TIRAMISU) {
</span></span><span style="display:flex;"><span>        context.getSystemService(LocaleManager<span style="color:#f92672">::</span><span style="color:#66d9ef">class</span>.java).applicationLocales =
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">LocaleList</span>.forLanguageTags(localeTag)
</span></span><span style="display:flex;"><span>    } <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">AppCompatDelegate</span>.setApplicationLocales(
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">LocaleListCompat</span>.forLanguageTags(localeTag)
</span></span><span style="display:flex;"><span>        )
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h2 id="step-7-usage-example">Step 7: Usage Example</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-kotlin" data-lang="kotlin"><span style="display:flex;"><span><span style="color:#66d9ef">val</span> context = <span style="color:#a6e22e">LocalContext</span>.current
</span></span><span style="display:flex;"><span>Button(onClick = {
</span></span><span style="display:flex;"><span>    localeSelection(context = context, localeTag = Locale(<span style="color:#e6db74">&#34;ta&#34;</span>).toLanguageTag())
</span></span><span style="display:flex;"><span>}) {
</span></span><span style="display:flex;"><span>    Text(text = <span style="color:#e6db74">&#34;Tamil&#34;</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>That&rsquo;s it! You&rsquo;ve successfully implemented in-app language selection in your Android app. Feel free to check out the <a href="https://github.com/Eganathan/Compose-LocalizationSample">sample app on GitHub</a> for a hands-on example.</p>
<p>If you encounter any issues or have questions, please leave a comment, and will do my best to assist you.</p>
<hr>
<p><em>Note: This article was originally published on Blogger on January 14, 2024 and imported to MangoDriod.</em></p>
]]></content:encoded></item></channel></rss>