Five New FxCop Globalization Rules

I have updated the downloadable source code for my .NET Internationalization book. The Visual Studio 2012 source code is downloadable from here. In this update there are 5 new FxCop globalization rules:-

  • Do not convert to uppercase - This rule catches all uses of ToUpper. It can be considered a more severe version of FxCop's own "Specify CultureInfo" rule. If the conversion to uppercase is used to perform a case insensitive comparison then String.Compare should be used instead. If the conversion to uppercase is used to change user data then it would be better not to convert the user data at all.
  • Do not convert to lowercase - This rule catches all uses of ToLower. It serves the same purpose as the previous rule except that it catches ToLower instead of ToUpper.
  • Boolean.ToString() is not localizable - This rule catches all uses of Boolean.ToString(). The words "True" and "False" are specific to English and are therefore not localizable. This rule is similar to the existing "Enum.ToString() is not localizable" rule.
  • Identifiers should not be called FirstName - This rule catches fields and properties that are called FirstName (or a variation of FirstName). The term "first name" is a western naming convention and it does not accurately identify a name part (even in Europe some countries use Family Name / Given Name order). Use the term "Given Name" instead.
  • Identifiers should not be called LastName - This rule catches fields and properties that are called LastName (or a variation of LastName). The term "last name" is a western naming convention and it does not accurately identify a name part. Use the term "Family Name" instead.

In total the downloadable source code now contains 25 FxCop globalization and localization rules.

Technorati Tags: ,,,

Currently rated 3.2 by 40 people

  • Currently 3.15/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Monday, April 22, 2013 at 6:04 PM
Tags:
Categories: Internationalization | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

What's New In The .NET Internationalization Source Code

I wrote a book called .NET Internationalization back in 2006. There is a whole bunch of source code (examples and reusable library code) that accompanies the book that is available for download (you don't need to buy the book to get the source code). I have been keeping the source code up to date with various changes since it was first released and I have just uploaded the most recent version. This blog post describes what's new.

Custom Cultures

I added an example of a new custom culture for Spanish (Chile) Unidad de Fomento, es-CL-CLF, to support the UDF currency in Chile.

Resource Code Generators

I added 3 new code generators for Visual Studio:-

  • JavaScriptResourceCodeGenerator - Creates .js files (JavaScript object literals) from .resx files
  • JavaScriptAddParentsResourceCodeGenerator - Creates .js files (JavaScript object literals) from .resx files, adds all parents except invariant
  • JavaScriptAddAllParentsResourceCodeGenerator - Creates .js files (JavaScript object literals) from .resx files, adds all parents including invariant

Machine Translation

The PseudoTranslator has a new Boolean property, ExcludeMarkup (default is true), where characters that are markup tags (e.g. "<strong>") are not pseudo translated.

The GoogleTranslator is now deprecated because the Google v1 translation API was deprecated by Google in December 2010.

I added Google2Translator for the Google v2 translation API. This is a paid service. See http://code.google.com/apis/language/translate/v2/getting_started.html for details.

Resource Administrator

You can now specify a value for PseudoTranslationCultureInfoName in the App.Config which allows you to change the name of the culture used for pseudo translation.

The GoogleTranslator is no longer used.

The Google2Translator is used if a value for "Google2TranslatorApplicationKey" is set in the App.config file.

If either the MicrosoftTranslator or the Google2Translator are used the remaining translators are disabled (because the Microsoft and Google translators are very reliable).

I fixed a bug where comments were not being preserved in neutral and specific resources when automatic translation was on.

The FileBasedResourcesGovernor now has a new property, Extension, which is the file extension of the files (e.g. ".resx").

ResourceGovernor.ReintegrateResourceSet has various bugs fixed.

Globalization FxCop Rules

I added 2 new rules:-

  • DoNotConcatenateLocalizableStrings - identifies code where resource strings are concatenated (use string parameters instead)
  • ResourceEntryIsNotUsed - identifies properties in Strongly Typed Resource Classes that are not used

Note that the ResourceEntryIsNotUsed class requires the Strongly Typed Resource

Class code to be manually modified so that the CompilerGeneratedAttribute is commented out.

The Translator
I added two new utilities:-

  • ReintegrateResources - a command line utility that intelligently reintegrates resources being sent back from the translator
  • ResourcePackager - a command line utility that ZIPs and unZIPs .resx files being sent to/from the translator

Enjoy.

Technorati Tags: ,

Currently rated 3.1 by 9 people

  • Currently 3.111111/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Monday, March 12, 2012 at 4:19 PM
Tags:
Categories: .NET Internationalization Book | Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

PublicResourceCodeGenerator now works with Visual Studio 2010

I have updated the PublicResourceCodeGenerator (and all of the other code generators) so that it installs and works with Visual Studio 2010 (as well as Visual Studio 2008). The PublicResourceCodeGenerator is used to create Strongly Typed Resource Classes with a public class and a public constructor so that resx files can be used with Silverlight (you can read all about these code generators here). You can download an MSI/EXE and/or the source code (for Visual Studio 2010, 2008 and 2005) here.

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Wednesday, September 01, 2010 at 6:30 PM
Tags:
Categories: Internationalization | .NET Internationalization Book | Silverlight
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

.NET Internationalization Visual Studio 2010 Source Code Available

The source code for my .NET Internationalization book is now available for Visual Studio 2010. Versions are still available for Visual Studio 2008, Visual Studio 2005 and Visual Studio 2003 but the version for Visual Studio 2010 is the only one that I will be updating from here on (until the next release of Visual Studio).

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Wednesday, September 01, 2010 at 6:11 PM
Tags:
Categories: .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Automatically Translating resx Files Using Microsoft Translator

Back in April 2009 I wrote about the Microsoft Translator (aka the Bing Translator), the various APIs that it exposes and in particular the REST API that it exposes to allow the automation of translation. At the time I also added a Microsoft Translator class to the list of translator classes used in the tool suite for my book, .NET Internationalization. In this post I join the dots and show you how to make use of these classes and automatically translate your resx files to another language.

  1. Get your Microsoft Translator "app id" from http://search.live.com/developers/appids.aspx.
  2. Download the free source code for the book from here.
  3. Extract the source code to a folder of your choice.
  4. Open ResourceAdministration\ResAdmin\App.Config and change the "value" of the "MicrosoftTranslatorApplicationId" key to the "app id" that you were given for the Microsoft Translator.
  5. Build the source code by opening a Visual Studio command prompt in the folder that you extracted the source code to and running "msbuild BuildAll.proj". If FxCop is not installed on your machine there will be build errors but these are not related to the translation tools and you can ignore these.
  6. Connect to the internet (the Microsoft Translator needs an internet connection).
  7. In ResourceAdministration\ResAdmin\bin\debug you will find ResAdmin.exe. This is the Resource Administrator which is a developer tool for managing resources. Run ResAdmin.exe.
  8. You will see the following dialog. In the "Source of Resources" enter the base directory containing your resx files. In the "Invariant language" enter the language code that the original resources are in (e.g. "en" for "English"). Click OK. ResAdmin Resources Source
  9. Next you will see the main form. You need to tell the Resource Administrator what language(s) to translate to. Select Tools | Languages and enter all of the languages to translate to (you should probably de-select Albanian at this point). Click OK. ResAdminMainForm
  10. You will be asked if you want to automatically add the necessary resx files for the new language(s).ResAdminAddLanguages Click Yes. At this point if "Automatic Translation" is on (see the status bar) the text in the resx files will be translated.
  11. The Resource Administrator tool uses a collection of machine translators to translate text where it falls back to other suitable translators if one fails. You can configure which translators are included in the list by selecting Tools | Translators.

Note that the Resource Administrator utility is not hard wired to use solely resx files. You can use the same utility with other sources of resources (including a database) by selecting Tools | Resources Source.

For more information on how to use the Resource Administrator see the .NET Internationalization book.

Currently rated 3.8 by 4 people

  • Currently 3.75/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Tuesday, September 29, 2009 at 6:14 PM
Tags:
Categories: Internationalization | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Localizing ASP.NET MVC

I've noticed that there has been a bit of confusion regarding localization in ASP.NET MVC so I thought I'd write up the solution to try to clear things up. ASP.NET has quite a reasonable localization model as by default it uses the ResourceManager and .resx files all wrapped up fairly neatly using the Generate Local Resources menu option in Visual Studio. Whereas there are some gaps the model is reasonably sound. Where this solution has learnt from previous localization models is in the resource provider model where you can replace the ResourceManager/.resx solution with an alternative resource implementation of your own design such as a WCF resource service. If you are unfamiliar with ASP.NET localization you should get up to speed with it before looking at localization in ASP.NET MVC.


ASP.NET MVC utilizes most of the ASP.NET localization model so the basics of using a resource provider and the default provider using the ResourceManager and .resx files is no different. The difference is that ASP.NET server side controls are either not possible without the the ASP.NET page model or difficult and are mostly unwanted in the 'pure' world of MVC. This difference is important in localization terms because Visual Studio's Generate Local Resources menu option expects to find ASP.NET server side controls. By default, the Generate Local Resources menu option creates a new .resx file in the App_LocalResources folder corresponding to the .aspx/.ascx page or control (so App_LocalResources\Default.aspx.resx is created to correspond to Default.aspx). Generate Local Resources iterates through every control looking for properties that are decorated with the LocalizableAttribute (set to true). Each control with any such property is modified to have a meta:resourcekey tag and the value of the property together with a key is added to the corresponding .resx file. The property is then said to be implicitly bound to the resource.


There are two problems with localizing MVC: there are no HTML properties that are decorated with the LocalizableAttribute and the HTML controls are not server side. The first issue means that Generate Local Resources does not find any properties to localize so the .resx file is not populated with resource entries and the HTML controls are not marked with a meta:resourcekey tag. What is important to note here, though, is that this is simply the nature of the Generate Local Resource menu option. The model still works so if you manually add a meta:resourcekey and you manually add the corresponding entry in the resx file (and the HTML control is server side) then localization will occur just as it does in an ASP.NET application. The second problem is that HTML controls are not server side by default. Localization occurs on the server and there's just no getting round this if you want to make use of all of the ASP.NET localization infrastructure. The solution is to change the HTML controls to be server side.

So here's an example with this humble HTML button control:-

<input type="button" value="Press Me"/>

To localize it for ASP.NET MVC first run Tools | Generate Local Resources. This will create the necessary .resx file and make minor modifications to the page (but not to the HTML control itself). To localize the control you need to add a runat tag and a meta:resourcekey tag:-

<input type="button" value="Press Me" runat="server" meta:resourcekey="PressMeButtonResources"/>

Then open up the associated .resx file (in the App_LocalResources folder) and add an entry with the key "PressMeButtonResources.value" and the value "Press Me (From resx)". When you run the site you will see that the button shows the value from the .resx file and not the value from the .aspx file. The button is now localizable.

 

Of course, all of the rest of the UI including the static text in the HTML, text in JavaScript, text in the code behind, text in libraries and text and resources everywhere still need to be localized but the solutions to localizing all of this text are the same for ASP.NET MVC as they are for ASP.NET so I'm not going to cover them here.

 

What is needed for MVC is an equivalent to Generate Local Resources that performs the same task except that instead of identifying properties as localizable based on having the LocalizableAttribute it uses some other means such as having a dictionary of 'known localizable properties'. For example the value property of an HTML INPUT control with type="Button" is always localizable and it does not need to be marked with a
LocalizableAttribute for this to be true.

 

By the way, if you're not using ASP.NET MVC and your regular ASP.NET application has lots of HTML and you're wondering about how to localize that then you have many more (better) options open to you. The main one of these is to convert your HTML controls to equivalent ASP.NET server side controls. If this is your plan then you should take a look at the I18NRefactorings (an add-in for the free DXCore) in the download at http://www.dotneti18n.com/Downloads.aspx that will help automate this process. I will blog about this separately at a future date.

Currently rated 3.6 by 11 people

  • Currently 3.636364/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Friday, May 15, 2009 at 9:44 PM
Tags:
Categories: Internationalization | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (9) | Post RSSRSS comment feed

Machine Translation Using The Microsoft Translator

When Live was first released it's true to say that I was disappointed because all other competitive search engines had online translation tools and these were missing from Live. I think it is fair to say that Microsoft has delivered now. The basic online translator, Microsoft Translator, has been available for some time now but at MIX 09 Microsoft announced a widget and various APIs and tools that build on the translation engine and open up machine translation to a much broader range of applications. This post describes what's available and how you can get started.

Microsoft Translator provides the basic online interactive translation facility like Google, Alta Vista and everyone else. Translation is from English to 13 languages and vice versa (there are no language pairs that are not either to or from English). The Microsoft Translator site also accepts URL parameters that allow you to tell it to automatically translate a site:-

http://www.microsofttranslator.com/bv.aspx?lp=en_fr&lo=TP&a=www.guysmithferrier.com

The "lp" parameter is the language pair ("en_fr" specifies that the translation is from English to French), the "lo" parameter is the page layout of the translation result ("TP" specifies that the page should be shown as translated with the original language appearing as tooltips) and the "a" parameter is the URL to translate. This facility is very useful for being able to send links of translated pages.

The first major announcement at MIX was the Translator Widget. The translator widget is a snippet of HTML and JavaScript that you add to your page that provides translation facilities for your page. You can try it out on this site (see the blue "Microsoft Translator" box on the top left hand side of this page). You can also see it working on http://www.dotneti18n.com. To add one of these to your site you need to request a widget code from http://www.microsofttranslator.com/widget (you can't copy the HTML/JavaScript from a site that already has the widget because the code only works for the site it was generated for).

The Translator Widget is certainly a great starting point but you can provide finer control over the translation process using the Translator AJAX API. This allows you to call into the translation API to specify what parts of the page should be translated and how. To use the AJAX API you need to request a (different) code from http://www.microsofttranslator.com/dev/ajax.

The area that is of greatest interest to me, however, is the HTTP REST API. This provides programmatic access to the Microsoft Translator API from any code that can make HTTP calls. As such it is perfect for utilities like the Resource Administrator on http://www.dotneti18n.com that translates resx files. Again you need to request an "app id" to use this API (this is a different code from the widget code and the AJAX API code) and you can request one from http://search.live.com/developers/appids.aspx. Armed with your AppId you can use an HttpWebRequest to execute POST requests like this:-

http://api.microsofttranslator.com/V1/Http.svc/Translate?appId=yourAppId&from=en&to=es

where the content is the text that you want to translate.

The following resources will help you get up to speed on all of these:-

As always you should read the terms of use (the terms of use for the REST API are here) but in general they say that these are available for non-commercial use. Commercial licences are available by contacting Microsoft.

In addition Microsoft has a growing collection of implementations of this technology:-

Others have said that 2009 will see the coming of age of machine translation. These advances certainly move that goal further forwards.

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Saturday, April 18, 2009 at 1:56 PM
Tags:
Categories: Internationalization | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (9) | Post RSSRSS comment feed

Podcast with Craig Murphy and Andy Westgarth

Craig Murphy and Andy Westgarth interviewed me at the "Heroes Happen Here" Visual Studio 2008 Launch last March and Craig posted the podcast on his site here as part of his Twelve Podcasts Of Christmas. It's about 15 minutes and I talk about Visual Studio 2008, extension methods, internationalization, community and The .NET Developer Network.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Tuesday, January 13, 2009 at 3:48 PM
Tags:
Categories: Internationalization | Miscellaneous - Other | Visual Studio | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

PublicResourceCodeGenerator Fixed

A while ago I blogged about the solution to creating strongly typed resource classes for Silverlight so that the classes had a public constructor to allow them to be loaded by the Silverlight XAML loader. Apologies to the people who downloaded the PublicResourceCodeGenerator and discovered that it worked in Visual Studio 2005 but not in Visual Studio 2008. It is fixed now for Visual Studio 2008. You can download it here.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Monday, November 10, 2008 at 10:54 AM
Tags:
Categories: Silverlight | Internationalization | .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

.NET Internationalization: Longest Review Ever!

On the first annversary of the release of .NET Internationalization Craig Murphy has finished his new epic: a review of .NET Internationalization. Craig wins the award for "Longest Review Ever" and you’d have to reprint the whole book to get a longer review than this. Never before in the field of human reviews has so much been written about a book by so few. Thanks, Craig, a supreme effort. And thanks also to your family for letting you take the book on holiday too.

And he gave it 4.5 out of 5 so I’m still chuffed.

Technorati Tags: .NET Internationalization, Craig Murphy, Internationalization

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Monday, August 13, 2007 at 3:20 PM
Categories: .NET Internationalization Book
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed