Dr.DG
  •  Dr.DG
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-03-11T21:49:10Z
I know this topic has been discussed yet but now a new aspect.

I faced an issue with localization (Russian), forum still showing dates in English.

After investigating a little, found that CurrentThread.CurrentCulture is set to the language code taken from the first language in the browser settings but not from the language file.

Therefore if your preferred browser language is not equal to the localization language you have the issue (tested only with IE).

This logic seems strange to me. Why not taking the language code from the language file?

So I changed Context.cs slightly and could upload it if anybody cares.
Sponsor
Dr.DG
  •  Dr.DG
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
2009-03-29T23:33:39Z
These are the suggested changes to Context.cs to address the above issue:
		public YafLocalization Localization
		{
			get
			{
                // Dr.DG, 2009-03-11: commented
                //if ( !_initCulture ) InitCulture();
                //if ( !_initLocalization ) InitLocalization();

                // Dr.DG, 2009-03-11: first call InitLocalization and then InitCulture to use the localization language code in InitCulture
				if ( !_initLocalization ) InitLocalization();
				if ( !_initCulture ) InitCulture();

				return _localization;
			}
			set
			{
				_localization = value;
				_initLocalization = ( value != null );
			}
		}

		protected void InitCulture()
		{
			if ( !_initCulture )
			{
				try
				{
                    // Dr.DG, 2009-03-11: commented
                    // string cultureCode = "";
                    //string [] tmp = HttpContext.Current.Request.UserLanguages;
                    //if ( tmp != null )
                    //{
                    //    cultureCode = tmp [0];
                    //    if ( cultureCode.IndexOf( ';' ) >= 0 )
                    //    {
                    //        cultureCode = cultureCode.Substring( 0, cultureCode.IndexOf( ';' ) ).Replace( '_', '-' );
                    //    }
                    //}
                    //else
                    //{
                    //    cultureCode = "en-US";
                    //}

                    // Dr.DG, 2009-03-11: set current culture to the localization language code
                    string cultureCode = _localization.LanguageCode;
					Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture( cultureCode );
					Thread.CurrentThread.CurrentUICulture = new CultureInfo( cultureCode );
				}
#if DEBUG
			catch ( Exception ex )
			{
				DB.eventlog_create( this.PageUserID, this, ex );
				throw new ApplicationException( "Error getting User Language." + Environment.NewLine + ex.ToString() );
			}
#else
				catch ( Exception )
				{
					// set to default...
					Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture( "en-US" );
					Thread.CurrentThread.CurrentUICulture = new CultureInfo( "en-US" );
				}
#endif
				// mark as setup...
				_initCulture = true;
			}			
		}
Jaben
  •  Jaben
  • 100% (Exalted)
  • YAF Developer
2009-04-01T16:45:21Z

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved