Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Change language dynamically

Hi, I'm having some troubles changing the language on the forum,I've already installed the multilingual plugin but what I need is get the language from the browser and dynamically change the forum's one, I dont want user input.
Now, with this
" Gdn::Locale()->Set("zh-CN", Gdn::ApplicationManager()->EnabledApplicationFolders(), Gdn::PluginManager()>EnabledPluginFolders()); "
I've been able to change what I think its the public part of the forum, but most of it remains unchanged. I think that's because in order to translate the rest i'd use "userMeta settings", but I haven't been able to make it work.
Any help would be apreciated.

Thx.

Comments

  • hgtonighthgtonight ∞ · New Moderator

    Do you want to change it only for logged in users?

    What version of Vanilla are you running?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • lifeisfoolifeisfoo Zombie plugins finder ✭✭✭

    What about this hook Gdn_Locale_AfterSet_Handler ?

    There was an error rendering this rich post.

  • @hgtonight said:
    Do you want to change it only for logged in users?

    What version of Vanilla are you running?

    I want to change it for everyone, but i've only been able to change what u can see when u're not logged.

    I'm using the latest version (2.0.xxx).

  • lifeisfoolifeisfoo Zombie plugins finder ✭✭✭

    Try disabling the multilang plugin and set the languange in the above hook.

    There was an error rendering this rich post.

  • I've tried it but it doesnt seems to affect at all, obviously because i'm doing something wrong.
    Here's my code:

    <?php class mandooThemeHooks extends Gdn_Plugin { public function Gdn_Locale_AfterSet_Handler(){ Gdn::Locale()->Set("ru-RU", Gdn::ApplicationManager()->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE); } } ?>

    BTW i've been looking for that hook in the documentation, but i havent been able to find it yet.

  • hgtonighthgtonight ∞ · New Moderator

    @lifeisfoo It looks like that event was introduced in 2.1b1.

    @pablo_ Most event hooks are not documented. Someone posted a list of events on the wiki.

    You can also find them by searching through the source files for FireEvent('EventName') or look at other plugins to see what they use.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • lifeisfoolifeisfoo Zombie plugins finder ✭✭✭

    You can use the Eventi plugin to see all events on a page http://vanillaforums.org/addon/eventi-plugin

    There was an error rendering this rich post.

  • pablo_pablo_ New
    edited May 2013

    Hi, i'm very gratefull for the help, finally i've been able to make the plugin, and change the language acording to the browser language.

    But now i'm told that i've to get the lang first from the session.

    Something like this:

    if (isset($_SESSION["lang"])) {
        $appLang = $_SESSION["lang"];} 
    

    But garden session doesnt seem to have any locale/language. I've tried:

    $Session = Gdn::Session();

    if (isset($Session["lang"]))

    but as I've said, there's no lang/language/ Gdn session, how can i retrieve it?

  • hgtonighthgtonight ∞ · New Moderator

    $_SESSION is the PHP session variable.

    If you are unsure of what a variable contains, I suggest you var_dump it in your development environment.

    Something like this:

    $Session = Gdn::Session();
    var_dump($Session);
    

    Then inspect the output. The language might be stored somewhere you didn't know to look.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • get the language from the browser

    flawed approach, you can trust this, or rely on this information to be provided.

    grep is your friend.

  • pablo_pablo_ New
    edited May 2013

    @hgtonight said:
    $_SESSION is the PHP session variable.

    If you are unsure of what a variable contains, I suggest you var_dump it in your development environment.

    Something like this:

    $Session = Gdn::Session();
    var_dump($Session);
    

    Then inspect the output. The language might be stored somewhere you didn't know to look.

    Already tried that but there was nothing i could relate to language, will look again tomorrow (can't do it if I'm not at work), but I'm pretty sure there wasn't.

    @x00 said:
    flawed approach, you can trust this, or rely on this information to be provided.

    I agree, that's the last clause, but since there's not, or at least I haven't found a lang stored in session, i don't know where else to look.

  • hgtonighthgtonight ∞ · New Moderator
    edited May 2013

    I don't think the Language is stored in the session. You can almost certainly find it in one of the objects and hook into that.

    I would question needing to get the default from somewhere, personally.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight said:
    I don't think the Language is stored in the session. You can almost certainly find it in one of the objects and hook into that.

    I would question needing to get the default from somewhere, personally.

    I didn't express myself well. Anyway i think it was clear what was meant by stored >_<.
    I'll paste tomorrow what i get from the var_dump, but I don't think there was anything related to lang/locale there (again, maybe I overlooked something).

  • hgtonighthgtonight ∞ · New Moderator

    @pablo_ said:
    I'll paste tomorrow what i get from the var_dump, but I don't think there was anything related to lang/locale there (again, maybe I overlooked something).

    Please do not do this; there is sensitive information stored in the session variables.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Firstly session is NOT controlled by the browser. If you want to set session variable that is certainly possible, as is user meta. The only thing the the browser has to do with session is in setting the cookies. This is a reference to the session.

    This framework does not automatically assume anything about language, in fact out of the box it is a one language deal, if you want to have user or session based locale, then you need to store this preference first before checking it.

    grep is your friend.

  • The only way you can get a rough idea of country of origin is by decoding IP, angina you can make any assumptions there,

    If you want the is type of broad translation then use google translate or similar.

    If you have specific clientèle, then allow them to choose between select translations.

    grep is your friend.

  • @x00 said:
    Firstly session is NOT controlled by the browser. If you want to set session variable that is certainly possible, as is user meta. The only thing the the browser has to do with session is in setting the cookies. This is a reference to the session.

    I don't think I've ever said session was controlled by browser Oo.
    It's just that i needed to get the lang from somewhere, so first I took it from the browser, then I was said that i had to get it from the session.

    @x00 said:

    This framework does not automatically assume anything about language.

    That was what i needed to know.

    @x00 said:
    if you want to have user or session based locale, then you need to store this preference first before checking it.

    So in any case I'm gonna have to wait for user input, right?

  • lifeisfoolifeisfoo Zombie plugins finder ✭✭✭

    If you want this info without user input, you can with ip localization. There are many commercial service that offer this service, one is http://www.ip2location.com/

    You can buy from them a country<->ip database to query with their api: http://www.ip2location.com/developers/php

    There was an error rendering this rich post.

Sign In or Register to comment.