Click here to Skip to main content
15,895,142 members
Articles / Web Development / ASP.NET

.NET String Resources

Rate me:
Please Sign up or sign in to vote.
4.85/5 (37 votes)
19 Apr 2012CPOL7 min read 143.2K   2.2K   143  
Concepts and patterns for the handling of strings in multilingual applications.
// -- FILE ------------------------------------------------------------------
// name       : LocalizationDesigner.Web.cs
// project    : Itenso String Resources
// created    : Jani Giannoudis - 2012.03.21
// language   : c#
// environment: .NET 4.0
// copyright  : (c) 2004-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Web.UI.Design;

namespace Itenso.Community.StringResources.ResStrings
{

	// ------------------------------------------------------------------------
	public class LocalizationDesigner : ControlDesigner
	{

		// ----------------------------------------------------------------------
		public override string GetDesignTimeHtml()
		{
			Localization localization = Component as Localization;
			if ( localization == null || string.IsNullOrEmpty( localization.SourceValue ) )
			{
				return string.Format( sourceValueFormat, undefinedLocalization );
			}


			return string.Format( sourceValueFormat, localization.SourceValue );
		} // GetDesignTimeHtml

		// ----------------------------------------------------------------------
		public override void Initialize( IComponent component )
		{
			// throw an exception if the designer is attached to a control for which it is not intended
			if ( !( component is Localization ) )
			{
				throw new InvalidOperationException(
					GetType().FullName + " only supports controls derived from Localization" );
			}
			base.Initialize( component );
		} // Initialize

		// ----------------------------------------------------------------------
		// members
		private const string undefinedLocalization = "Loc";
		private const string sourceValueFormat = "<font size=\"2\" color=\"#FF9933\">&nbsp;[{0}]</font>";


	} // class LocalizationDesigner

} // namespace Itenso.Community.StringResources.ResStrings
// -- EOF -------------------------------------------------------------------

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)


Written By
Software Developer (Senior)
Switzerland Switzerland
👨 Senior .NET Software Engineer

🚀 My Open Source Projects
- Time Period Library 👉 GitHub
- Payroll Engine 👉 GitHub

Feedback and contributions are welcome.



Comments and Discussions