Localization Approach for ASP.NET Web site

String Resources

For string resources we will use local/global resources connecting to DB using DbResourceProvider from  “Creating a Data Driven ASP.NET Localization Resource Provider and Editor”
http://www.west-wind.com/presentations/wwdbresourceprovider/

It also has  DbResourceControl,  that shows controls with Localizable attribute and connect them to editor.

From http://guysmithferrier.com/Downloads/Top10TipsI18NASPNET.pdf and
http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
To convert your HTML controls to equivalent ASP.NET server side controls, look at the I18NRefactorings (an add-in for VS) in the download at http://www.dotneti18n.com/Downloads.aspx (folder VS2010/ASPNETSpecifics/I18NRefactorings/I18NRefactorings in the 2010 zip)that will help automate this process.

Javascript Files

For javascripts we should separate localizable and non-localizable functions ,e.g. MyScript.js and MyScript.L10n.js(L10n stands for localization)  and
use ResourceUICultures to specify languages supported, e.g.(from Around the World with ASP.NET ASP.NET AJAX documentation Applications http://msdn.microsoft.com/en-us/magazine/cc135974.aspx#S3)

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”

EnableScriptLocalization=”true”>

 <Scripts>

   <asp:ScriptReference Path=”MyScript.L10n.js”     ResourceUICultures=”ru”/>

 </Scripts>

</asp:ScriptManager>

Consider to use CompositeScript as described in
http://bellouti.wordpress.com/2008/09/14/combining-javascript-files-with-ajax-toolkit-library/ and
http://www.asp.net/ajaxlibrary/Combining%20Client%20Scripts%20into%20a%20Composite%20Script.ashx

ASP.NET Control to extract Resource information as JSON http://www.codeproject.com/KB/custom-controls/ResourcesToJavaScript.aspx

ScriptManager links
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.enablescriptlocalization.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptreferencebase.resourceuicultures.aspx
Other related links
Check if a language file is loaded for jQuery Globalization plugin

CSS Files
For CSS consider to use different themes for different cultures.
(examples not L10n specific
http://www.codeproject.com/KB/aspnet/dynamicThemes.aspx
Dynamically Applying Themes To Your ASP.Net Site With A Sitemap
ASP.NET Themes and Skins http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx
http://www.codeproject.com/KB/aspnet/ThemesAndSkins.aspx

)
From http://stackoverflow.com/questions/3230576/load-different-css-for-site-localization
void Page_PreInit(object sender, EventArgs e)
{
   //If current context has no session then abort
   if (HttpContext.Current.Session == null)
       return;

   //Get current page context
   Page page = (Page)sender;

   switch (page.Culture) {
       case “en-US”:
           page.Theme = “en-USTheme”;
           break;
       case “fr-FR”:
           page.Theme = “fr-FRTheme”;
           break;
       default:
           page.Theme = “DefaultTheme”;
           break;
   }
Additionally  FallBack implementation is required.

Alternative css -related solutions
http://stackoverflow.com/questions/1221441/localize-images-via-css has a few suggestions, not something too attractive.
CSS Loader from resource http://forums.asp.net/t/1346799.aspx/1?CSS+with+localization not attractive for me- prefer to maintain css in file system

Concerns about themes from  http://forums.asp.net/t/1176552.aspx/1

I have abandoned the concept of Themes, at least the ASP.NET way. There are several reasons for that:

  1. One cannot control the CSS files used on a page through Theming. All CSS files in a Theme gets applied, even if you plan to use just one for a page.
  2. One cannot localize a Theme, one need to create a copy of the default and apply the changes to it, creating a theme that is culture specific.

 

The solution I opted for is to create my own Styles folder in which different ‘Themes’ are place in their respective subfolders. I can now control the CSS & apply text-direction when neccessary.

 

Localized Files

http://stackoverflow.com/questions/1982686/asp-net-localized-files
string cultureSpecificFileName = String.Format(“TOS_{0}.pdf”, CultureInfo.CurrentCulture.Name)
In the example given, the file would have to be named TOS_en-US.pdf. It you want to use the 2-letter ISO culture names, use CurrentCulture.TwoLetterISOLanguageName and then the file name would be TOS_en.pdf.
http://forums.asp.net/t/1039924.aspx/1?Themes+and+images+localization
You can create page specific resource files or global resource file and localize imageurl there.
For example, in Default.en-GB.aspx (in App_LocalResources): Image1.ImageUrl = “xxx”, while add meta:resourceKey=”Image1″ in .aspx to the Image to localize~
Or make a MyGlobal.en-GB.resx (in App_GlobalResources), Image1Url = “xxx”, and then add ImageUrl=”<%$ Resources:MyGlobal, Image1Url %>” to the Image to localize.

From http://www.globalme.net/web-localization/aspnet-localization
If possible, try avoiding images and graphics with embedded text. Using background images and retrieving the text from a resource file will make the localization effort much easier. If that is not possible, point the source of the image to the resx file which will let you easily change it depending on the language. This applies to other external assets such as pdf and doc files as well.

Tools for adding Localization to an ASP.NET project

Resharper for localization -http://www.jetbrains.com/resharper/webhelp/Resources__Index.html
If don’t have Resharper -try free Resource Refactoring Tool (http://resourcerefactoring.codeplex.com/)

Zeta Resource Editor http://zetaresourceeditor.codeplex.com/ also lists a few other tools.

Consider GetCultureFromUrl(Request.Url);
(from http://guysmithferrier.com/Downloads/Top10TipsI18NASPNET.pdf)

General Localization related links:

Localizing Resources for Component Libraries Overview

http://msdn.microsoft.com/en-us/library/bb398937.aspx#Localizing_Static_Script_Files_and_Their_Resources

http://www.beansoftware.com/ASP.NET-Tutorials/Globalisation-Multilingual-CultureInfo.aspx http://www.asp.net/general/videos/how-do-i-create-a-multi-lingual-site-with-localization

Generate a local resource file from an ASP.NET Web page

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx

http://asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html

Localize ASP.NET MVC 2 DataAnnotations validation messages with a custom resource provider

Why we have both CurrentCulture and CurrentUICulture

Extending the ASP.NET 2.0 Resource-Provider Model
BONUS CHAPTER 1.Resources and Localization
http://roundedcorners.wordpress.com/2010/04/10/resources-for-a-custom-resource-provider/

Advertisements