1

I am working on Xamarin iOS/Android and also have PCL project for portable class library. What I need is to use RESX files of PCL projects in Xamarin iOS/Android. My project is not Xamarin.Forms, so this link doesn't work for me. [Localizing Xamarin.Forms Apps with RESX Resource Files][1]

I don't want to use separated files on iOS and android for multi-language support.

My idea is as following:

1) Create two RESX files for english and chinese in PCL project.

AppResources.resx

AppResources.zh-CN.resx

2) Load RESX files from iOS and Android projects.

3) When the language is swichted in my app, change UI languages.

But I cannot find the exact way. I will be happy if you can help me.

Jimmy
  • 43
  • 8
  • https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/ – Akash Amin Jun 30 '16 at 05:29
  • Making `AppResources` class in `AppResources.Designer.cs` public and then use reference of this file eg. MyProject.Localization.AppResources.StringKey will give you value. – Vishnu Jul 01 '16 at 09:38

1 Answers1

1

I have solved this problem. Maybe this post helps me. ios localizing .net

I have created 2 resx files in PCL project. and named it as following.

LackPack.resx

LangPack_zh_CN.resx


And I defined a static function in PCL to

    public static string GetString (I18N sID)
    {
        string sResource = STRINGS_ROOT + "_" + currLocale;
        Type type = Type.GetType (sResource);
        if (type == null) {
            if (currLocale.Length > 2) {
                sResource = STRINGS_ROOT + "_" + currLocale.Substring (0, 2); // Use first two letters of region code
                type = Type.GetType (sResource);
            }
        }
        if (type == null) {
            sResource = STRINGS_ROOT;
            type = Type.GetType (sResource);
            if (type == null) {
                System.Diagnostics.Debug.WriteLine ("No strings resource file when looking for " + sID + " in " + currLocale);
                return null; // This shouldn't ever happen in theory
            }
        }
        ResourceManager resman = new ResourceManager (type);
        return resman.GetString (sID.ToString());
    }

we can use it on iOS/Android lie this.

Localise.GetString (I18N.TitleHistory);
public enum I18N
{
    BtnOk,
    BtnContinue,
    BtnLogin,
}
Community
  • 1
  • 1
Jimmy
  • 43
  • 8
  • Here is an alternative solution using .txt files and a nuget ready to go: http://xleon.net/xamarin/dotnet/localization/i18n/2017/02/09/easy-and-cross-platform-localization-for-xamarin-and-dotnet/ – xleon Feb 12 '17 at 15:43