Globalization, Localization Xamarin.Forms

PhenekPhenek Member ✭✭

Hello World,

I'm using Visual Studio for Mac, to build iOS and Droid Applications
I'm searching an easy way to make internalisation on my Application.

First I try this way https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/localization/
But all *.Designer.cs are not auto generated.
Seems I got some problem with ResXFileCodeGenerator. ("Can only be use with .NET project" => Best Error ever in C#!)

Second I tried this way https://github.com/xleon/I18N-Portable,
but the I18n don't find my Locales folder with all en.txt *.txt
Seems I got problems with ressource files

If you got any idea why I can't make it works
Please help me

If you got any third library that can make my life easier with internationnalisation, like I18n can do when it's working.
Please tell me

Thanks by advance for your answers

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    First test - Is it VS for Mac?
    Do you have access to a Windows machine with Visual Studio? Or can you install VS for Windows on your mac either through VMWare parallels or booting into Windows through bootcamp?

    If it works right in Windows but not on Mac, then you know its VS for mac.
    If its bad on both platforms then make sure you're doing everything correctly since many others have used that tutorial successfully.

  • ClayZuvichClayZuvich USMember ✭✭
    edited March 2018

    IMO, I would not follow instructions posted on the Xamarin Forms link. I would suggest using the native implementation, and then provide a very simple API to access the string on both platforms.

    The drawback of course is that you end up with strings in both platforms; however, you will not have to deal with weird behavior trying to normalize the strings in a resx file. I'm fairly certain you have to use the native implementation anyways to support iOS plist specific strings, so why not keep it consistent and easy?

    In other words, follow instructions for iOS and Android, not for Forms. Here's a code snippet I've used for getting localized strings from the native platforms.

    iOS Implementation

    public override string GetLocalizedString(string key) {
    return NSBundle.MainBundle.LocalizedString(key, null);
    }

    Android

    public class LocalizeImplementation : Localize {
    private const string StringResourceType = "string";

        public override string GetLocalizedString(string key) {
            var context = Android.App.Application.Context.ApplicationContext;
            if (context == null)
                return key;
    
            var id = context.Resources.GetIdentifier(key, StringResourceType, context.PackageName);
            return context.Resources.GetString(id);
        }
    
  • PhenekPhenek Member ✭✭

    Thanks for your suggestions :) .

    I will wait a few days more before starting implementation of Globalization.

    hope some people will suggest me more solutions :p

Sign In or Register to comment.