This object is in archive! 

Multi language

Archived Licences B. 11 years ago

Hi,


is there an easy way to associate a user with a langage and show a different langage dependnig on the user's langage?


We have to support 2 langages, but I don't see any way of switching it depneding on the user.

Best Answer
photo

This is not possible, as we stick to the idea of not mixing content of different languages in one community.

For different languages support it will require 2 different communities and easy way to switch between them by adding Flags in header.phtml in themes.

Replies (8)

photo
1

This is not possible, as we stick to the idea of not mixing content of different languages in one community.

For different languages support it will require 2 different communities and easy way to switch between them by adding Flags in header.phtml in themes.

photo
1

Let's say we add a new field in the user table containing the language. Could there be a way of loading the interface with that language at the start?

photo
1

It would be better to use language list that you have in the system and show it in user profile to choose language. So module will add that field and would switch languages. But it's hard to give a solution, as it requires custom development

photo
1

Ok we will do the custom development. So basically we have to create a new module that switches languages and adds a selection in the user profile so that he can manage the language? Could you tell us where the language setting is loaded in the code so that we can start from there?

photo
1

Here’s what we’ll do:


The place where language is initialized is: /application/3.0/library/Singular/Bootstrap.php


Find public function initTranslate (Zend_Config $options) method.

Then find and replace inside this method case 'user_settings': ............... break;

with:

  1. case 'user_settings':
  2. $this->_require('auth');
  3. $user = Singular_Core::_('Auth')->getLoggedUser();
  4. $userSettings = Singular_Core::_('UserSettings');
  5. if ($userSettings->hasValue('site_default_language', $user)) {
  6. $language = $userSettings->getValue('site_default_language', $user);
  7. } else {
  8. $language = $options->defaultLanguage;
  9. }
  10. break;

After, you can open /configs/application.inc and change language source from:

  1. $config['resources']['translate']['languageSource'] = 'system_settings';

to

  1. $config['resources']['translate']['languageSource'] = 'user_settings';

Now system will look for default language in "<prefix>_user_settings" table by "site_default_language" config_key that corresponds to proper "user_id", in your case - current logged user. If system is unable to find user-defined language it will uses globally defined in $options->defaultLanguage.


You module should manipulate "site_default_language" parameter for each user. I.e: each user is allowed to setup his own native language from list in profile.


I guess this tutorial will be useful to get a grip on your task.

photo
1

Thank you!

photo
1

Another question for you guys.


I tried to add a radio button in the profile page so that the user can change the default language of the website.


this is the code i've added in User.php

  1. //start add
  2. //load configs table
  3. $configsDb = Singular_Loader::get('System_Model_DbTable_UsersConfigs');
  4. //get logged user id
  5. $loggeduserid = $this->getView()->activeUser->id;
  6. //get default language config for logged user
  7. $loggeduserconfigs = $configsDb->findByKeyAndUserId(
  8. System_Model_DbTable_UsersConfigs::DEFAULT_LANGUAGE,$loggeduserid);
  9. //create params array
  10. $params2 = array(
  11. 'label' => $this->getView()->t('Default Language'),
  12. 'description' => $this->getView()->t('Change the default language of IdeaCatcher'),
  13. 'required' => true,
  14. 'value' => $loggeduserconfigs['value'],
  15. 'filters' => array('StringTrim', 'HtmlEntities', 'StripTags'),
  16. 'multiOptions' => array(
  17. System_Model_UserConfig::FRANCAIS => 'Français',
  18. System_Model_UserConfig::ANGLAIS => 'English'
  19. ),
  20. 'decorators' => array(
  21. 'ViewHelper',
  22. array('ViewScript', array('viewScript' => 'forms/elements/multi-radio.phtml'))
  23. )
  24. );
  25. $langselect = new Zend_Form_Element_Radio(System_Model_DbTable_UsersConfigs::DEFAULT_LANGUAGE, $params2);
  26. //end add
  27. $this->addDisplayGroup(array($fullName, $email,$langselect), 'main');


I also added two new constants in UserConfig.php

  1. const FRANCAIS = 'fr';
  2. const ANGLAIS = 'en';

and one constant in usersConfigs.php

  1. const DEFAULT_LANGUAGE = 'site_default_language';

the radio buttons are rendered on the page, but when i try to save the profile, the data is not saved to the Database.


Do i need to add some extra code to handle the database update?

photo
1

Hello,

Sorry, but we don't provide custom code as it's not within standard support and is considered to be custom development that goes as additional service and estimated on custom request.

If you have request for custom development, please email us support(at)useresponse.com

P.S. Also we see that you are changing core. We don't recommend using that method as after upgrade, you'll loose all the changes

Replies have been locked on this page!