I18N-Portable icon indicating copy to clipboard operation
I18N-Portable copied to clipboard

Locales not found when running on Xamarin iOS

Open fiftysixkbit opened this issue 7 years ago • 15 comments

I am able to deploy on Android but on iOS, I get the following error:

I18NPortable.I18NException: No locales have been found. Make sure you've got a folder called 'Locales' containing embedded resource files (with extensions .txt) in the host assembly

The app has been terminated.

I have a Locales folder in my Core project that contains en.txt and fr.txt.

The exception occurs in App.xaml.cs where I18N gets initialized.

public App()
{
    InitializeComponent();

    I18N.Current
        .SetLogger(text => Debug.WriteLine(text))
        .SetFallbackLocale("en")
        .Init(GetType().GetTypeInfo().Assembly);

    MainPage = new NavigationPage(new LoginPage());
}

fiftysixkbit avatar Feb 23 '18 09:02 fiftysixkbit

You need to set Build Action to Embedded Resource on the properties of every .txt file

xleon avatar Feb 23 '18 12:02 xleon

Yes, the build action is set to Embedded resource for both my en.txt and fr.txt

image

fiftysixkbit avatar Feb 23 '18 22:02 fiftysixkbit

I have the very same setup and it works fine. Are you sure that GetType().GetTypeInfo().Assembly is the same assembly where .txt files are?

Can you attach a test project that I can try myself?

xleon avatar Feb 23 '18 23:02 xleon

I got similar problem with iOS devices. I18N-Portable does not choose the correct translation file. For me it seems that the system has mixed up localization codes as you can see in the image.

unbenannt

eggf avatar Feb 27 '18 09:02 eggf

Interesting. That seams like a bug with french locales. Can you guys confirm it just happens with french? @eggf @bhyip23

xleon avatar Feb 27 '18 10:02 xleon

No, it is not just with French. Also with Russian, Spanish or Italian language.

eggf avatar Feb 27 '18 10:02 eggf

Ok, I´ll make some tests to see if I can find a fix or at least to isolate the bug (not sure if this is an iOS bug or a Xamarin bug)

xleon avatar Feb 27 '18 10:02 xleon

Can you guys tell what version/s of iOS and Xamarin.iOS are giving you trouble?

xleon avatar Feb 27 '18 10:02 xleon

Visual Studio 2017 Version 15.4.5 Xamarin 4.7.10.38 (34c1b6c) Xamarin.iOS and Xamarin.Mac SDK 11.3.0.47 (51128b8) Visual Studio for Mac Version 7.2.2 (build 11) XCODE Version 9.1 (9B55)

eggf avatar Feb 27 '18 10:02 eggf

Are you testing on simulator or physical device?

xleon avatar Feb 27 '18 12:02 xleon

On both with same errors. iOS 11.1

eggf avatar Feb 27 '18 12:02 eggf

I think we are hitting this exact bug on iOS 11: https://bugzilla.xamarin.com/show_bug.cgi?id=59596 There´s a potential workaround in this comment: https://bugzilla.xamarin.com/show_bug.cgi?id=59596#c8 and this one: https://bugzilla.xamarin.com/show_bug.cgi?id=59596#c26

I was struggling with it for a bit, and I solved issue (in my app) by configuring properly info.plist. Before change in my info.plist I had something like

<key>CFBundleDevelopmentRegion</key>
<string>pl</string>
<key>CFBundleLocalizations</key>
<array>
<string>pl</string>
</array>

Now I changed it to someghing like:

<key>CFBundleDevelopmentRegion</key>
<string>en_US</string>
<key>CFBundleLocalizations</key>
<array>
<string>cs_CZ</string>
<string>da_DK</string>
<string>de_DE</string>
<string>en_US</string>
<string>nl_NL</string>
<string>pl_PL</string>
<string>pt_BR</string>
<string>pt_PT</string>
<string>ru_RU</string>
<string>sv_SE</string>
<string>zh_CN</string>
</array>

When I did it, localization started to work as expected.

xleon avatar Feb 27 '18 15:02 xleon

Just an update for my original problem... I tried to reproduce it with a new project but everything works, so I just moved all my files to the new project.

fiftysixkbit avatar Feb 27 '18 19:02 fiftysixkbit

Please @bhyip23 can you attach your old and new info.plist files in the iOS project? It would be good to know what are the changes affecting this bug

xleon avatar Feb 27 '18 20:02 xleon

Sorry for the late reply, been really busy with other stuff.

The only difference in the info.plist is that the old one had an extra entry:

<key>CFBundleName</key>
<string>My_Application</string>

fiftysixkbit avatar Mar 29 '18 07:03 fiftysixkbit