Use Localization Manager Helper class to apply the localizable properties
Helper class to implement the localizable properties.
Create a Resource file in the project. You can use the Resource Editor to edit the contents of the resource file.
The resource file helps you to embed strings, images, e.t.c. in one common location and you need to write an interface to retrieve them.
This makes it easier to maintain the images in the project structure.
Add necessary strings with Name and Value.
Add Images (you can even drag and drop)
And then use the Localization class shown below to retrieve them.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace Infrastructure.Interface.Localization
{
/// <summary>
/// Helper class provided suport for localization.
/// </summary>
public sealed class LocalizationManager
{
/// <summary>
/// Get a value from resource file for key.
/// </summary>
/// <param name="key">Key</param>
/// <returns>Resource value</returns>
public static string GetValue(string key)
{
if (string.IsNullOrEmpty(key))
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Value_NullOrEmpty);
string value = Properties.Resources.ResourceManager.GetString(key);
if (string.IsNullOrEmpty(value))
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Value_NotFound + key);
return value;
}
/// <summary>
/// Get an image from resource file for key.
/// </summary>
/// <param name="imageName">Image name key</param>
/// <returns>Resource Image</returns>
public static Bitmap GetImage(string imageName)
{
if (string.IsNullOrEmpty(imageName))
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Image_NullOrEmpty);
object image = Properties.Resources.ResourceManager.GetObject(imageName);
if (image == null)
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Image_NotFound + imageName);
return (Bitmap)image;
}
/// <summary>
/// Get an icon from resource file for key.
/// </summary>
/// <param name="iconName">Icon name key</param>
/// <returns>Resource icon</returns>
public static Icon GetIcon(string iconName)
{
if (string.IsNullOrEmpty(iconName))
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Icon_NullOrEmpty);
object image = Properties.Resources.ResourceManager.GetObject(iconName);
if (image == null)
throw new
InfrastructureInternalException(Properties.Resources.Localization_Message_Icon_NotFound + iconName);
return (Icon)image;
}
}
}
How to use it:
----------------
//string
CountryLabel.Text = LocalizationManager.GetValue(ResourceKeyNames.COUNTRYCONTROL_LABEL_COUNTRY);
//image
ErrorBox.Image = LocalizationManager.GetImage(ResourceKeyNames.IMAGE_ERROR);
//Icon
this.Icon = LocalizationManager.GetIcon(ResourceKeyNames.ICON_APP);
By [)ia6l0 iii Popularity (1353 Views)