Conversation
Comandeer
left a comment
There was a problem hiding this comment.
The overall logic looks good, there is only a small issue with outputting the [lang] attribute – see my inline comments for more details.
| } ); | ||
| }, | ||
|
|
||
| 'test adds the default editor lang code to the Styles combo box item if it is not defined': function() { |
There was a problem hiding this comment.
This test fails in my browser:
Values should be the same.
Expected: en (string)
Actual: en-gb (string)
It would probably be better to set the language to one with a low probability of usage in our team and one different than config.defaultLanguage – that's how we will have the certainty that the fallback really works.
| bender.editorBot.create( { | ||
| name: 'cb_2', | ||
| config: { | ||
| lang: 'en', |
There was a problem hiding this comment.
| lang: 'en', | |
| language: 'en', |
| resultElement.setHtml( '' ); | ||
|
|
||
| CKEDITOR.tools.array.forEach( panelItems, function( element, index ) { | ||
| resultElement.appendHtml( 'Item ' + index + ': ' + JSON.stringify( element.getAttributes() ) + '</br></br>' ); |
There was a problem hiding this comment.
The dump of all attributes in the JSON format is quite unreadable. Maybe just display the value of the [lang] attribute?
There was a problem hiding this comment.
Sure. Changed.
plugins/listblock/plugin.js
Outdated
| ' draggable="false"' + | ||
| ' ondragstart="return false;"' + // Draggable attribute is buggy on Firefox. | ||
| ' href="javascript:void(\'{val}\')" ' + | ||
| ' lang="{language}"' + |
There was a problem hiding this comment.
Adding the language directly in the listblock template results in outputting this attribute in each place that uses the listblock – so if the language is not set, the [lang="{language}"] will be generated (you can see it e.g. in Font dropdown).
plugins/listblock/plugin.js
Outdated
| if ( language ) { | ||
| data.language = language; | ||
| } |
There was a problem hiding this comment.
Probably the logic that fallbacks to the editor's language should be moved here to always output the correct [lang] attribute in various toolbar buttons.
KarolDawidziuk
left a comment
There was a problem hiding this comment.
Thank you @Comandeer for the review!
I've applied the changes mentioned in your inline comment and PR is ready for another review.
| resultElement.setHtml( '' ); | ||
|
|
||
| CKEDITOR.tools.array.forEach( panelItems, function( element, index ) { | ||
| resultElement.appendHtml( 'Item ' + index + ': ' + JSON.stringify( element.getAttributes() ) + '</br></br>' ); |
There was a problem hiding this comment.
Sure. Changed.
Comandeer
left a comment
There was a problem hiding this comment.
@KarolDawidziuk, thx for your changes! However, I'm wondering if we couldn't simplify our approach (see my inline comments for more details).
plugins/listblock/plugin.js
Outdated
| proto: { | ||
| add: function( value, html, title ) { | ||
| var id = CKEDITOR.tools.getNextId(); | ||
| add: function( value, html, title, language, editor ) { |
There was a problem hiding this comment.
Five parameters are probably too many.
I'm wondering if we could replace the added ones with the options object pattern:
| add: function( value, html, title, language, editor ) { | |
| add: function( value, html, title, options ) { | |
| options = CKEDITOR.object.merge( someDefaultOptions, options ); |
The second idea I had: maybe we could pass the editor to the list block constructor and save it as this._.editor? However, I'm not sure if a list block instance can't be reused in another editor 🤔
I see even two more solutions, probably even easier ones:
- pass only possible language fallbacks (so basically
editor.langCode) instead of the whole editor, - add the
[lang]attribute only if it's known; it's absence should make the screen reader use the nearest available value – so the editor's container[lang]attribute.
There was a problem hiding this comment.
Thanks for the ideas 👍
Let's go with applying the lang attribute when it's defined.
plugins/listblock/plugin.js
Outdated
| editorLanguage = editor.config.language || | ||
| editor.config.defaultLanguage || | ||
| editor.langCode; |
There was a problem hiding this comment.
Do we need so many options? Couldn't we use just editor.langCode? It should contain the actual language of the editor.
There was a problem hiding this comment.
Removed as we changed our approach.
plugins/listblock/plugin.js
Outdated
| title: CKEDITOR.tools.htmlEncodeAttr( title || value ), | ||
| text: html || value | ||
| text: html || value, | ||
| language: language || editorLanguage |
There was a problem hiding this comment.
If we go with the "add the [lang] attribute only if it's known" approach, then we could add the whole markup here (similar to what we do in the button plugin).
| * Item 0 should have the lang attribute set to `pl`. | ||
| * Item 1 should have the `lang` attribute set to the editor language value. |
There was a problem hiding this comment.
| * Item 0 should have the lang attribute set to `pl`. | |
| * Item 1 should have the `lang` attribute set to the editor language value. | |
| * Item 1 should have the lang attribute set to `pl`. | |
| * Item 2 should have the `lang` attribute set to the editor language value. |
Additionally, in my case the editor is en-gb but the second item is en 🤔 I don't know why as the code suggests they should be the same.
There was a problem hiding this comment.
Fixed. I added lang instead of language in the editor config.
|
Thanks @Comandeer for the review! It's ready for another one. |
Comandeer
left a comment
There was a problem hiding this comment.
LGTM! I've just updated the manual test description as it became outdated.
What is the purpose of this pull request?
New feature
Does your PR contain necessary tests?
All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
Did you follow the CKEditor 4 code style guide?
Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.
What is the proposed changelog entry for this pull request?
What changes did you make?
PR adds the ability to set the language of the Styles dropdown elements. When the language is not explicitly set, the same language as the editor will be added.
Which issues does your PR resolve?
Closes #5410.