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: 177

Comment

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

Join Ning Developer Docs

Comment by Laurens Laudowicz on August 19, 2009 at 1:33am
hey

what about the language feature...is there an update...does it work flawless now?
Comment by Ronaldo Richieri on March 5, 2009 at 2:38am
I think you did not read the comments. Ning have changed the way they worked, and they have disabled the option to edit files, so this Hack is not working anymore ok?
Comment by Moataz on March 4, 2009 at 3:21pm
Hey Mr. Ronaldo,

I try it but the my index.php not found, please help me to find it and edit.
Thanks in advance,
Moataz
Comment by Ronaldo Richieri on February 26, 2009 at 4:29am
no :-(
Comment by mirage on February 26, 2009 at 2:46am
Hi Ronaldo,

Please any update on it...??
Comment by Ronaldo Richieri on February 9, 2009 at 4:18pm
pois é, parece uma nova politica, tenho impressão que eles fizeram isso pra ter um modelo de negócios mais interessante (pra eles) ..rs.. Mas não sei ao certo, o que sei é que não tem mais código fonte disponível para alterar. Os hacks que já haviam sido feitos nas redes antigas continuam funcionando, mas não dá pra modificar ou adicionanr hacks em outras redes. Infelizmente, e eu também achei meio absurdo...
Comment by Nayse Lopez on February 9, 2009 at 2:18pm
saquei. mas porque noa é mais possivel mexer no index.php (absurdo) ou porque o novo update mexeu da confg e o hack nao roda? estou deixando messages em todos as discussoes e ja mandei requests para o carinhas do ning. é o fim da picada nao ter essa funcionalidade para uma rede que quer ser mundial. Fui na rede teste que vc linkou e a troca de idiomas funionou, quando eu me inscrevi. Ou seja, o hack funciona ainda, certo?
Comment by Ronaldo Richieri on February 9, 2009 at 2:12pm
Olá Nayse. Nenhuma notícia, parece que daqui pra frente tudo que se desejar desenvolver, qualquer aplicação, tem que ser no padrão OpenSocial. Como não conheço, não sei se é possível desenvolver uma funcionalidade como esta dentro do OpenSocial :-( Desculpe!
Comment by Nayse Lopez on February 9, 2009 at 2:00pm
OI Ronaldo, alguma noticia do acesso ao php? estou colocando no ar uma rede biligue portugues e espanhol e precisoooooo deste hack. mas nao consigo acessar mais o php. tentei pelo ultimo caminho que vc tinha dado (http://www.ning.com/home/apps/edit?appUrl=yournetworkname) mas agora aparecem mapping urls. tem como aplicar o hack assim? socorro.
Comment by mirage on January 23, 2009 at 2:24pm
hi ronaldo

as i have tried to edit the php but DB2Admin is right i can't edit it...

can you tell me how can i edit it even there is one button to edit it after clicking it jsut it shows


Pattern
/xn/detail/([^\?]+)(?:\?(.*))?

Target (then in text field )

/index.php/main/index/detail?id=$1&$2

so please can you guide us how to do it

looking forward for your prompt reply or action

regards,

mirage

© 2024   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service