コード例 #1
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Returns any translation for the passed individual message.
 /// </summary>
 /// <remarks>
 /// This this the main entry point into i18n library for translating strings.
 /// Selection of acceptable user languages is determined per-request and that
 /// is used to resolve the msgid against any existing localized versions of that string.
 /// Should no translation exist, the msgid string is returned.
 /// </remarks>
 /// <param name="context">Describes the current request.</param>
 /// <param name="msgid">Specifies the individual message to be translated (the first part inside of a nugget). E.g. if the nugget is [[[Sign in]] then this param is "Sign in".</param>
 /// <param name="msgcomment">Specifies the optional message comment value of the subject resource, or null/empty.</param>
 /// <param name="allowLookupWithHtmlDecodedMsgId">
 /// Controls whether a lookup will be attempted with HtmlDecoded-msgid should the first lookup with raw msgid fail.
 /// Defaults to true.
 /// </param>
 /// <returns>Localized string, or msgid if no translation exists.</returns>
 public static string GetText(
     this System.Web.HttpContext context,
     string msgid,
     string msgcomment,
     bool allowLookupWithHtmlDecodedMsgId = true)
 {
     return(context.GetHttpContextBase().GetText(
                msgid,
                msgcomment,
                allowLookupWithHtmlDecodedMsgId));
 }
コード例 #2
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Returns the translation of the passed string entity which may contain zero or more fully-formed nugget.
 /// </summary>
 /// <param name="context">Describes the current request.</param>
 /// <param name="entity">String containing zero or more fully-formed nuggets which are to be translated according to the language selection of the current request.</param>
 /// <returns>Localized (translated) entity.</returns>
 public static string ParseAndTranslate(this System.Web.HttpContext context, string entity)
 {
     return(context.GetHttpContextBase().ParseAndTranslate(entity));
 }
コード例 #3
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Returns the language for the current request inferred from the request context:
 /// that is, attributes of the request other that the URL.
 /// </summary>
 /// <remarks>
 /// The language is infered from the following attributes of the request,
 /// in order of preference:<br/>
 ///     i18n.langtag cookie<br/>
 ///     Accept-Language header<br/>
 ///     fall back to i18n.LocalizedApplication.Current.DefaultLanguage<br/>
 /// Additionally, each language is matched by the language matching algorithm
 /// against the set of application languages available.
 /// </remarks>
 /// <param name="context">Context of the current request.</param>
 /// <returns>
 /// Returns language tag describing the inferred language.
 /// </returns>
 /// <exception cref="System.InvalidOperationException">
 /// Expected GetRequestUserLanguages to fall back to default language.
 /// </exception>
 public static LanguageTag GetInferredLanguage(this System.Web.HttpContext context)
 {
     return(context.GetHttpContextBase().GetInferredLanguage());
 }
コード例 #4
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Runs the Language Matching Algorithm for the UserLanguages of the current request against
 /// the specified array of AppLanguages, returning the AppLanguage determined to be the best match.
 /// </summary>
 /// <param name="context">Context of the current request.</param>
 /// <param name="AppLanguages">
 /// The list of languages in which an arbitrary resource is available.
 /// </param>
 /// <returns>
 /// LanguageTag instance selected from AppLanguages with the best match, or null if there is no match
 /// at all (or UserLanguages and/or AppLanguages is empty).
 /// It is possible for there to be no match at all if no language subtag in the UserLanguages tags
 /// matches the same of any of the tags in AppLanguages list.
 /// </returns>
 public static LanguageTag ChooseAppLanguage(this System.Web.HttpContext context, IEnumerable <LanguageTag> AppLanguages)
 {
     return(context.GetHttpContextBase().ChooseAppLanguage(AppLanguages));
 }
コード例 #5
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Add a Content-Language HTTP header to the response, based on any languages
 /// that have provided resources during the request.
 /// </summary>
 /// <param name="context">Context of the current request.</param>
 /// <returns>
 /// true if header added; false if no languages provided content during the request and
 /// so no header was added.
 /// </returns>
 public static bool SetContentLanguageHeader(this System.Web.HttpContext context)
 {
     return(context.GetHttpContextBase().SetContentLanguageHeader());
 }
コード例 #6
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Returns a collection of languages supported by the user-agent, in descending order
 /// of preference. The first item in the collection refers to any Principle Application Language (PAL)
 /// for the request determined by EarlyUrlLocalization (which calls SetPrincipalAppLanguageForRequest),
 /// or is null if EarlyUrlLocalization is disabled.
 /// </summary>
 /// <param name="context">Context of the current request.</param>
 /// <returns>
 /// Array of languages items sorted in order or language preference.
 /// </returns>
 /// <remarks>
 /// This method is optimised such that the collection is built only once per request.
 /// </remarks>
 /// <see>
 /// See LanguageItem.ParseHttpLanguageHeader for more details.
 /// </see>
 public static LanguageItem[] GetRequestUserLanguages(this System.Web.HttpContext context)
 {
     return(context.GetHttpContextBase().GetRequestUserLanguages());
 }
コード例 #7
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Returns any cached per-request value that identifies the Principle Application Language (PAL)
 /// with which the current request is to be processed. That is, the value of any
 /// most-recent call to SetPrincipalAppLanguageForRequest.
 /// If SetPrincipalAppLanguageForRequest has not yet been called for the request,
 /// returns the default app language.
 /// </summary>
 /// <param name="context">Context of the request.</param>
 /// <returns>
 /// The Principal AppLanguage Language for the request, or the default app language
 /// if none previously set.
 /// </returns>
 public static ILanguageTag GetPrincipalAppLanguageForRequest(this System.Web.HttpContext context)
 {
     return(context.GetHttpContextBase().GetPrincipalAppLanguageForRequest());
 }
コード例 #8
0
ファイル: HttpContextExtensions.cs プロジェクト: zingix/i18n
 /// <summary>
 /// Helper for caching a per-request value that identifies the principal language
 /// under which the current request is to be handled.
 /// </summary>
 /// <param name="context">Context of the request.</param>
 /// <param name="pal">Selected AppLanguage aka Principle Application Language (PAL).</param>
 /// <param name="updateThreadCulture">
 /// Indicates whether to also update the thread CurrentCulture/CurrentUICulture settings.
 /// </param>
 public static void SetPrincipalAppLanguageForRequest(this System.Web.HttpContext context, ILanguageTag pal, bool updateThreadCulture = true)
 {
     context.GetHttpContextBase().SetPrincipalAppLanguageForRequest(pal, updateThreadCulture);
 }
コード例 #9
0
 public static TargetingContext GetTargetingContext(this System.Web.HttpContext httpContext, IEngine engine = null)
 {
     return(GetTargetingContext(httpContext.GetHttpContextBase(), engine));
 }