If you're deciding per user per load, you could just use a GET var in the url to hold a localization variable. Then just use the variable when you initialize the CKEditor instance using the language config value.
Of course you need to make sure that you confirm it is a valid localization code, otherwise you may have issues, such as breaking the editor when it sees a non-expected value.
Say you have a url with a variable in it like "http://localhost/ckeditor.html?lang=en". The lang=en is a GET variable, which is accessible in a variety of ways. However, in this case, we will probably use javascript to get that variable, here is a function you can use that I located on Snipplr:
function getUrlVars()
{
var map = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
map[key] = value;
});
return map;
}
So pretty much you can call this function like:
var urlVars = getUrlVars(); //call function
document.write(urlVars["lang"]); //this will write "en" to the document as in the above example
So where does this get us? Well we now have the lang variable from the url, so we can now initialize CKEditor with the lang code:
This will create the editor using the desired language. Put all the pieces together and you get:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
</head>
<body>
<textarea name="editor1"></textarea>
<script type="text/javascript">
window.onload = function ()
{
function getUrlVars()
{
var map = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value)
{
map[key] = value;
});
return map;
}
var urlVars = getUrlVars(); //get the lang from the GET variable "lang"
CKEDITOR.replace("editor1",
{
language: urlVars["lang"]
});
};
</script>
</body>
</html>
Now open that page up and simply append "?lang=en" to the url. Hit enter. Nothing should change. Now try replacing en with de. The language of the editor should change (it did for me ). The good news here is that CKEditor handles this great even without a lang code (meaning it won't break horribly if there is no GET variable named lang).
Re: how to set the localized language dynamically?
If you're deciding per user per load, you could just use a GET var in the url to hold a localization variable. Then just use the variable when you initialize the CKEditor instance using the language config value.
Of course you need to make sure that you confirm it is a valid localization code, otherwise you may have issues, such as breaking the editor when it sees a non-expected value.
Re: how to set the localized language dynamically?
would you show me some code since im new the CKEditor, please?
thanks a lot
Re: how to set the localized language dynamically?
Say you have a url with a variable in it like "http://localhost/ckeditor.html?lang=en". The lang=en is a GET variable, which is accessible in a variety of ways. However, in this case, we will probably use javascript to get that variable, here is a function you can use that I located on Snipplr:
So pretty much you can call this function like:
So where does this get us? Well we now have the lang variable from the url, so we can now initialize CKEditor with the lang code:
This will create the editor using the desired language. Put all the pieces together and you get:
Now open that page up and simply append "?lang=en" to the url. Hit enter. Nothing should change. Now try replacing en with de. The language of the editor should change (it did for me
). The good news here is that CKEditor handles this great even without a lang code (meaning it won't break horribly if there is no GET variable named lang).
Hope it helps, good luck!