Open simongiesen opened 4 months ago
it turns out that localization can be applied via CSS:
<style>
.ql-snow .ql-tooltip::before {
content: "URL besuchen:" !important;
}
.ql-snow .ql-tooltip input[type=text]::placeholder {
content: "https://www.beispiel.de";
}
.ql-snow .ql-tooltip a.ql-action::after {
content: 'Bearbeiten' !important;
}
.ql-snow .ql-tooltip a.ql-remove::before {
content: 'Entfernen' !important;
}
.ql-snow .ql-tooltip.ql-editing a.ql-action::after {
content: 'Speichern' !important;
}
.ql-snow .ql-tooltip[data-mode=link]::before {
content: "Link eingeben:" !important;
}
.ql-snow .ql-tooltip[data-mode=formula]::before {
content: "Formel eingeben:" !important;
}
.ql-snow .ql-tooltip[data-mode=video]::before {
content: "Video-URL eingeben:" !important;
}
/* Zusätzliche Stile für bessere Anpassung */
.ql-snow .ql-tooltip input[type=text] {
width: 200px; /* Breite anpassen, falls nötig */
}
.ql-snow .ql-tooltip a.ql-preview {
max-width: 250px; /* Maximale Breite für Vorschau-Links anpassen */
}
</style>
Yeah, it's kind of crazy.
But don't rely on !important
. Create a separate file with the css class and then connect it during initialization, so your solution will be more flexible. Although with things like embed url
placeholder
it won't work...
This example reproduces a case with a translation into Russian and modification of the Font size
representation.
Quill doesn't seem to have any awareness for multi-lingual use or for screen-reader suitability.
I use these for tooltips and labels, each get passed an array of tuples where the first tuple element is a css selector and the second a string display value:
// set titles on toolbar buttons - multilang support
addTooltips(tooltips) {
if (tooltips) {
tooltips.map(([selector, tooltip]) => {
try {
this.toolbarContainer.querySelectorAll(selector).forEach(element => {
element.setAttribute('title', tooltip);
});
} catch (error) {
console.warn(`Quill Tooltips - Invalid selector: ${selector}. Error: ${error.message}`);
}
});
}
}
// set labels on toolbar items - multilang support for dropdown items such as font/heading size
replaceLabels(labels) {
if (labels) {
try {
const style = document.createElement('style');
style.innerHTML = labels.map(([selector, label]) => {
return `${selector} { content: '${label}' !important; }`;
}).join(' ');
document.head.appendChild(style);
} catch (error) {
console.warn(`Quill Toolbar Labels - Error: ${error.message}`);
}
}
}
And also for button icons:
replaceButtonIcons(buttonIcons) {
if (buttonIcons) {
buttonIcons.map(([selector, svg]) => {
try {
this.toolbarContainer.querySelectorAll(selector).forEach(element => {
element.innerHTML = svg;
});
} catch (error) {
console.warn(`Quill ButtonIcons - Invalid selector: ${selector}. Error: ${error.message}`);
}
});
}
}
Where buttonIcons is an array of tuples of selector + svg
Recently, it came out that it is extremely unsatisfying using locals with Quill.
I am using the new Quill 2.x WYSIWYG editor. I am trying to implement german localization. Here is my approach so far:
const de = { 'ui': { 'font': 'Schriftart', 'size': 'Größe', 'bold': 'Fett', 'italic': 'Kursiv', 'underline': 'Unterstrichen', 'strike': 'Durchgestrichen', 'color': 'Farbe', 'background': 'Hintergrund', 'script': 'Skript', 'header': 'Überschrift', 'blockquote': 'Zitat', 'code-block': 'Codeblock', 'indent': 'Einrücken', 'list': 'Liste', 'direction': 'Textrichtung', 'link': 'Link', 'image': 'Bild', 'video': 'Video', 'formula': 'Formel', }, 'tooltips': { 'bold': 'Fett', 'italic': 'Kursiv', 'underline': 'Unterstrichen', 'strike': 'Durchgestrichen', 'color': 'Textfarbe', 'background': 'Hintergrundfarbe', 'header': 'Überschrift', 'font': 'Schriftart', 'size': 'Schriftgröße', 'link': 'Link einfügen', 'image': 'Bild einfügen', 'blockquote': 'Zitat', 'code-block': 'Codeblock', 'indent': { '+1': 'Einrücken', '-1': 'Ausrücken' }, 'align': { 'center': 'Zentriert ausrichten', 'right': 'Rechts ausrichten', 'justify': 'Blocksatz' }, 'list': { 'ordered': 'Nummerierte Liste', 'bullet': 'Aufzählungsliste' }, 'direction': 'Textrichtung', 'link': 'Link einfügen', 'formula': 'Formel einfügen' }, 'placeholder': 'Geben Sie hier Ihren Text ein...', 'missing': { 'image': 'Bildbeschreibung', 'link': 'Wohin soll dieser Link führen?' }, 'action': { 'apply': 'Anwenden', 'cancel': 'Abbrechen' } };
var quill = new Quill('#editorRisikobewertung', { modules: { toolbar: [ [{ header: [1, 2, false] }], ['bold', 'italic', 'underline'], ['link', 'blockquote', 'code-block'], [{ 'list': 'ordered'}, { 'list': 'bullet' }] ], },
language: 'de', i18n: { de }, theme: 'snow'
}); Somehow I am missing the point, can you help me out? Nothing happens, the locales are not applied. What is the best approach to implement localization for Quill? I find nothing detailed in the Knowledge Base.
BTW:
it does not make any difference it is just not working.