How can I localize strings in ServiceStack annotations? E.g. from a resource file. At the moment I help myself with string constants. But of course it is not possible to change the language at runtime or on startup. Surely there is a more elegant solution!
[Input(Label = label.FirstName, Help = help.FirstName)]
public string FirstName { get; set; }
There’s no explicit support for localization, but all attributes are used to populate the App Metadata which you can modify at runtime with something like:
Where ResolveLocalizedString is an API you can override in your AppHost to return alternative text which ServiceStack uses for internal error messages.
I’ll look at doing this by default for these properties now so you’ll only need to override AppHost.ResolveLocalizedString() in future.
FYI in the latest v6.1.1 that’s now available on MyGet, the localizable strings are now being passed to ResolveLocalizedString so you can just override it in your AppHost to return the localized alternative text.
If your ResolveLocalizedString() is never being called when you call /metadata/app.json then you’ll need to clear your NuGet packages cache to download the latest v6.1.1: