示例#1
0
    /// <summary>
    /// The load translation.
    /// </summary>
    /// <param name="fileName">
    /// The file name.
    /// </param>
    /// <returns>
    /// Returns the translation Culture Info.
    /// </returns>
    public CultureInfo LoadTranslation([NotNull] string fileName)
    {
      CodeContracts.VerifyNotNull(fileName, "fileName");

      if (this._localizer != null)
      {
        return this._localizer.CurrentCulture;
      }

#if !DEBUG
			if ( _localizer == null && HttpContext.Current.Cache ["Localizer." + fileName] != null )
				_localizer = ( Localizer ) HttpContext.Current.Cache ["Localizer." + fileName];
#endif
      if (this._localizer == null)
      {
        this._localizer =
          new Localizer(
            HttpContext.Current.Server.MapPath(
              "{0}languages/{1}".FormatWith(YafForumInfo.ForumServerFileRoot, fileName)));

#if !DEBUG
				HttpContext.Current.Cache ["Localizer." + fileName] = _localizer;
#endif
      }

      // If not using default language load that too
      if (fileName.ToLower() != "english.xml")
      {
#if !DEBUG
        if ( _defaultLocale == null && HttpContext.Current.Cache ["DefaultLocale"] != null )
          _defaultLocale = ( Localizer ) HttpContext.Current.Cache ["DefaultLocale"];
#endif

        if (this._defaultLocale == null)
        {
          this._defaultLocale =
            new Localizer(
              HttpContext.Current.Server.MapPath(
                "{0}languages/english.xml".FormatWith(YafForumInfo.ForumServerFileRoot)));
#if !DEBUG
          HttpContext.Current.Cache ["DefaultLocale"] = _defaultLocale;
#endif
        }
      }

      try
      {
        // try to load culture info defined in localization file
        this._culture = this._localizer.CurrentCulture;
      }
      catch
      {
        // if it's wrong, fall back to current culture
        this._culture = CultureInfo.CurrentCulture;
      }

      this._languageFileName = fileName.ToLower();

      return this._culture;
    }
示例#2
0
        /// <summary>
        /// The load translation.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <returns>
        /// Returns the translation Culture Info.
        /// </returns>
        public CultureInfo LoadTranslation([NotNull] string fileName)
        {
            CodeContracts.VerifyNotNull(fileName, "fileName");

            if (this._localizer != null)
            {
                return(this._localizer.CurrentCulture);
            }

#if !DEBUG
            if (_localizer == null && HttpContext.Current.Cache["Localizer." + fileName] != null)
            {
                _localizer = (Localizer)HttpContext.Current.Cache["Localizer." + fileName];
            }
#endif
            if (this._localizer == null)
            {
                this._localizer =
                    new Localizer(
                        HttpContext.Current.Server.MapPath(
                            "{0}languages/{1}".FormatWith(YafForumInfo.ForumServerFileRoot, fileName)));

#if !DEBUG
                HttpContext.Current.Cache["Localizer." + fileName] = _localizer;
#endif
            }

            // If not using default language load that too
            if (fileName.ToLower() != "english.xml")
            {
#if !DEBUG
                if (_defaultLocale == null && HttpContext.Current.Cache["DefaultLocale"] != null)
                {
                    _defaultLocale = (Localizer)HttpContext.Current.Cache["DefaultLocale"];
                }
#endif

                if (this._defaultLocale == null)
                {
                    this._defaultLocale =
                        new Localizer(
                            HttpContext.Current.Server.MapPath(
                                "{0}languages/english.xml".FormatWith(YafForumInfo.ForumServerFileRoot)));
#if !DEBUG
                    HttpContext.Current.Cache["DefaultLocale"] = _defaultLocale;
#endif
                }
            }

            try
            {
                // try to load culture info defined in localization file
                this._culture = this._localizer.CurrentCulture;
            }
            catch
            {
                // if it's wrong, fall back to current culture
                this._culture = CultureInfo.CurrentCulture;
            }

            this._languageFileName = fileName.ToLower();

            return(this._culture);
        }