Are resx files a suitable way to customise for dif

2019-05-07 12:42发布

问题:

I'm looking at customising the various pieces of text in an application for different customers. It seems like .resx resources would be a sensible way to do this. However, all the literature for resx I come across seems to be about localising for language differences (as in English, French, Spanish, etc.), so just want to check it is the best thing simply for customer differences in text as well.

And, hypothetically, could it also deal with different languages for different customers, e.g.:

CustomerA.resx
CustomerA.en-US.resx
CustomerA.de-DE.resx

CustomerB.resx
CustomerB.en-US.resx
CustomerB.de-DE.resx

... etc

Is resx the way to go for customer differences?

回答1:

You can use them for storing different strings per customer - it will work. I imagine you don't have many customer to cater for and they do not require the strings to be modified very often. Otherwise the management of multiple files may become a real pain.

Storing per-customer strings in the database (with caching) may be a better option, especially if you want the customers to modify their strings.



回答2:

I wouldn't customize like this per customers, how do you specify then if you have to loadCustomerA or CustomerB resources? Resx are ok for languages localizations but if you want to have different texts for different customers, I would probably read the strings from a database table which would contain initially the default values then you customize values in the customer specific database.



回答3:

Yes, it is possible to do what you need with resx files. You can use custom cultures to achieve that. Please take a look at How to load different RESX files based on some parameter.