Override culture/language based on user's profile?

Last post 04-20-2009, 1:47 PM by Anonymous. 3 replies.
Sort Posts: Previous Next
  •  04-17-2009, 12:32 PM 51215

    Override culture/language based on user's profile?

    I have CuteChat integrated into my Community Server website.  In Community Server, the user's language is specified as part of their profile.  I'd like to tell CuteChat to use the user's profile language, and not rely on their browser settings?  Is this possible currently?  If not, please consider making this aspect more extensible as a future enhancement.
     
    Thanks,
    Troy
  •  04-20-2009, 8:43 AM 51265 in reply to 51215

    Re: Override culture/language based on user's profile?

    Hi wolbrink,
     
    Try this way:
     
    1. Open file 'Channel.aspx'(\CuteSoft_Client\CuteChat\Channel.aspx)
     
    2. Find section
    override protected void OnInit(EventArgs args)

     base.OnInit(args);
    }
     
    3. Add the code below into the section above
     
       CommunityServer.Components.User user = CommunityServer.Users.GetUser();
        uteChat.ChatApi.SetConfig("CustomCulture", user.Profile.Language);
       CuteChat.ChatApi.SetConfig("CultureType", "Client");
     
    like:
     
    override protected void OnInit(EventArgs args)
       CommunityServer.Components.User user = CommunityServer.Users.GetUser();
        uteChat.ChatApi.SetConfig("CustomCulture", user.Profile.Language);
       CuteChat.ChatApi.SetConfig("CultureType", "Client");
     base.OnInit(args);
    }
     
     
    Regards,
     
    Ken
  •  04-20-2009, 11:04 AM 51267 in reply to 51265

    Re: Override culture/language based on user's profile?

    Thanks, Ken!
     
    I'll give this a try.  Is this something you've done on your site?  If so, has it worked well for you?
    override protected void OnInit(EventArgs args)
       CommunityServer.Components.User user = CommunityServer.Users.GetUser();
        uteChat.ChatApi.SetConfig("CustomCulture", user.Profile.Language);
       CuteChat.ChatApi.SetConfig("CultureType", "Client");
     base.OnInit(args);
    }
     
    I was actually thinking of doing it this way, but I'm wondering about a few issues:
     
    1.  What if two requests for "Channel.aspx" come in at the same time.  Won't the last user to set the global "CustomCulture" win?  Perhaps this page should be in a critical section (start in OnInit and end in OnUnload)?
     
    2.  What about all the "ajax" stuff going on.  Will the return values of all these ajax-calls be correctly localized?
     
    Thanks,
    Troy
  •  04-20-2009, 1:47 PM 51276 in reply to 51267

    Re: Override culture/language based on user's profile?

    I found a solution!  I added this to Global.asax.cs:
     

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)

    {

    User user = CSContext.Current.User;

    if (user.Profile.Language == "de")

    // fixes a bug where neutral cultures < en-us are ignored

    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");

    else

    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(user.Profile.Language);

    // set config so that CurrentUICulture is used

    CuteChat.ChatApi.SetConfig("CultureType", "Server");

    CuteChat.ChatApi.SetConfig("CurrentCulture", "");

    }

    --Troy
View as RSS news feed in XML