Ning Developer Docs

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:


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:

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:
Find your index.php and click on it

Here is the content of my index.php:


//Hacking starts
$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',
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.

Views: 171


You need to be a member of Ning Developer Docs to add comments!

Join Ning Developer Docs

Comment by Lourenzo Ferreira on April 16, 2008 at 5:59am
That's nice!

Have you created this whole thing?

The problem is - how to localize content? Ning has no built-in support to content translation.

Let's brainstorm:

1 - Adding locale information to content
It would be possible to hack this by forking the code (as you've made to allow user-chosen interface language), adding a property "locale" or "language" containing an ISO formated language (such as pt_BR), defaulting to the network main language, for example.

2 - Linking language pieces into one content entity
I can for now figure out a couple ways to do it:

Using meta-content:

  => ID (number)
=> Locales (Array)
=> Locale (Object)
=> ID (number) - Links to actual content
=> Language (string)

Or just adding translations into the default language content in a tree model:

  => ID (number)
=> Title (string)
=> Content (text)
=> Locale (string)
=> Translations (Array)
=> Translation (Object) -> Links To another piece of content
=> Locale (string)
=> ID (number)

The big deal would be redesign tag handling and content search to comply with the new content design.

Almost all models, views and controllers - I think mainly controllers - should be rewritten to do this.

Obviously this would require several hours of detailed planning and even more programming... But I think it would be nice to do.

Unfortunately, I think ning's main app is not changeable by community and we would lose all the new stuff on ning app's official code.
Comment by karl ortenburg on April 16, 2008 at 5:55am
Ronaldo, what a difference you're making to everyone not having English as their mother tongue! Great job, thanks so much. K
Comment by Ronaldo Richieri on April 15, 2008 at 8:39pm
if anyone wants to see this feature working, go to sing up and change your profile languages sometimes ;)
Comment by Ronaldo Richieri on April 15, 2008 at 8:35pm
Well, Actually, I fixed up the Blog Post entry because Jose was right. There is no need to request the source code. We work on index.php now instead of /lib/XG files...
Comment by Ronaldo Richieri on April 15, 2008 at 7:38pm
Hi Jose! This is a work around. I would like that this feature was ning native, but it isn't. So this is a first version of this code. Mike Nicholson and others from ning will polish it up and maybe we can create a way to do this without having to get the source code... but for now it's necessary.
Comment by Jose A. Ramirez on April 15, 2008 at 7:32pm
Could i add this code without gettting the source code? i would like to add this and keep having updates...
Comment by Ronaldo Richieri on April 15, 2008 at 6:11pm
No problems! This is the Idea! Please make this code better and share with the others in the documentation section. There are a lot of people needing this!
Comment by Ronaldo Richieri on April 15, 2008 at 4:18pm
Well, I made this piece of code today. Actually, it's on a testing network that I create. There may exists bugs when use this codes, but at this time, it's working for me. You can try it on the following network:

Subscribe and select the language you want. I only provide Portuguese, English, Spanish and french.

If you really need this feature on your network, I can give you a help.

I just receive these comments in this page as feedback, ok?

Comment by karl ortenburg on April 15, 2008 at 3:38pm
Hi Ronaldo, thanks for sharing this so generously.

Does this 'choice of languages' actually work on your site?

I am not going to try this tonight a) it's 23:30 already b) I am not that technical but I would be very much interested if it indeed works fine.

If it does, have you had any feedback from ning on it?

Comment by Jose A. Ramirez on April 15, 2008 at 1:26pm
Im going to try this tonight...!

© 2023   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service