I was looking a way to let the members of my network choose their preferred language. I searched the forums but there was nothing like this on Ning. So I decided to do my way. It wasn't easy, but here how it was:
BE CAREFUL! DO AT YOUR OWN RISK!!
1 - First, you DON'T need the source code of your network :-)
2 - Then you need one or two free hours to do the work.
3 - Now, create a new profile Question to your network (Manage -> Profile Questions). I called "Preferred Language". It must be a multiple choice question. So you need to write the Choices you want to be available to your network's members. In my network, I put these:
Português (Brasil),English (U.S.),Español (España),Français
Of course the choices must be comma separeted.
4 - After that, you need to edit your own profile and answer this new question. After this, your user object has a new attribute. You need to check this at your content manager because we need to know what is the name of the attribute created. I don't know other way to do this but going to content manager:
http://YOURNETWORK.ning.com/xn/ningbar.php/helpers/contentManager.php
5 - Search for your user object, and you will se a new attribute at the last lines probably. Some thing like "my.xg_profiles_answer_q14" and the value you selected when you fill your new profile.. something like "English (U.S.)" ou "Potuguês (Brasil)"
Well the important for us is the "my.xg_profiles_answer_q20". It can be different on your network ok?
6 - Now, you need to edit the index.php of your network (BE CAREFUL!!!). Access the following link:
http://www.ning.com/home/apps/edit?appUrl=yournetworkname
Find your index.php and click on it
Here is the content of my index.php:
<?php
define('NF_APP_BASE',dirname(__FILE__));
//Hacking starts
try{
if(XN_Profile::current()->isLoggedIn()){
$query =XN_Query::create('Content')
->filter( 'type', 'eic', 'User')
->filter( 'owner' )
->filter( 'contributor', '=', XN_Profile::current() );
$mylocale = $query->uniqueResult();
//Português (Brasil),English (U.S.),Español (España),Français
$languages = array('Português (Brasil)' => 'pt_BR',
'English (U.S.)' => 'en_US',
'Español (España)'=>'es_ES',
'Français'=>'fr_CA');
if ($mylocale->my->xg_profiles_answer_q14){
$locale = $languages[$mylocale->my->xg_profiles_answer_q14];
define('XG_LOCALE', $locale);
}
}
/*End of work around */
} catch (MyException $e) {
echo 'oi';
//nothing to do ;)
}
//Hacking finishs
require_once NF_APP_BASE . '/lib/index.php';
Here we have some important notes:
a) Make $languages array in accordance with the options of language you will provide on your network.. The firs column of this array, should have the same values of the profile question you've created, in other words, "Português (Brasil)", "English (U.S.)", etc.
The second column should have the correspondent code for this language: pt_BR, en_US and so on...
b) Replace the "xg_profiles_answer_q14" with name of the attribute you collected at the step 5.
That's it. Now, take a deep breath and make a test.
Hope it works for you :-) fell free to contact me.
You need to be a member of Ning Developer Docs to add comments!
Join Ning Developer Docs