Exemple #1
0
        /// <summary>
        /// The get text, with a Specific Language.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="tag">
        /// The tag.
        /// </param>
        /// <param name="languageFile">
        /// The Language file
        /// </param>
        /// <returns>
        /// The get text.
        /// </returns>
        public string GetText([NotNull] string page, [NotNull] string tag, [NotNull] string languageFile)
        {
            string localizedText;

            if (languageFile.IsSet())
            {
                var localization = new Localization();
                localization.LoadTranslation(languageFile);
                localizedText = localization.GetText(page, tag);
            }
            else
            {
                localizedText = this.GetLocalizedTextInternal(page, tag);
            }

            if (localizedText == null)
            {
#if !DEBUG
                string filename;

                if (languageFile.IsSet())
                {
                    filename = languageFile;
                }
                else
                {
                    if (YafContext.Current.PageIsNull() || YafContext.Current.LanguageFile == string.Empty ||
                        YafContext.Current.LanguageFile == string.Empty ||
                        !YafContext.Current.Get <BoardSettings>().AllowUserLanguage)
                    {
                        filename = YafContext.Current.Get <BoardSettings>().Language;
                    }
                    else
                    {
                        filename = YafContext.Current.LanguageFile;
                    }
                }


                if (filename == string.Empty)
                {
                    filename = "english.xml";
                }

                HttpContext.Current.Cache.Remove($"Localizer.{filename}");
#endif
                YafContext.Current.Get <ILogger>()
                .Log(
                    YafContext.Current.PageUserID,
                    $"{page.ToLower()}.ascx",
                    $"Missing Translation For {page.ToUpper()}.{tag.ToUpper()}");

                return($"[{page.ToUpper()}.{tag.ToUpper()}]");
            }

            localizedText = localizedText.Replace("[b]", "<b>");
            localizedText = localizedText.Replace("[/b]", "</b>");

            return(localizedText);
        }
Exemple #2
0
        /// <summary>
        /// Reads a template from the language file
        /// </summary>
        /// <param name="templateName">
        /// The template Name.
        /// </param>
        /// <param name="templateLanguageFile">
        /// The template Language File.
        /// </param>
        /// <returns>
        /// The template
        /// </returns>
        private string ReadTemplate(string templateName, string templateLanguageFile)
        {
            if (templateName.IsNotSet())
            {
                return(null);
            }

            if (templateLanguageFile.IsNotSet())
            {
                return(this.Get <ILocalization>().GetText("TEMPLATES", templateName));
            }

            var localization = new Localization.Localization();

            localization.LoadTranslation(templateLanguageFile);

            return(localization.GetText("TEMPLATES", templateName, templateLanguageFile));
        }
Exemple #3
0
        /// <summary>
        /// The get text, with a Specific Language.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="tag">
        /// The tag.
        /// </param>
        /// <param name="languageFile">
        /// The Language file
        /// </param>
        /// <returns>
        /// The get text.
        /// </returns>
        public string GetText([NotNull] string page, [NotNull] string tag, [NotNull] string languageFile)
        {
            string localizedText;

            if (languageFile.IsSet())
            {
                var localization = new Localization();
                localization.LoadTranslation(languageFile);
                localizedText = localization.GetText(page, tag);
            }
            else
            {
                localizedText = this.GetLocalizedTextInternal(page, tag);
            }

            if (localizedText == null)
            {
#if !DEBUG
                string filename;

                if (languageFile.IsSet())
                {
                    filename = languageFile;
                }
                else
                {
                    if (BoardContext.Current.PageIsNull() || BoardContext.Current.LanguageFile.IsNotSet() ||
                        !BoardContext.Current.Get <BoardSettings>().AllowUserLanguage)
                    {
                        filename = BoardContext.Current.IsGuest
                                       ? UserHelper.GetGuestUserLanguageFile()
                                       : BoardContext.Current.Get <BoardSettings>().Language;
                    }
                    else
                    {
                        filename = BoardContext.Current.IsGuest
                                       ? UserHelper.GetGuestUserLanguageFile()
                                       : BoardContext.Current.LanguageFile;
                    }
                }


                if (filename == string.Empty)
                {
                    filename = "english.xml";
                }

                BoardContext.Current.Get <IDataCache>().Remove($"Localizer.{filename}");
#endif
                BoardContext.Current.Get <ILogger>().Log(
                    BoardContext.Current.Get <IUserDisplayName>().GetName(BoardContext.Current.CurrentUser),
                    $"{page.ToLower()}.ascx",
                    $"Missing Translation For {page.ToUpper()}.{tag.ToUpper()}");

                return($"[{page.ToUpper()}.{tag.ToUpper()}]");
            }

            localizedText = localizedText.Replace("[b]", "<b>");
            localizedText = localizedText.Replace("[/b]", "</b>");

            return(localizedText);
        }