Beispiel #1
0
 private bool TryGetData(UITextCategoryTag categoryTag,
                         UITextDataTag dataTag, LanguageTag language, out XElement data)
 {
     data = xmlFile
            .Element(categoryTag.ToString())
            .Element(dataTag.ToString())
            .Element(language.ToString());
     return(data != null);
 }
    public string GetStringByTag(LanguageTag languageTag)
    {
        for (int i = 0; i < languageInfos.Count; i++)
        {
            LanguageInfo languageInfo = languageInfos[i];

            if (languageInfo.LanguageTag == languageTag)
            {
                if (languageInfo.Text == "")
                {
                    Debug.LogWarning("Language Tag " + languageTag + " not found in " + Language);
                    return(languageTag.ToString() + "_" + Language);
                }
                return(languageInfo.Text);
            }
        }
        Debug.LogWarning("Language Tag " + languageTag + " not found in " + Language);
        return(languageTag.ToString() + "_" + Language);
    }
Beispiel #3
0
        private bool TryGetData(LogMessage logMessage, LanguageTag languageTag,
                                out XElement xElement)
        {
            xElement = logDataFile
                       ?.Element(logMessage.LogCategoryTag.ToString())
                       ?.Element(logMessage.LogMessageTag.ToString())
                       ?.Element(languageTag.ToString());

            return(xElement != null);
        }
Beispiel #4
0
        private bool TryGetData(MainTag mainTag, SubTag subTag,
                                ActorDataTag actorData, LanguageTag language, out XElement xElement)
        {
            if (TryGetData(mainTag, subTag, actorData, out xElement))
            {
                xElement = xElement
                           .Element(language.ToString());

                return(xElement != null);
            }
            return(false);
        }
Beispiel #5
0
        void Helper_LanguageMatching(
            string expected,
            string userLanguages)
        {
            LanguageItem [] UserLanguages = userLanguages.Split(',').Select(x => new LanguageItem(new LanguageTag(x), 1, 0)).ToArray();
            string          text;
            LanguageTag     langtag = LanguageMatching.MatchLists(
                UserLanguages,
                AppLanguages,
                null,
                null,
                out text);

            Assert.AreEqual(expected, langtag != null ? langtag.ToString() : "");
        }
        public ActionResult SetLanguage(string langtag, string returnUrl)
        {
            // If valid 'langtag' passed.
            LanguageTag lt = LanguageTag.GetCachedInstance(langtag);

            if (lt.IsValid())
            {
                // Set persistent cookie in the client to remember the language choice.
                Response.Cookies.Add(new HttpCookie("i18n.langtag")
                {
                    Value    = lt.ToString(),
                    HttpOnly = true,
                    Expires  = DateTime.UtcNow.AddYears(1)
                });
            }
            // Owise...delete any 'language' cookie in the client.
            else
            {
                var cookie = Response.Cookies["i18n.langtag"];
                if (cookie != null)
                {
                    cookie.Value   = null;
                    cookie.Expires = DateTime.UtcNow.AddMonths(-1);
                }
            }
            // Update PAL setting so that new language is reflected in any URL patched in the
            // response (Late URL Localization).
            HttpContext.SetPrincipalAppLanguageForRequest(lt);
            // Patch in the new langtag into any return URL.
            if (returnUrl.IsSet())
            {
                returnUrl = LocalizedApplication.Current.UrlLocalizerForApp.SetLangTagInUrlPath(HttpContext, returnUrl, UriKind.RelativeOrAbsolute, lt == null ? null : lt.ToString()).ToString();
            }
            // Redirect user agent as approp.
            Bootstrapper.Run();
            return(Redirect(returnUrl));
        }
Beispiel #7
0
    /// <summary>
    /// Page load to handle post back and more
    /// </summary>
    /// <param name="sender">the page object</param>
    /// <param name="e">The event arguments</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string language = this.Request.Form["Language"];
            if (language != null)
            {
                string scriptSubtag = this.Request.Form["ScriptSubtag"];
                string regionSubtag = this.Request.Form["Territory"];
                string likelyLanguageTag = this.Request.Form["LikelyLanguageTag"];
                if (!String.IsNullOrEmpty(likelyLanguageTag))
                {
                    this.likelyLanguageTag = new LanguageTag(likelyLanguageTag);
                }

                string loc = txtLoc.Text;

                int id = -1;
                Int32.TryParse(hdnLocaleId.Value, out id);

                int fallbackId = 0;
                Int32.TryParse(lstFallbackLoc.SelectedValue, out fallbackId);

                string privateUseSubtag = txtPrivateUseSubtag.Text.Trim();

                LanguageTag objLangTag = new LanguageTag(language, scriptSubtag, regionSubtag, privateUseSubtag);
                objLangTag.RegistryUri = new Uri(Request.Url, "language-subtag-registry.xml");
                string languageTag = objLangTag.ToString();

                string culture = lstCulture.SelectedValue;
                string uiCulture = lstUICulture.SelectedValue;

                int lcid = 1033;
                System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo(uiCulture);
                if (info != null)
                {
                    lcid = info.LCID;
                }

                string flagFile = rblFlag.SelectedValue;
                string flagUrl = CommonApi.AppImgPath + "flags/" + flagFile;

                string nativeName = txtNativeName.Text;
                string englishName = txtEnglishName.Text;

                bool isRightToLeft = chkIsRightToLeft.Checked;

                LocalizationLanguageState localeState = LocalizationLanguageState.Active;
                if (Enum.IsDefined(typeof(LocalizationLanguageState), hdnState.Value))
                {
                    localeState = (LocalizationLanguageState)Enum.Parse(typeof(LocalizationLanguageState), hdnState.Value);
                    if (LocalizationLanguageState.Defined == localeState)
                    {
                        localeState = LocalizationLanguageState.Active;
                    }
                }

                this.Locale = new LocaleData(id, lcid, englishName, nativeName, isRightToLeft, loc, culture, uiCulture, language, languageTag, flagFile, flagUrl, fallbackId, localeState);
            }
        }
        else
        {
            LanguageDesc.Text = String.Format(LanguageDesc.Text, this.GetDateOfCLDR());
            System.Text.StringBuilder bcp47HyperlinkMarkup = new System.Text.StringBuilder();
            using (HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(bcp47HyperlinkMarkup)))
            {
                BCP47.RenderControl(writer);
            }

            BCP47.Visible = false;
            System.Text.StringBuilder rfc5646HyperlinkMarkup = new System.Text.StringBuilder();
            using (HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(rfc5646HyperlinkMarkup)))
            {
                RFC5646.RenderControl(writer);
            }

            RFC5646.Visible = false;
            XmlLangDescP1.Text = String.Format(XmlLangDescP1.Text, bcp47HyperlinkMarkup.ToString(), rfc5646HyperlinkMarkup.ToString());

            Ektron.Cms.BusinessObjects.Localization.L10nManager l10nMgr = new Ektron.Cms.BusinessObjects.Localization.L10nManager(this.CommonApi.RequestInformationRef);
            MachineTranslationUndefinedPanel.Visible = !l10nMgr.IsMachineTranslationSupported;
            PseudoLocalizationUndefinedPanel.Visible = !l10nMgr.IsPseudoLocalizationSupported;
        }
    }