Localising (or localizing) a Windows Phone application is straightforward, however, testing that you have correctly localised the text is harder. One method is to use a pseudo language but I found that has a couple of problems; you need to overwrite a locale (although you can use my previous posts to create a new ‘unsupported’ language), you need to maintain that language with your default language, and…I just find it over noisy. So I present an alternative.
Here is an example of an application I am working on;

If I switch on the ‘test localisation’ then the page looks like;

Argh, I’ve not localised ‘save’! The idea is that all the localised strings show up as their resource name surrounded by a ‘%’. I think this makes it easier to spot the non-localised text, plus you could turn it on during a test session therefore allowing you to report the resource id that is incorrectly localised for a specific language.
The code is based on a previous post but I’ll show the code again with the slight adjustments;
Note, if you want to dynamically support switching between a language and testing it, then you need to change the GetString to call the base class
public class TestResourceManager : ResourceManager
{
public TestResourceManager()
: base("MyApp.Localisation.StringLibrary", typeof(StringLibrary).Assembly)
{
}
public override string GetString(string name, System.Globalization.CultureInfo culture)
{
return "%" + name + "%";
}
}
Then add a constructor to the default string library.
public class LocalisedStrings
{
private static readonly StringLibrary _localizedResources = new StringLibrary();
#if DEBUG_LOCALE
static LocalisedStrings()
{
Type type = _localizedResources.GetType();
FieldInfo info = type.GetField("resourceMan", BindingFlags.NonPublic | BindingFlags.Static);
info.SetValue(null, new TestResourceManager());
}
#endif
public StringLibrary LocalizedResources { get { return _localizedResources; } }
}
Like this:
Like Loading...