Click here to Skip to main content
15,886,026 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 142.1K   2.2K   143  
Concepts and patterns for the handling of strings in multilingual applications.
// -- FILE ------------------------------------------------------------------
// name       : App.xaml.cs
// project    : Itenso String Resources
// created    : Jani Giannoudis - 2011.09.09
// language   : C# 4.0
// environment: .NET 2.0
// copyright  : (c) 2011 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace Itenso.Community.StringResources.SampleApplication
{

	// ------------------------------------------------------------------------
	public partial class App
	{

		// ----------------------------------------------------------------------
		/// <summary>
		/// Constructor for the Application object.
		/// </summary>
		public App()
		{
			// Global handler for uncaught exceptions. 
			UnhandledException += Application_UnhandledException;

			// Show graphics profiling information while debugging.
			if ( System.Diagnostics.Debugger.IsAttached )
			{
				// Display the current frame rate counters.
				Current.Host.Settings.EnableFrameRateCounter = true;

				// Show the areas of the app that are being redrawn in each frame.
				//Application.Current.Host.Settings.EnableRedrawRegions = true;

				// Enable non-production analysis visualization mode, 
				// which shows areas of a page that are being GPU accelerated with a colored overlay.
				//Application.Current.Host.Settings.EnableCacheVisualization = true;
			}

			SetupCulture();

			// Standard Silverlight initialization
			InitializeComponent();

			// Phone-specific initialization
			InitializePhoneApplication();
		} // App

		// ----------------------------------------------------------------------
		private static void SetupCulture()
		{
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new  System.Globalization.CultureInfo( "ar-DZ" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "ca-ES" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "zh-HK" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "cs-CZ" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "da-DK" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "de-DE" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "de-CH" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "el-GR" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "en-US" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "es-ES" );
			//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "fi-FI" );
		} // SetupCulture

		// ----------------------------------------------------------------------
		/// <summary>
		/// Provides easy access to the root frame of the Phone Application.
		/// </summary>
		/// <returns>The root frame of the Phone Application.</returns>
		public PhoneApplicationFrame RootFrame { get; private set; }

		// ----------------------------------------------------------------------
		// Code to execute when the application is launching (eg, from Start)
		// This code will not execute when the application is reactivated
		public void Application_Launching( object sender, LaunchingEventArgs e )
		{
		} // Application_Launching

		// ----------------------------------------------------------------------
		// Code to execute when the application is activated (brought to foreground)
		// This code will not execute when the application is first launched
		public void Application_Activated( object sender, ActivatedEventArgs e )
		{
		} // Application_Activated

		// ----------------------------------------------------------------------
		// Code to execute when the application is deactivated (sent to background)
		// This code will not execute when the application is closing
		public void Application_Deactivated( object sender, DeactivatedEventArgs e )
		{
		} // Application_Deactivated

		// ----------------------------------------------------------------------
		// Code to execute when the application is closing (eg, user hit Back)
		// This code will not execute when the application is deactivated
		public void Application_Closing( object sender, ClosingEventArgs e )
		{
		} // Application_Closing

		// ----------------------------------------------------------------------
		// Code to execute if a navigation fails
		private static void RootFrame_NavigationFailed( object sender, NavigationFailedEventArgs e )
		{
			if ( System.Diagnostics.Debugger.IsAttached )
			{
				// A navigation has failed; break into the debugger
				System.Diagnostics.Debugger.Break();
			}
		} // RootFrame_NavigationFailed

		// ----------------------------------------------------------------------
		// Code to execute on Unhandled Exceptions
// ReSharper disable MemberCanBeMadeStatic.Local
		private void Application_UnhandledException( object sender, ApplicationUnhandledExceptionEventArgs e )
// ReSharper restore MemberCanBeMadeStatic.Local
		{
			if ( System.Diagnostics.Debugger.IsAttached )
			{
				// An unhandled exception has occurred; break into the debugger
				System.Diagnostics.Debugger.Break();
			}
		} // Application_UnhandledException

		#region Phone application initialization

		// ----------------------------------------------------------------------
		// Avoid double-initialization
		private bool phoneApplicationInitialized;

		// ----------------------------------------------------------------------
		// Do not add any additional code to this method
		private void InitializePhoneApplication()
		{
			if ( phoneApplicationInitialized )
				return;

			// Create the frame but don't set it as RootVisual yet; this allows the splash
			// screen to remain active until the application is ready to render.
			RootFrame = new PhoneApplicationFrame();
			RootFrame.Navigated += CompleteInitializePhoneApplication;

			// Handle navigation failures
			RootFrame.NavigationFailed += RootFrame_NavigationFailed;

			// Ensure we don't initialize again
			phoneApplicationInitialized = true;
		} // InitializePhoneApplication

		// ----------------------------------------------------------------------
		// Do not add any additional code to this method
		private void CompleteInitializePhoneApplication( object sender, NavigationEventArgs e )
		{
			// Set the root visual to allow the application to render
// ReSharper disable RedundantCheckBeforeAssignment
			if ( RootVisual != RootFrame )
// ReSharper restore RedundantCheckBeforeAssignment
				RootVisual = RootFrame;

			// Remove this handler since it is no longer needed
			RootFrame.Navigated -= CompleteInitializePhoneApplication;
		} // CompleteInitializePhoneApplication

		#endregion

	} // class App

} // namespace Itenso.Community.StringResources.SampleApplication
// -- 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