I18N-Portable
I18N-Portable copied to clipboard
Locales not found when running on Xamarin iOS
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());
}
You need to set Build Action to Embedded Resource on the properties of every .txt file
Yes, the build action is set to Embedded resource for both my en.txt and fr.txt
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?
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.
Interesting. That seams like a bug with french locales. Can you guys confirm it just happens with french? @eggf @bhyip23
No, it is not just with French. Also with Russian, Spanish or Italian language.
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)
Can you guys tell what version/s of iOS and Xamarin.iOS are giving you trouble?
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)
Are you testing on simulator or physical device?
On both with same errors. iOS 11.1
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.
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.
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
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>