Localization (i18N) in ASP.Net Multi-tenant SaaS application

断了今生、忘了曾经 提交于 2020-06-25 16:21:13

问题


Problem scenario:

Implement ASP.Net localization in a SaaS based application.

Additional complexity: The tenant should be able to edit the localized content. Thus, if the hosted application has 10 tenants with each supporting 5 languages, we could end up with 50 units of translation content.

Please suggest on what would be an ideal approach given the above scenario.

Listed below, are approaches used in the past (for my other applications) and why they are not relevant now:

Option 1: ASP.Net resource files

Problem: Only one language file is created per localizable resource (.aspx page). Hence, it is not possible to have one Home.aspx.resx file for each of the tenant translations. Though the resx keys can be modified to contain the TenantId (lblFirstName_44) and stored in the same resx file, but then this would be difficult to maintain and we could end up with large files.

Option 2: Storing multilingual content in dedicated database tables (Labels, Messages, MenuItems)

Problem: This has worked well in the past (in scenarios where the end user requires dynamic update of localizable content). The earlier solution relied heavily on cached data, in case of a multi-tenant solution the data would require extensive caching per page – per tenant. The caching could also be done per content type (Labels, Messages, MenuItems)

An alternate approach could be to implement a custom resource provider (by building on .Net’s existing provider)

Option 3: Third party open source solutions like FairlyLocal

Problem: Although very simple to implement, suffers from the same drawback as .resx files – not designed for allowing the end user to modify the content and to maintain multiple versions (tenant-wise) of same file.

Note: In case of not finding another solution, we would probably go with Option 2


回答1:


I'd go for the second option. Especially since your resource entries are subject to modifications, resex files are not an option as you have said.

. You can easily find a good resource provider such as westwind one or write a custom provider.




回答2:


The first option (storing translatable texts into resource files) is out. This would result in totally unmanageable mess.

The second option (using Database) is the most promising, just write your own Resource Provider, implement DB logic and you are done. In case of multi-tenancy, you would also need to provide valid context (based on URL?) and fall-back mechanism (so if the resource key is not found for this tenant, it would use default string) but these are minor annoyances.

As for third-party solutions I haven't heard of one that could be used in your context. You would probably have to implement almost the same amount of code as in case of DB solution (to support multi-tenancy) but you would end up with having a dependency on some vendor - this seems less flexible to me (just think how you would fix bugs...).




回答3:


The only option that sounds scalable and maintainable is to store localized text in database. Resource type could be a bit complicated to map (such as images) but still a better solution than either of the other two.

It makes me wonder, how come Microsoft did not think of a solution to this challenge specially with their Azure initiative.



来源:https://stackoverflow.com/questions/6571481/localization-i18n-in-asp-net-multi-tenant-saas-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!