开发者

Localization in the Business Layer

We are writing an ASP.开发者_StackOverflow社区NET MVC application and every once in a while we need to add a string to a description or a note that is not generated by the UI to a database record. For example, if we need to reverse a transaction, we will prepend the word 'Reverse' to the description of the original transaction.

What is the best way to go about localizing these strings we have to add every now and again? On the web project we are using resource language files so everything is really taken care of by the .net framework. Can you get a class library project (the business layer) to take advantage of the automatic localization like a web project as well?


What we usually do is having additional resource files in the back-end projects. Usually they don't grow that big, so I think it's safe to do that. Usually, you can then access those resources like this:

string dummy = Properties.ResourceFileName.Reverse;

If you add a resource file in Visual Studio, the IDE will take care of generating the required code-behind to make that work.

For your example, I would suggest you having a string like this:

Reverse {0}

Then replace {0} with the actual transaction description. This way the translator will be able to move {0} before "Reverse" in case the specific language requires it. This is just an example, but best practices suggest us to avoid concatenating localizable strings as they may break in different languages. Example:

string dummy = string.Format(Properties.ResourceFileName.Reverse, transactionDescription);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜