Reputation: 63835
I work on a product where we have to worry a bit about localization. Currently, this is the workflow for when I have to use(or add) a localized string:
ResourceFactory.ResourceMgr.GetString("MY_MAGIC_STRING")
(where ResourceMgr
is just a static field to a ResourceManager)This 3 step process for any strings is a real pain. Are there any patterns or ways to make this process easier?
Upvotes: 12
Views: 958
Reputation: 15029
There is this Java solution that might give you some ideas: http://rodionmoiseev.github.com/c10n/
The idea is to store translations in the source code itself, using annotations on interface methods. Then, by using a special utility, you can dynamically create proxies (classes dynamically implementing the interface) that would return localised string value when invoking the interface method.
This way, "MY_MAGIC_STRING"
is replaced with a call to MyMagicString()
method, which gives you some spelling/type safety and makes it more refactoring friendly.
Upvotes: 0
Reputation: 100547
Auto-generated files with access to each individual string are much easier to use - set "Custom tool" for RESX file to PublicResXFileCodeGenerator
.
Code would look like:
using MyProject.Resources;
...
localizedText = Resources.SomeReasonableName;
Side notes:
Upvotes: 5