C# Class System.Globalization.I18NComplete

The I18NComplete class
Mostra file Open project: adaptabi/i18N-Complete Class Usage Examples

Public Properties

Property Type Description
BasePath string
DefaultWorkingLanguage string
DefaultWorkingLanguageLCID int
HideAllLocalizedText bool
Localizations Localization>.Dictionary

Public Methods

Method Description
GetBestLanguage ( HttpRequest request, string fallback = null ) : string

Spins through the language preferences in the supplied HttpRequest, returning the first complete or partial match on a loaded language.

GetMessage ( string msgID, string languageCode = null, int lcid = null ) : Message

Gets a translated message version of the supplied text message.

LCID ( string cultureName ) : int

Private Methods

Method Description
GetText ( string msgID, string languageCode = null, int lcid = null, bool plural = false ) : string

Gets a translated version of the supplied text message.

I18NComplete ( ) : System.Collections.Generic

Static constructor of I18NComplete

OnGetting_ ( string defaultResult, CultureInfo culture, string text, object arguments ) : string

Throws the Getting_ global event

@Alias _ and GetString

Translates the given text applying string.Format(text, arguments) to the current culture language.

The text and argument values will be HTML Encoded when used in ASP.NET MVC

OnGetting__ ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string html, object arguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting__ global event

@Alias GetHtml and FormatHtml

Translates the given html applying string.Format(html, arguments.Select(a => HttpUtility.HtmlEncode(a))) to the current culture language.

The html will be kept as it is, while arguments will be automatically HTML Encoded

OnGetting___ ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string html, string>.Func escapeArgumentFunc, object htmlArguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting___ global event

@Alias GetRaw and FormatRaw

Translates the given html applying string.Format(html, arguments.Select(a => escapeArgumentFunc(a))) to the current culture language.

For each argument the escape func will be called before applying the format

OnGetting___ ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string html, object htmlArguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting___ global event

@Alias GetRaw and FormatRaw

Translates the given html applying string.Format(html, htmlArguments) to the current culture language.

Warning! Neither the html nor the htmlArguments will be encoded whatsoever

OnGetting___q ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string html ) : System.Web.Mvc.MvcHtmlString

Throws the Getting___q global event

Quotes the text as the xgettext cannot correctly extract values from attributes

Translates the given html applying '"'+HttpUtility.HtmlAttributeEncode(string.Format(html, htmlArguments))+'"' to the current culture language.

Warning! Neither the html nor the htmlArguments will be encoded whatsoever

Usage: <div title=@___q("< class='tip'>There are {0} {1} in cart.</div>", 3, "<b>Items</b>")>... -- Note the missing quotes!

OnGetting___s ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string singularHTML, string pluralHTML, int count, string>.Func escapeArgumentFunc, object htmlArguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting___s global event

@Alias GetPluralRaw and FormatRawPlural

Translates the given singular or plural text/html applying string.Format(count == 1 ? singular : plural, arguments.Select(a => escapeArgumentFunc(a))) to the current culture language.

For each argument the escape func will be called before applying the format

OnGetting___s ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string singularHTML, string pluralHTML, int count, object htmlArguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting___s global event

@Alias GetPluralRaw and FormatRawPlural

Translates the given singular or plural HTML applying string.Format(html, arguments) to the current culture language.

Warning! Neither the html nor the htmlArguments will be encoded whatsoever

OnGetting__q ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string html ) : System.Web.Mvc.MvcHtmlString

Throws the Getting__q global event

Quotes the text as the xgettext cannot correctly extract values from attributes

Translates the given html applying '"'+HttpUtility.HtmlAttributeEncode(string.Format(html, arguments.Select(a => HttpUtility.HtmlEncode(a))))+'"' to the current culture language.

The html will be kept as it is, while arguments will be automatically HTML Encoded

Usage: <input type="submit" value=@__q("Save") /> -- Note the missing quotes!

OnGetting__s ( System.Web.Mvc.MvcHtmlString defaultResult, CultureInfo culture, string singularHTML, string pluralHTML, int count, object arguments ) : System.Web.Mvc.MvcHtmlString

Throws the Getting__s global event

@Alias GetPluralHtml and FormatHtmlPlural

Translates the given singular or plural HTML applying string.Format(html, arguments.Select(a => HttpUtility.HtmlEncode(a))) to the current culture language.

The singular/plural HTML will be kept as it is, while arguments will be automatically HTML Encoded

OnGetting_s ( string defaultResult, CultureInfo culture, string singular, string plural, int count ) : string

Throws the Getting_s global event

@Alias GetPluralString and FormatPlural

Translates the given singular or plural text applying string.Format(text, arguments) to the current culture language.

The singular/plural text and argument values will be HTML Encoded when used in ASP.NET MVC

Method Details

GetBestLanguage() public static method

Spins through the language preferences in the supplied HttpRequest, returning the first complete or partial match on a loaded language.
public static GetBestLanguage ( HttpRequest request, string fallback = null ) : string
request System.Web.HttpRequest
fallback string
return string

GetMessage() public static method

Gets a translated message version of the supplied text message.
public static GetMessage ( string msgID, string languageCode = null, int lcid = null ) : Message
msgID string Text to be translated
languageCode string Language to translate into
lcid int Specify the Culture LCID for faster access if you know it
return Message

LCID() public static method

public static LCID ( string cultureName ) : int
cultureName string
return int

Property Details

BasePath public_oe static_oe property

This is the base path under which localizations will be stored.
public static string BasePath
return string

DefaultWorkingLanguage public_oe static_oe property

The language that MsgIDs are given in (generally the language the project is being developed in).
public static string DefaultWorkingLanguage
return string

DefaultWorkingLanguageLCID public_oe static_oe property

The default culture LCID
public static int DefaultWorkingLanguageLCID
return int

HideAllLocalizedText public_oe static_oe property

FOR TESTING ONLY! If true, all calls to GetText will return an empty string. this is useful when searching for any strings that might not be flagged for localization.
public static bool HideAllLocalizedText
return bool

Localizations public_oe static_oe property

The cached localization
public static Dictionary Localizations
return Localization>.Dictionary