Project:Wysiwyg
Version:6.x-2.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed

Issue Summary

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.

AttachmentSize
wysiwyg.language.patch1.93 KB

Comments

#1

Status:needs work» postponed

This is blocked by #362318: Limit wysiwyg language selection to available languages

#2

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

#3

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

<?php
/**
* 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;
      }
    }
  }
}
?>

#4

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.

<?php
/**
* 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;
      }
    }
  }
}
?>

#5

subscribing

#6

#7

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

nobody click here