Xamarin.forms: [Android] Localization does not work properly with "Bundle assemblies into native code" option enabled

Created on 17 Jan 2018  路  17Comments  路  Source: xamarin/Xamarin.Forms

Description

Localization does not work properly with "Bundle assemblies into native code" option enabled in release mode. Once the locale is changed, the app picks the default locale strings(English), although the language/locale was changed to, say, spanish/french.

To fully change the strings, we have to force kill the app (Remove from recent apps section), and then restart the app, only then the strings are picked correctly according to the set locale. The locale changes only once per session of the app. If we change the locale again from spanish to french, it starts picking default strings(English) again and we have to force kill the app and restart again.

However this problem doesn't occur when running in debug mode, or in release mode with "Bundle assemblies into native code" switched off. The resource strings are in Xamarin.Forms project and we are changing the locale as given in this link.
Somewhat very similar to this bug .
Also, the said workaround in the bug comments don't work either.

Steps to Reproduce

  1. Create Xamarin.Forms app
  2. Add localization support as shown here
  3. Enable "Bundle assemblies into native code" in Android build options
  4. Start the app and change the language

Expected Behavior

App should change the locale and display the strings of the changed locale.

Actual Behavior

App shows the default(English) locale strings, doesn't change the strings until next restart of the app.

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE: VS 2017 Enterprise 15.5.1

    • Platform Target Frameworks: iOS, Android

    • iOS:

    • Android: 8.1.0.24 (HEAD/9cfa7836b)

    • UWP:

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:
l10n 5 help wanted low high impact Android bug up-for-grabs

Most helpful comment

Hi Xamarin team. Do you have any update on this serious bug? We cannot implement multi-language features right now because of this bug.
Also, We need a proper workaround.

All 17 comments

do you have a sample project with the issue?

I tried the Xamarin localization sample project here
https://github.com/xamarin/xamarin-forms-samples/tree/master/TodoLocalized

and in release mode with embedded assemblies the language on everything updated when I changed the locale on the device without having to restart the app.

It is working if you change the device locale from Andoid's settings but if you want to change the locale from the code like below, it doesn't work and fallbacks to English.

var ci = new System.Globalization.CultureInfo("es");
DependencyService.Get<ILocalize>().SetLocale(ci);
AppResources.Culture = ci;
public void SetLocale(CultureInfo ci)
{
    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;
}

@bulente Exactly! It doesn't change in runtime like that.

This is probably related to this bug https://github.com/xamarin/Xamarin.Forms/issues/2049

Other platforms like UWP, Silverlight, and WPF have a "Language" property on FrameworkElement. But, Xamarin Forms doesn't yet have such a property and therefore the page doesn't know what language to use. We've had to work around this with converters.

We've had to work around this with converters.

My workaround is: Instead of giving the user a list of languages for selection, I only list 2 selection items: Use phone's language and English. Then the samples work fine.

from #4479 @raphibolliger reports

Demo project

https://github.com/raphibolliger/XamarinLocalizeTest
You can have a look at the view on the running app. Its also a short logging included during app startup which will write a translated (or not) sentence to the console.

Workaround

My workaround for this problem is to manually include builded dll's of resources in the Android project via Assets. And then load it on startup in MainActivity. This is not included in the demo project.

Steps to Reproduce

  1. Build the demo project with "Bundle assemblies into native code" enabled in release mode
  2. Start the app
  3. Verify the localized sentences

@rmarinho Do you have any idea when someone can take care of this bug? Its a blocking issue for your customer project. And this comes along with a enterprise feature which is not cheap.

I have also new information about my described workaround above. After some more tests I figured out that this is also not working. So we have no workaround and still waiting that this would be fixed.

Does anybody solved this issue ? We are still waiting for a new Xamarin version to correct this bug.

Any updates on this bug?

Hi Xamarin team. Do you have any update on this serious bug? We cannot implement multi-language features right now because of this bug.
Also, We need a proper workaround.

Any updates on this bug? This is a major blocker for the multi-language application and we need some workaround to address this issue.

Hello @PureWeen ,
I have the same problem
With the app in debug all works in the right way
If I publish the app in release, then only english is shown.
nb: in android settings I cant see "Bundle assemblies into native code", anyway I publish my app into playstore using aab

My company app should go live in store in a few days...How should I solve this issue?
I cant have app only in english

I noticed that if I remove
<AndroidPackageFormat>aab</AndroidPackageFormat>
from 'myproject.Android.csproj' then localization works, but I can't create aab anymore

For now I solve removing AndroidPackageFormat and using 'Generate one package per selected ABI'

@PureWeen Hi, any update on this? This is a major blocker for us too. We change language at runtime based on user need.

For anyone is facing the issue, you only need to update Xamarin.Android from 10.0 to 10.1 or up.

ref: https://github.com/xamarin/xamarin-android/issues/3596

@sasivishnu can you confirm what @huybuidac has indicated?

@PureWeen Sorry, missed this comment altogether due to chaos situation at that time. We released our app without having multi-language support.

Later this weekend or next weekend, I will play around and confirm this. Thanks @huybuidac for information :)

Was this page helpful?
0 / 5 - 0 ratings