Select the FCKEditor language - full exampleSelect the FCKEditor language - full example

Posted June 28th, 2009 in FCKEditor

I had an email from someone asking about my "Select the interface language in FCKEditor from a select box" post and where they should put the Javascript and drop down box. This post shows the full PHP page required to display the FCKEditor with language selection drop down boxes.

The code does not contain the necessary work to save it to the database; it just shows how to have all the elements in your page.

A working example (using FCKEditor 2.6.2) can be found here.

And here is the code behind that page:

<html>
<head>
<title>FCKEditor Change Language Example</title>
<script language="javascript">

function FCKeditor_OnComplete(editor) {
   
    var select = document.getElementById("languages");
    for(lang in editor.Language.AvailableLanguages) {
        select.options[select.options.length] =
          new Option(editor.Language.AvailableLanguages[lang], lang);
    }
    select.value = editor.Language.ActiveLanguage.Code;
  
}

function change_language(lang) {
    window.location.href = window.location.pathname + "?lang=" + lang ;
}

</script>
</head>

<body>

<select id="languages" onchange="change_language(this.value);">
</select>
<?php

require_once('fckeditor/fckeditor.php');

$oFCKeditor = new FCKeditor('html');
if(isset($_GET['lang'])) {
    $oFCKeditor->Config['AutoDetectLanguage'] = false ;
    $oFCKeditor->Config['DefaultLanguage'] = $_GET['lang'] ;
}
else {
    $oFCKeditor->Config['AutoDetectLanguage'] = true ;
    $oFCKeditor->Config['DefaultLanguage'] = 'en' ;
}
$oFCKeditor->Create();

?>

</body>
</html>

Related posts:

Share or Bookmark

Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.

Subscribe or Follow

Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

Comments

blog comments powered by Disqus