Reputation: 43
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.
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.
Upvotes: 1
Views: 1620
Reputation: 43
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,
}
Upvotes: 1