One-click language setting?

One-click language setting?

This question is answered

I have no idea if this is technically possible - but I wanted to throw this question out to the masterminds on the forum just in case...

I'd like to set up a header in our community with flags for our core languages which would set the user's language setting when they click on them. So that a user could change their language without having to go into their profile options.

Is this something which could be achieved?

Verified Answer
  • You should be able to do this by creating a new header fragment. It's just like creating a widget except you have to register it in the theme.config files instead of through the UI Customization process.

    As for getting the configured/installed languages to display in the .ascx file part of the widget, I'm not sure about that one. However, I would be interested in having the same capability so please update the post if you work it out.

  • Thanks for the response, Kevin. I'm not so worried about creating the element which will show on the page, and I don't need it to dynamically display which languages are installed - I'd be happy to just maintain that manually as the languages are not going to change much.

    The part that I really don't know how to do is to set the user's language choice based on which flag they click on.

    ____________

    One other side note - I see that this post has been moved into the 'Telligent Evolution Platform' forum, from the Telligent Community forum. Doesn't look like this forum gets much traffic, and I don't really see why it was moved. Any moderators care to clarify?

  • Gordon, sorry it took so long to reply. I did not notice the post was moved so it kind of dropped out of view for me. I think this will solve your problem if you have not already done so.

    User user = CSContext.Current.User;
    user.Profile.Language = "{{ culture code}}";
    CommunityServer.Users
    .UpdateUser(user);

     

    You will need to make sure you reference the appropriate assemblies in your project. Also beware the UserUpdate events will fire after this change so if you have custom code in an ICSModule then becareful not to put yourself into an infinite loop.

    You will need to make sure you reference the appropriate assemblies in your project. Also beware the UserUpdate events will fire after this change so if you have custom code in an ICSModule then becareful not to put yourself into an infinite loop.

     

     

  • Not sure what your requirements are, but this if you need to be able to adjust the anonymous user this won't fully work.  If you need to deal with anonymous users, your best bet would be to write a CSModule which hooks into the UserKnown event, and reads the language setting from a cookie (which you'd set by some kind of drop down list).  You could also write a second CSModule which hooks into the PreUserUpdate event, and when users are being created checks if the user's set a language in the cookie and then set that as the user's default language.

  • Alex, can you eleborate on what you do when handling that event if you are dealing with an anonymous user? What setting or property do you change to ensure the correct langauge pack is loaded?

  • Pretty much the same as you did above, but don't commit the change to the database.

    // If the user is registered, use their profile language setting.

    if (CSContext.Current.User.IsAnonymous)

    {

       // logic to determine the language to use

       CSContext.Current.User.Profile.Language = "en-us";

    }

    Now I'm sure you don't want

  • Thank you both for your answers. I think this will be really helpful.

    Our community is pretty much restricted to registered users, so the anonymous user scenario isn't so much of an issue.

    Cheers,

  • Gordon,


    I think guys gave you good solution already how to switch user locale. Though be aware about existing issues with Telligent.Community and Telligent.Enterprise language support I mentioned already on forums.
    1. Site Terms - you have to add it manually in SQL database for each of language you need to have support on your site http://telligent.com/communities/technical/community/f/533/p/1057610/1325607.aspx#1325607

    2. There are like 460+ bugs in TC and TE at the moment regarding multi language support. I reported it here - http://telligent.com/communities/technical/community/f/533/p/1057730/1325725.aspx

    We actually spent some time already fixing that, so ping me if you need more information about it.

All Replies
  • You should be able to do this by creating a new header fragment. It's just like creating a widget except you have to register it in the theme.config files instead of through the UI Customization process.

    As for getting the configured/installed languages to display in the .ascx file part of the widget, I'm not sure about that one. However, I would be interested in having the same capability so please update the post if you work it out.

  • Thanks for the response, Kevin. I'm not so worried about creating the element which will show on the page, and I don't need it to dynamically display which languages are installed - I'd be happy to just maintain that manually as the languages are not going to change much.

    The part that I really don't know how to do is to set the user's language choice based on which flag they click on.

    ____________

    One other side note - I see that this post has been moved into the 'Telligent Evolution Platform' forum, from the Telligent Community forum. Doesn't look like this forum gets much traffic, and I don't really see why it was moved. Any moderators care to clarify?

  • Gordon, sorry it took so long to reply. I did not notice the post was moved so it kind of dropped out of view for me. I think this will solve your problem if you have not already done so.

    User user = CSContext.Current.User;
    user.Profile.Language = "{{ culture code}}";
    CommunityServer.Users
    .UpdateUser(user);

     

    You will need to make sure you reference the appropriate assemblies in your project. Also beware the UserUpdate events will fire after this change so if you have custom code in an ICSModule then becareful not to put yourself into an infinite loop.

    You will need to make sure you reference the appropriate assemblies in your project. Also beware the UserUpdate events will fire after this change so if you have custom code in an ICSModule then becareful not to put yourself into an infinite loop.

     

     

  • Not sure what your requirements are, but this if you need to be able to adjust the anonymous user this won't fully work.  If you need to deal with anonymous users, your best bet would be to write a CSModule which hooks into the UserKnown event, and reads the language setting from a cookie (which you'd set by some kind of drop down list).  You could also write a second CSModule which hooks into the PreUserUpdate event, and when users are being created checks if the user's set a language in the cookie and then set that as the user's default language.

  • Alex, can you eleborate on what you do when handling that event if you are dealing with an anonymous user? What setting or property do you change to ensure the correct langauge pack is loaded?

  • Pretty much the same as you did above, but don't commit the change to the database.

    // If the user is registered, use their profile language setting.

    if (CSContext.Current.User.IsAnonymous)

    {

       // logic to determine the language to use

       CSContext.Current.User.Profile.Language = "en-us";

    }

    Now I'm sure you don't want

  • Thank you both for your answers. I think this will be really helpful.

    Our community is pretty much restricted to registered users, so the anonymous user scenario isn't so much of an issue.

    Cheers,

  • Gordon,


    I think guys gave you good solution already how to switch user locale. Though be aware about existing issues with Telligent.Community and Telligent.Enterprise language support I mentioned already on forums.
    1. Site Terms - you have to add it manually in SQL database for each of language you need to have support on your site http://telligent.com/communities/technical/community/f/533/p/1057610/1325607.aspx#1325607

    2. There are like 460+ bugs in TC and TE at the moment regarding multi language support. I reported it here - http://telligent.com/communities/technical/community/f/533/p/1057730/1325725.aspx

    We actually spent some time already fixing that, so ping me if you need more information about it.