(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Internationalization/Globalization in Silverlight - Part 6 - Naming

(2 votes)
Ross Wozniak
>
Ross Wozniak
Joined Feb 19, 2010
Articles:   9
Comments:   0
More Articles
1 comments   /   posted on Feb 26, 2010
Tags:   internationalization , globalization , resx , naming-conventions , ross-wozniak

This article is compatible with the latest version of Silverlight.

As mentioned in the What is a .resx file and how should I us it? post, when you create a .resx file a corresponding .cs (or .vb) file/class is code-generated, and this class gives you strongly-typed access to resources. This can be used in declarative databinding or in code. One important thing to understand however is that if you create a .resx file called MyStrings.resx, behind the scenes a class is created called MyStrings. So make sure when you name your .resx files that you don’t use a name that you have used for another class in your project!

Naming conventions for .resx keys

From what I’ve read, Microsoft’s recommendation for .resx keys is Pascal-case. What this means is that each word is capitalized. An example of that would be LabelName. However, if you create a Silverlight Business Application in VisualStudio you will find that they use underscores in their names. I tend to like this convention. Some examples would be:

Command_Save

Label_Name

Message_NoRecordsFound

ErrorMessage_GenericError

Common prefixes

I haven’t come across any set rules around how .resx keys should be named, but what I tend to go with is a set of common prefixes, like the ones above; Command_, Label_, Message_, ErrorMessage_, etc. I like using prefixes so that when the keys in your .resx file are sorted alphabetically by name (you can sort by other columns if you’d like), all of the Commands will be grouped together, etc.

What is a Command?

If you’re not familiar with this term you may be wondering what I’m talking about. Command basically refers to any clickable element that invokes an action. For example, a button, a menu item, a context menu item, etc.

So why use the term command? Well, suppose you have a user interface like the one I showed in the Should I internationalize? post:

 

In this UI (Microsoft Outlook) the user can click New in either the File menu or the toolbar. Both of these will do the same thing. In fact, you may even have buttons and context menu items somewhere in your UI that say ‘New’. Rather than have .resx keys like Button_New, MenuItem_New, etc., we can wrap all these up in one common .resx key, Command_New.

In fact, if you aren’t using it already, you should be taking advantage of the ICommand interface in Silverlight 4. Its purpose is to have a single action that can be invoked from multiple places…menus, toolbars, buttons, etc.


Subscribe

Comments

  • -_-

    RE: Internationalization/Globalization in Silverlight - Part 6 - Naming


    posted by Aicha on Nov 10, 2010 11:09
    Thaks for this post, but the building of the source code show this error message "The attachable property 'ResponseButton' was not found in type 'RadWindow" ? i can't resolve it :(

Add Comment

Login to comment:
  *      *       
Login with Facebook

From this series