I created a slightly ugly solution, but it works. My portable class library (PCL) has a folder called "strings" inside which files are created:
- strings.resx
- strings_fr.resx
- strings_ja_JP.resx
I installed all this as an Embedded Resource using a special tool like ResXFileCodeGenerator. This means that I have a separate resource DLL for each language.
In iOS, I can get the locale by calling:
string sLocale = NSLocale.CurrentLocale.LocaleIdentifier;
I would suggest that there is an Android equivalent using Locale , but I don't know what it is.
This gives me a string like "ja_JP" or "fr_FR" or "en_GB" (note that they underline, not dashes). Then I use this with the following static class that I created to get the appropriate resource manager and get a string from it.
If the locale aa_BB is specified, it first searches for strings_aa_BB, then for strings_aa, then for strings.
public static class Localise { private const string STRINGS_ROOT = "MyPCL.strings.strings"; public static string GetString(string sID, string sLocale) { string sResource = STRINGS_ROOT + "_" + sLocale; Type type = Type.GetType(sResource); if (type == null) { if (sLocale.Length > 2) { sResource = STRINGS_ROOT + "_" + sLocale.Substring(0, 2);
An example of how this will be used (with reference to the code above) would be:
string sText = Localise.GetString("enter_movie_name", sLocale); lblEnterMovieName.Text = sText;
A significant drawback of this is that all presentations will have to have their own typing programmatically, but have growth potential, that translations can be performed once, and then reused on many platforms. They also remain separate from the main code in their own DLLs and therefore can be recompiled individually if necessary.