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:

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.

Views: 173

Comment

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

Join Ning Developer Docs

Comment by Ronaldo Richieri on December 25, 2008 at 7:15am
This hack is not working anymore, since another update (Tab Editor) was released :-( I will work on it next days :-)
Comment by DB2Admin on December 23, 2008 at 2:06pm
I would love to enable member language selection but it seems that since an Oct 08 update the ability to edit index.php via webdav no longer exists. Is there another way to edit index.php and add the above customizations? Alternatively would be great if Ning adds it as a feature.
Comment by Alberto Azevedo on October 18, 2008 at 11:20am
i managed to make this work, changing the default language for the network to ENGLISH... It wasnt working at first cause it was set to Portuguese...

Thanks for this!
Comment by Mr809 on August 13, 2008 at 7:17pm
Hello there:
First of all thanks for sharing this. I did everything steps by steps but for some reason it only stays in spanish. It does not change to any other language. Do you know what can be the reason? this is mY code
Comment by Andrew Spiering on June 12, 2008 at 12:44pm
I just checked out the google translator and it wasn't able to access my site. A dialog box appeared that said, " Permission denied to get property Window.dojo"

Any thoughts?
Comment by Andrew Spiering on June 12, 2008 at 12:37pm
Comment by Oles on May 13, 2008 at 2:38pm
Hi Ronaldo! Hi Mike!
Thank you very much, great job!
It works for me fine till I use one of available languages as active.
As soon as I change active language to my translation into russian or ukrainian I get error message:
Fatal error: Class 'XG_CustomMessageCatalog_en_US' not found in /apps/socialnetworkmain/lib/XG_LanguageHelper.php on line 338

I use the code from Documentation section. Please let me know how to modify the $languages array to add my own translation.

Thanks!
Comment by Lourenzo Ferreira on April 18, 2008 at 2:37pm
I personally don't trust google translator. Maybe because I've used about 2 years ago....
The generated text use to be a total mess.

Anyway, if the users can propose better translations, it means the system grows it's intelligence up with the users' tips. It sounds like Google things.

About the mashup, it looks great!

I remembered now that my ning-hacking time have being short, but I hope soon I can take some deep looks at the community new ideas.
Comment by Ronaldo Richieri on April 18, 2008 at 7:58am
Another great idea is to mix the code I've done with the google translator idea that is on this site:

http://formularacing.ning.com/

The guys are making the site content translation with google translator and it's very nice... When a sentence is weird, you can put your mouse over it and suggest a better translation. Sounds nice and can be better than my solution :)

We could mix the both thing. The user select his ou her preffered languge, than google translator is activate and make the rest, every time the person enter on the home page :-)
Comment by Ronaldo Richieri on April 16, 2008 at 12:39pm
Hi!

Yeah, All by my self (it seems to be a music)

You're right. It seems to be a hard work and we probably will lose changes because it's impossible to do this without requesting the source code.

Maybe, it didn't make sense to do this with all type of content. Maybe Blog Posts and texts box. The new "Notes" feature would be great since it's near to be a Wiki.

© 2024   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service