Click here to Skip to main content
12,405,653 members (60,332 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

189.2K views
1.7K downloads
94 bookmarked
Posted

Declarative ASP.NET globalization

, 16 Apr 2004 CPOL
An article on how to implement globalization support for ASP.NET pages through attributes and reflection
GlobalizationModule
bin
Debug
GlobalizationModule.pdb
Release
GlobalizationModule.csproj.user
httppipeline.gif
obj
Debug
GlobalizationModule.pdb
Release
MyWebApp
bin
fi-FI
fr-FR
GlobalizationModule.pdb
MyWebApp.pdb
sv-SE
Controls
flags
Finland.gif
France.gif
Sweden.gif
UnitedKingdom.gif
Global.asax
MyWebApp.csproj.webinfo
MyWebApp.vsdisco
using System;
using System.Resources;
using System.Reflection;
using System.Globalization;
using GlobalizationModule;

namespace MyWebApp
{
    /// <summary>
    /// Special LocalizeAttribute for localizing both 
    /// Text and ToolTip fields of a label.
    /// </summary>
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
    public class TooltipLocalizerAttribute : LocalizeAttribute
    {
        public TooltipLocalizerAttribute()
        {}

        private string tooltipResourceName_;
        /// <summary>
        /// Name of the tooltip resource.
        /// </summary>
        public string ToolTipResourceName
        {
            get { return tooltipResourceName_; }
            set { tooltipResourceName_ = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void LocalizeObject(object target, System.Web.UI.Page page)
        {
            // User's page class is superclass of the ASP.NET page class
            Type userPageClass = page.GetType().BaseType;
            // The user's assembly is the one that holds his/her page class
            Assembly targetAssembly = userPageClass.Assembly;

            CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)target;
            
            // Localize label's Text property
            label.Text = (string)base.LoadResource(
                    this.ResourceName, culture, page, targetAssembly);
 
            // Localize label's Tooltip property
            label.ToolTip = (string)base.LoadResource(
                this.ToolTipResourceName, culture, page, targetAssembly);
        }
    }    
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sami Vaaraniemi
Web Developer
Finland Finland
Sami Vaaraniemi has been working as a software developer since 1990, primarily on Microsoft technologies. After 12 years of Win32 API and C++ he switched to .NET. He currently works as an independent consultant and can be contacted through his website at www.capehill.net.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 17 Apr 2004
Article Copyright 2003 by Sami Vaaraniemi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid