Localization: How to allow the user to define custom resources without compiling?

Posted by gehho on Stack Overflow See other posts from Stack Overflow or by gehho
Published on 2010-03-24T15:24:09Z Indexed on 2010/03/25 7:43 UTC
Read the original article Hit count: 326

Filed under:
|
|
|

In our application, we have a collection of data items, each with a DisplayedName property. This property should be localized, i.e. it should be displayed in the language selected by the user. Therefore, another property, DisplayedNameResourceKey, specifies which resource should be returned by the DisplayedName property.

In simplified code this means something like this:

public string DisplayedName
{
    get
    {
        return MyResources.ResourceManager.GetObject(this.DisplayedNameResourceKey);
    }
}

public string DisplayedNameResourceKey
{
    get;
    set;
}

Now, the problem is: The user should be able to edit these items including the DisplayedName, or more precisely the DisplayedNameResourceKey. And not only this, but the user should also be able to somehow define new resources which he can then reference. That is, he can either choose from a predefined set of resources (some commonly used names), or define a custom resource which then needs to be localized by the user as well.

However, the user cannot add custom resources to MyResources at runtime and without compiling. Therefore, another approach is needed. It does not have to be an extremely user-friendly way (e.g. UI is not required) because this will typically be done by our service engineers.

I was thinking about using a txt or csv file containing pairs of resource keys and the corresponding translations. A separate file would exist for every language at a predefined location. But I am not really satisfied with that idea because it involves a lot of work to resolve the resources.

Does anyone know a good approach for such a situation?

© Stack Overflow or respective owner

Related posts about localization

Related posts about resources