The attached patch adds a 'USER_DEFAULT' language (could probably use some work) option on the configuration screen, and then, if a profile is set with that as the language, swaps in the global $language->language parameter at page load.

For all the reasons mentioned in #362318: Limit wysiwyg language selection to available languages, this needs work because there is no guarantee that a user's configured language would have been installed on the 3rd-party wysiwyg library.

CommentFileSizeAuthor
wysiwyg.language.patch1.93 KBjhedstrom

Comments

sun’s picture

Status: Needs work » Postponed
markus_petrux’s picture

As soon as #362318 gets in, we can use the list of languages available per editor to see if the user interface language (*) is in the list, if so, we could tell the editor to use that one dynamically. Hence the language defined at editor profile level may end up as a fall back resource, in case user interface languages are not available per editor profile.

(*) by "user interface languages" I probably mean, the current language, if not available, try with the site default language. Or something like that. :P :)

markus_petrux’s picture

Since we can alter the editor settings, this is now easy to achieve from a little custom module.

/**
 * Implementation of wysiwyg_editor_settings_alter().
 *
 * Tell TinyMCE to use the current language if it is installed.
 *
 * @todo You may need to change the file checking logic to add support for other editors.
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($settings['language'] != $GLOBALS['language']->language) {
    // Check existence of TinyMCE core language file.
    if (file_exists($context['editor']['library path'] .'/langs/'. $GLOBALS['language']->language .'.js')) {
      // Check existence of TinyMCE theme language file.
      if (file_exists($context['editor']['library path'] .'/themes/'. $context['theme'] .'/langs/'. $GLOBALS['language']->language .'.js')) {
        $settings['language'] = $GLOBALS['language']->language;
      }
    }
  }
}
NaX’s picture

Thanks markus_petrux you saved we working this out myself.

This is how I ended up doing it. It includes language direction because I needed Arabic, but for it to work it looks like you need to enable the Right-to-left and Left-to-right plugins/button that seem to come from the directionality plugin.

/**
* Implementation of hook_wysiwyg_editor_settings_alter().
*
* Tell TinyMCE to use the current language if it is installed.
*
* @todo You may need to change the file checking logic to add support for other editors.
*/
function myModule_wysiwyg_editor_settings_alter(&$settings, $context) {
  $lang = $GLOBALS['language']->language;
  // TinyMCE uses the old language code
  if ($lang == 'zh-hans') {
    $lang = 'zh';
  }
  $direction = $GLOBALS['language']->direction == LANGUAGE_RTL ? 'rtl' : 'ltr';
  if ($settings['language'] != $lang) {
    // Check existence of TinyMCE core language file.
    if (file_exists($context['editor']['library path'] .'/langs/'. $lang .'.js')) {
      // Check existence of TinyMCE theme language file.
      if (file_exists($context['editor']['library path'] .'/themes/'. $context['theme'] .'/langs/'. $lang .'.js')) {
        $settings['language'] = $lang;
        $settings['directionality'] = $direction;
      }
    }
  }
}
zilverdistel’s picture

subscribing

twod’s picture

attiks’s picture

Thanks @markus_petrux and @NaX works like a charm even for chinese

stevieegee’s picture

Version: 6.x-2.x-dev » 7.x-2.2

Hi All

I used @NaX's code on Wysiwyg 7.x-2.2 and it worked a treat. The only change I did, was due to TinyMCE now having codes zh-cn for Simplified Chinese and zh-tw for Traditional Chinese.

Thank you all for your help.

Stephen