If you are building native android and iOS apps you could have the interface:
public interface ILocalization {
string GetLocalizedString(string key);
}
And in the Android and iOS projects you have a class that implements the interface, Android:
public class LocalizationAndroid : ILocalization
{
public Activity context;
public LocalizationAndroid(Activity _context) {
context = _context;
}
public string GetLocalizedString(string key)
{
var resourceId = (int)typeof(Resource.String).GetField(key).GetValue(null);
return context.GetString(resourceId);
}
}
iOS:
public class LocalizationIOS : ILocalization
{
public string GetLocalizedString(string key)
{
return NSBundle.MainBundle.LocalizedString(key, null);
}
}
And then pass one instance of the class (instantiated in your view) to the view model to get the strings. The strings must be placed at the Localizable.strings file for the iOS project and at the Strings.xml file for the Android project.
On the ViewModel you would have:
public class MyViewModel
{
public ILocalization LocalizationObject;
private List<Thing> _items;
public MyViewModel(ILocalization _localizationObject)
{
LocalizationObject = _localizationObject;
_items.Add(new Thing(LocalizationObject.GetLocalizedString("Open")));
_items.Add(new Thing(LocalizationObject.GetLocalizedString("Closed")));
}
}
This, considering the fact that you added the two strings "Open" and "Closed" for the "Open" and "Closed" keys on the Strings.xml(Android) and the Localizable.strings (iOS).