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
pablo_
New
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.
0
Comments
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.
What about this hook
Gdn_Locale_AfterSet_Handler
?There was an error rendering this rich post.
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).
Try disabling the multilang plugin and set the languange in the above hook.
There was an error rendering this rich post.
@lifeisfoo ok
Maybe you want this?
http://vanillaforums.org/discussion/23580/howto-more-languages-for-your-vanilla#latest
I've tried it but it doesnt seems to affect at all, obviously because i'm doing something wrong.
<?php class mandooThemeHooks extends Gdn_Plugin { public function Gdn_Locale_AfterSet_Handler(){ Gdn::Locale()->Set("ru-RU", Gdn::ApplicationManager()->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE); } } ?>Here's my code:
BTW i've been looking for that hook in the documentation, but i havent been able to find it yet.
@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.
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.
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:
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?
$_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:
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.
flawed approach, you can trust this, or rely on this information to be provided.
grep is your friend.
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.
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.
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.
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).
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.
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.
That was what i needed to know.
So in any case I'm gonna have to wait for user input, right?
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.