Bug 31720 - Localizing With RESX Resource Files Does Not Work
Summary: Localizing With RESX Resource Files Does Not Work
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2015-07-07 14:43 UTC by Jimmy [MSFT]
Modified: 2017-08-23 21:01 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Cannot reproduce failure described (117.59 KB, image/png)
2015-07-07 16:02 UTC, CraigD
Details
using shared runtime doesn't seem to affect my test (146.40 KB, image/png)
2015-07-07 17:33 UTC, CraigD
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Jimmy [MSFT] 2015-07-07 14:43:21 UTC
*** Overview ***
An Android app built with Xamarin.Forms and using RESX Resource files for localization does not load the correct language resources for the device and instead uses the English resources.

I reproduced this bug using the Xamarin.Forms Localization with RESX sample project available here: http://developer.xamarin.com/samples/xamarin-forms/UsingResxLocalization/


*** Steps to Reproduce ***
1. On the Android emulator or device, change the language to another language like Spanish or German
2. Download and run the sample project linked to above  
 

*** Actual Results ***
The app’s string resources are in English even though the system is set to another language.  


*** Expected Results ***
The app’s string resources are in the same language as what the system is set to.

The expected results can be seen by running the project on iOS, which does not experience this bug.


*** Environment Info ***
=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.iOS ===

Version: 8.10.3.2 (Business Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Xamarin.Android ===

Version: 5.1.4.16 (Business Edition)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.35 (Business Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.3
Darwin Jimmys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 CraigD 2015-07-07 16:02:13 UTC
Created attachment 11914 [details]
Cannot reproduce failure described
Comment 2 CraigD 2015-07-07 16:02:34 UTC
I've just downloaded and tested the sample - I've included my configuration information below for comparison.

For me, the sample works as expected (without making any modifications). 
When I set the Android system language to Spanish, the correct language strings and flag graphic are shown. See attached screenshot.

The code mentioned here...

http://developer.xamarin.com/guides/cross-platform/xamarin-forms/localization/#Troubleshooting_Embedded_Resources

...is already in the App.cs file. Can you confirm that you see the following output in the console?

     ===============
     found resource: UsingResxLocalization.Resx.AppResources.resources
     found resource: UsingResxLocalization.PagesXaml.FirstPageXaml.xaml

Also, verify the output from the Android/Localize.cs file emits the following (to confirm that the correct language is being recognized).

     android:es_ES
     net:es-ES
     es-ES

Finally, were any other configuration changes made to the Android project options (eg. build options, linking options, etc)?

------ CONFIGURATION INFORMATION ------

Xamarin Studio
Version 5.9.4 (build 5)
Installation UUID: 81270b48-59a5-4b76-86eb-a908e437fbd4
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

Xamarin.Android
Version: 5.1.4.16 (Business Edition)
Android SDK: /Users/craigdunn/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Xamarin Android Player
Version: Unknown version
Location: /Applications/Xamarin Android Player.app

Build Information
Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

Operating System
Mac OS X 10.10.3
Darwin Craigs-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 3 Jimmy [MSFT] 2015-07-07 17:11:56 UTC
It looks like having "Use shared Mono runtime" under Options > Android build is causing the issue. 

With the option checked, the correct flag image is shown, but the controls aren't localized. I was using the debug config to test and the option is turned on by default for debug builds and turned off in release builds.
Comment 4 CraigD 2015-07-07 17:33:33 UTC
Created attachment 11918 [details]
using shared runtime doesn't seem to affect my test
Comment 5 CraigD 2015-07-07 17:37:17 UTC
I'm glad you've found a scenario where you can make it work (it's always a good idea to test with "production" settings, as well as with our debugging-experience optimizers enabled).

I'm still puzzled though - as the second attached screenshot shows, I'm also using the shared runtime in my testing. If there are any other settings you've noticed that make a difference, I'd love to hear about it and get to the bottom of the difference in behavior.
Comment 6 CraigD 2015-07-07 18:26:46 UTC
UPDATE: apparently a *Clean* isn't enough to remove old builds. 

With a more rigorous delete and re-build process, I'm able to see the same results as you (I should know better than to trust *Clean*).

I'm marking this as a confirmed bug - but I'm not really clear if it will be 'fixed'. To answer my own questions above:

* YES, the resources seem to be loaded; the following appears in the output console (so it's at least finding the default resources)

    ===============
    found resource: UsingResxLocalization.Resx.AppResources.resources
    found resource: UsingResxLocalization.PagesXaml.FirstPageXaml.xaml

* YES, the language is detected correctly, the following appears in the output console

   android:es_ES
   net:es-ES
   es-ES

* YES, the flag displays correctly (which confirms the language is detected correctly). Because this is just a modified path on disk, rather than an embedded resource being loaded, this probably makes sense.

So it appears the problem is with _loading_ the resources. On further testing, it appears that the culprit is actually the *Fast assembly deployment* sub-option of the Shared Mono Runtime... I can consistently make it work/fail simply by changing that setting.

The feature description for *Fast assembly deployment* is:

> Creates a package without assemblies, and deploys assemblies directly to the device. Improves re-deployment speed after code changes.

I'm theorizing that this affects the ability to load the resource satellite assemblies.

WORKAROUND: for now, I've updated the sample so that the configuration you get when you download it does NOT use *Fast assembly deployment*
Comment 7 Jonathan Pryor 2015-07-08 12:54:25 UTC
What device are you seeing this with? Is it a Galaxy S5 or S6?

This is *probably* Bug #31037, in which .resx-based localization doesn't work when using Fast Deployment to a Galaxy S5 and S6 (and others?).

It Works For Me™ on a Nexus 5:

$ cd UsingResxLocalization/Android
$ xbuild /t:Install /p:EmbedAssembliesIntoApk=False
...
> 		Using fast dev path: /storage/emulated/0/Android/data/UsingResxLocalization.Android/files/.__override__
$ xbuild /t:_Run

When my language is set to German, I see the expected German strings.

Now, what's different wrt the Galaxy S 6? It's the "fast dev path" contents:

> $ adb shell ls -l /storage/emulated/0/Android/data/UsingResxLocalization.Android/files/.__override__
> ...
> drwxrwx--- u0_a139  sdcard_r          2015-07-08 12:42 de
> $ adb shell ls -l /storage/emulated/0/Android/data/UsingResxLocalization.Android/files/.__override__/de
> -rw-rw---- u0_a139  sdcard_r     3072 2015-07-08 12:47 UsingResxLocalization.resources.dll

On the Galaxy S 6, the "de" and other locale directories aren't created, so only the default (English) translation is available.

Disabling fast assembly deployment causes the assemblies and the resource assemblies to be embedded into the .apk, instead of deployed separately. This works around the issue on the above Galaxy devices, but at the cost of increased debug turnaround times: instead of *maybe* rebuilding and reinstalling a ~3.2MB .apk -- which may be skipped, depending on the nature of the code change -- instead a 6.4MB .apk must *always* be rebuilt and reinstalled for *every* code change.

, as the entire .apk needs to be rebuilt, c
Comment 8 Jimmy [MSFT] 2015-07-08 13:43:07 UTC
I only tested on the emulator, no devices.

If the translations don't seem to work with Fast Deployment enabled on the emulator, could we get a note on the Localization guide indicating this? Or is it something that can be fixed?
Comment 9 CraigD 2015-07-08 13:51:12 UTC
@jimmy.garrido I already updated the doc and added this information to the Troubleshooting section.

@jonp I was testing with Xamarin Android Player - Nexus 4 (KitKat) image.

I agree that it sounds like Bug #31037
Comment 10 BogdanU 2015-12-26 16:48:41 UTC
I can confirm this issue and tested the following methods:

1) In Xamarin Studio at Android Build Options, unchecked Use Share Mono Runtime, uncheck Embed assemblies in Native Code, created Android Package and mounted app on a Galaxy S3 as well as on an AllView A5 Easy, strings do not appear in other language that the default from AppResources.resx.

2) In Xamarin Studio at Android Build Options, checked Embed assmblies in Native Code, mounted on same 2 devices, same thing happening.

In Xamarin Android Player using an Android KitKat Nexus 4, the strings show correctly. Any solution to strings displaying would be highly appreciated right now.
Comment 11 Radek Doulik 2016-01-18 10:38:38 UTC
Bogdan, what is the version of Xamarin Android you use to replicate it? What Android version is on your devices?
Comment 12 Cody Beyer (MSFT) 2017-08-23 21:01:02 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!