views:

195

answers:

3

Hi,

To use the built in Localization (Resource Provider) in ASP.NET can only handle translated strings (see GetString("key", locale) with no user defined arguments if I have read the documentation correct.

What is the best, to build a custom resource provider that can handle arguments like GetString("key", locale, parameters)? To use that, I change the API which not is to good because the ResourceProvider always should be the same out to the developer and the only thing that can/should be different is the backend.

The second alternative I see is to build new provider that derives from ProviderBase or maybe to make a class that not derives from anything.

What do you think? Should I add methods to the Resource Provider or build something new?

+1  A: 

You could:

a) store the localized strings with placeholders, either {0}, {1},..., {n} which will then work with string.Format() or

b) use your own placeholders ({FirstName}, {LastName}, {JobTitle}, etc.) and then replace them in your own methods with actual values. Translators can move the placeholders around (because sentences are built differently based on the language).

I am not sure what you want the parameters for, but I guess it's about the scenario in b) above.

Pawel Krakowiak
A: 

Hi,

Yes, I want to use the parameters like the example you wrote, I've chose to use named placeholders like your b) example.

But for that, I'm forced to build a new layer on top the GetString to handle that, is it beautiful? I don't like that design.

Another thing that I'm forced to do with the ResourceProvider is to extend it to handle language rules like in English, one and other but in Czech, they use one, few, other. Russian language have a few rules more.

So maybe the best solution is to build a new Provider that not is built on top the ResourceProvider but the ProviderBase?

Does anybody have any suggestion/design tips?

Pawel is correct, you will need to do a giant work to implement your own provider, when there is no need. Just make a simple function that get the resource string and call your custom text replace function.
Eduardo Molteni
A: 

I push up this question a bit, does anybody have any suggestion or design tips, should I use the ResourceProvider or build something new (maybe build from ProvideBase)?