Published with permission of Ronaldo Richiery. Thanks, Ronaldo!
I have used the text from Ning tutorial for this hack to describe new Ronaldo's solution.
Sorry for mistakes, English is not my native language. Here it is!
Introduction:
Giving your members the ability to define localization options for a network is a really cool feature that many of you have been asking about. Ronaldo Richieri, a developer on this community came up with a great solution to this problem. This tutorial explains Ronaldo's solution and shows you how to implement a system that will allow members to set their own language preferences for a network by interacting with a specific network profile questions.
To implement our language selection system, we will need to complete 3 tasks. First, you will have to create the set of customized language files to be used in your network. This step allows to avoid problems in the networks where memebers have to choose between languages from default language set and customized language files or new languages provided by NC. Second, we'll need to create a member profile question on our network that will serve as member driven language configuration setting. Next, we'll be adding logic to our network's index.php file that will check a user's profile questions and determine which language pack to apply to a network at runtime.
Step 1 - Creating customized language set for your network
For example, you wish to give your memebers to choose between dafault Ning's Spanish and Chinese you don't know, English (US) customised with Language Editor and Russian language imported from some translation files. Existence in your network of ANY customised languages or imported translations demands to make all other optional languages "customised", which put all their files to the same folders. In our case you should "customize" Spanish and Chinese language files for example by opening them in language editor and adding to any word HTML comment string and saving your changes.
Import your translation file to your network using Language editor.
Step 2 - Creating Profile Question for Selecting a Preferred Language
Login to your network and login as the Network Creator.
Click on the tab labeled "Manage"
On the "Manage" page for your network, click on the link labeled "Profile Questions".
Define a new profile question with the following attributes
Question Title: Preferred Language
Answer Type: Multiple Choice
Choices: English, Español, Chinese, Russian
Save your profile question.
Step 3 - Identify the ID Value Associated with the New Preferred Language Profile Question
Make sure that you're logged out of your network.
Click on the link labeled "Sign Up"
Begin the process of creating a test account. Once you reach the page that asks you to answer profile questions for the network stop the signup process for a moment.
View the generated source code for the profile question page. (You can either right click your mouse and view source or use a tool like Firebug)
In the generated source, locate the input fields for your "Preferred Language" question. (You can do a text search for the phrase "Preferred Language")
Once you've located the input fields for "Preferred Language", we're going to want to find the question's id #.
This "Preferred Language" question consists of several radio buttons. Locate any one of the radio buttons for the "Preferred Language" profile question. You should see something that looks like:
- Locate the "name" attribute for this radio button.
The value for the "name" attribute should look something like "question_30". The integer value, contained in this attribute is the id # you're looking for (In the example above this integer value is "30"). Remember or write this value down somewhere.
Step 3 - Adding Logic to Determine Which Language Pack is Applied To Your Network At Runtime
Login to your network's file system using WebDav
Open folder
https://yourdomain.dav.ning.com/xn_resources/instances/shared/js/me...
and find Ning assigned name for your imported Russian translation file. It looks like “custom_123456789”.
Locate the file named "index.php".
Make a backup copy of the index.php file in case you want to revert the functionality we'll be adding to your network
Replace your index.php file with the following PHP code from attachment
(Sorry, I do not know how to insert code)... )))
Replace in the language array the name for imported translation file for Russian language custom_123456789 with the name you find in folder
https://yourdomain.dav.ning.com/xn_resources/instances/shared/js/me...
Replace in the two “xg_profiles_answer_q30” strings integer value "30" with the question id value you identified in step 2 of this tutorial.
Save your changes.
Testing:
Verify new language functionality with an existing member account
Login to your network with an existing member account
Click on the tab labeled "My Page"
Click on the link labeled "My Settings"
Click on the link labeled "About Me"
Select a "Preferred Language"
Save changes and verify that the proper language pack is applied to your network.
Verify new language functionality with a new member account
Signup for a new member account
Verify that once the account has been created and you are logged into your network with the new account, the correct language pack is applied to your network.
Additional Info:
Please remember that the functionality built in this tutorial has NOT been through our normal QA process. Please do not implement the concepts outlined in this tutorial on a production network until you've thoroughly tested and verified all the functionality for yourself.