Created
September 23, 2020 19:20
-
-
Save davist11/d0630e8e91c8ffa5fd6ebdafd835236b to your computer and use it in GitHub Desktop.
Redactor Language Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($R) { | |
$R.add("plugin", "language", { | |
translations: { | |
en: { | |
language: "Change Language", | |
}, | |
}, | |
init: function (app) { | |
this.app = app; | |
this.opts = app.opts; | |
this.lang = app.lang; | |
this.block = app.block; | |
this.toolbar = app.toolbar; | |
this.options = this.opts.languages; | |
this.currentLangAttr; | |
}, | |
start: function () { | |
var dropdown = {}; | |
for (var key in this.options) { | |
var value = this.options[key]; | |
dropdown[key] = { | |
title: value, | |
api: "plugin.language.set", | |
args: key, | |
}; | |
} | |
var $button = this.toolbar.addButton("language", { | |
title: this.lang.get("language"), | |
}); | |
$button.setIcon('<i class="re-icon-specialcharacters"></i>'); | |
$button.setDropdown(dropdown); | |
}, | |
set: function (lang) { | |
if (!this.currentLangAttr) { | |
this.addAttribute(lang); | |
this.currentLangAttr = lang; | |
} else if (this.currentLangAttr === lang) { | |
this.removeAttribute(); | |
this.currentLangAttr = null; | |
} else { | |
this.removeAttribute(); | |
this.addAttribute(lang); | |
this.currentLangAttr = lang; | |
} | |
}, | |
addAttribute: function (lang) { | |
var args = { | |
attr: { | |
lang: lang, | |
}, | |
}; | |
this.block.set(args); | |
}, | |
removeAttribute: function () { | |
var args = { | |
attr: { | |
lang: this.currentLangAttr, | |
}, | |
}; | |
this.block.toggle(args); | |
}, | |
}); | |
})(Redactor); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"buttons": [ | |
"html", | |
"formatting", | |
"bold", | |
"italic", | |
"unorderedlist", | |
"orderedlist", | |
"link", | |
"image", | |
"video" | |
], | |
"plugins": [ | |
"fullscreen", | |
"video", | |
"language" | |
], | |
"toolbarFixed": true, | |
"languages": { | |
"en-US": "English (US)", | |
"en-GB": "English (GB)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spinning up a craft site locally and adding the plugin is likely the easiest method for testing. Not really a whole lot to test though...