Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 3a92fc4

Browse files
authoredMar 9, 2020
Merge pull request #259 from ckeditor/i/6107
Feature: Brought the support for right–to–left languages to the table and table cell property forms. Closes ckeditor/ckeditor5#6107.
2 parents 3abc494 + b173029 commit 3a92fc4

File tree

7 files changed

+106
-20
lines changed

7 files changed

+106
-20
lines changed
 

‎src/tablecellproperties/ui/tablecellpropertiesview.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ export default class TableCellPropertiesView extends View {
682682
// -- Horizontal ---------------------------------------------------
683683

684684
const horizontalAlignmentToolbar = new ToolbarView( locale );
685+
const isContentRTL = this.locale.contentLanguageDirection === 'rtl';
685686

686687
horizontalAlignmentToolbar.set( {
687688
isCompact: true,
@@ -695,7 +696,7 @@ export default class TableCellPropertiesView extends View {
695696
labels: this._horizontalAlignmentLabels,
696697
propertyName: 'horizontalAlignment',
697698
nameToValue: name => {
698-
return name === 'left' ? '' : name;
699+
return name === ( isContentRTL ? 'right' : 'left' ) ? '' : name;
699700
}
700701
} );
701702

@@ -781,14 +782,20 @@ export default class TableCellPropertiesView extends View {
781782
* @type {Object.<String,String>}
782783
*/
783784
get _horizontalAlignmentLabels() {
785+
const locale = this.locale;
784786
const t = this.t;
785787

786-
return {
787-
left: t( 'Align cell text to the left' ),
788-
center: t( 'Align cell text to the center' ),
789-
right: t( 'Align cell text to the right' ),
790-
justify: t( 'Justify cell text' )
791-
};
788+
const left = t( 'Align cell text to the left' );
789+
const center = t( 'Align cell text to the center' );
790+
const right = t( 'Align cell text to the right' );
791+
const justify = t( 'Justify cell text' );
792+
793+
// Returns object with a proper order of labels.
794+
if ( locale.uiLanguageDirection === 'rtl' ) {
795+
return { right, center, left, justify };
796+
} else {
797+
return { left, center, right, justify };
798+
}
792799
}
793800

794801
/**

‎src/tableproperties/ui/tablepropertiesview.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,19 @@ export default class TablePropertiesView extends View {
681681
* @type {Object.<String,String>}
682682
*/
683683
get _alignmentLabels() {
684+
const locale = this.locale;
684685
const t = this.t;
685686

686-
return {
687-
left: t( 'Align table to the left' ),
688-
center: t( 'Center table' ),
689-
right: t( 'Align table to the right' )
690-
};
687+
const left = t( 'Align table to the left' );
688+
const center = t( 'Center table' );
689+
const right = t( 'Align table to the right' );
690+
691+
// Returns object with a proper order of labels.
692+
if ( locale.uiLanguageDirection === 'rtl' ) {
693+
return { right, center, left };
694+
} else {
695+
return { left, center, right };
696+
}
691697
}
692698
}
693699

‎src/ui/colorinputview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class ColorInputView extends View {
175175

176176
dropdown.buttonView.children.add( colorPreview );
177177

178-
dropdown.panelPosition = 'sw';
178+
dropdown.panelPosition = locale.uiLanguageDirection === 'rtl' ? 'se' : 'sw';
179179
dropdown.panelView.children.add( removeColorButton );
180180
dropdown.panelView.children.add( colorGrid );
181181
dropdown.bind( 'isEnabled' ).to( this, 'isReadOnly', value => !value );

‎tests/manual/rtl.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
99
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
1010

11+
import TableProperties from '../../src/tableproperties';
12+
import TableCellProperties from '../../src/tablecellproperties';
13+
1114
ClassicEditor
1215
.create( document.querySelector( '#editor' ), {
13-
plugins: [ ArticlePluginSet ],
16+
plugins: [ ArticlePluginSet, TableProperties, TableCellProperties ],
1417
language: {
15-
ui: 'en',
16-
content: 'ar'
18+
ui: 'ar',
19+
content: 'en'
1720
},
1821
toolbar: [
1922
'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
2023
],
2124
table: {
22-
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
25+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ],
2326
tableToolbar: [ 'bold', 'italic' ]
2427
}
2528
} )

‎tests/tablecellproperties/ui/tablecellpropertiesview.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ describe( 'table cell properties', () => {
474474
expect( toolbar.ariaLabel ).to.equal( 'Horizontal text alignment toolbar' );
475475
} );
476476

477-
it( 'should bring alignment buttons', () => {
477+
it( 'should bring alignment buttons in the right order (left-to-right UI)', () => {
478478
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
479479
'Align cell text to the left',
480480
'Align cell text to the center',
@@ -487,6 +487,30 @@ describe( 'table cell properties', () => {
487487
] );
488488
} );
489489

490+
it( 'should bring alignment buttons in the right order (right-to-left UI)', () => {
491+
// Creates its own local instances of locale, view and toolbar.
492+
const locale = {
493+
t: val => val,
494+
uiLanguageDirection: 'rtl',
495+
contentLanguageDirection: 'rtl'
496+
};
497+
const view = new TableCellPropertiesView( locale, VIEW_OPTIONS );
498+
const toolbar = view.horizontalAlignmentToolbar;
499+
500+
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
501+
'Align cell text to the right',
502+
'Align cell text to the center',
503+
'Align cell text to the left',
504+
'Justify cell text'
505+
] );
506+
507+
expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
508+
true, false, false, false
509+
] );
510+
511+
view.destroy();
512+
} );
513+
490514
it( 'should change the #horizontalAlignment value', () => {
491515
toolbar.items.last.fire( 'execute' );
492516
expect( view.horizontalAlignment ).to.equal( 'justify' );

‎tests/tableproperties/ui/tablepropertiesview.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ describe( 'table properties', () => {
439439
expect( toolbar.ariaLabel ).to.equal( 'Table alignment toolbar' );
440440
} );
441441

442-
it( 'should bring alignment buttons', () => {
442+
it( 'should bring alignment buttons in the right order (left-to-right UI)', () => {
443443
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
444444
'Align table to the left',
445445
'Center table',
@@ -451,6 +451,29 @@ describe( 'table properties', () => {
451451
] );
452452
} );
453453

454+
it( 'should bring alignment buttons in the right order (right-to-left UI)', () => {
455+
// Creates its own local instances of locale, view and toolbar.
456+
const locale = {
457+
t: val => val,
458+
uiLanguageDirection: 'rtl',
459+
contentLanguageDirection: 'rtl'
460+
};
461+
const view = new TablePropertiesView( locale, VIEW_OPTIONS );
462+
const toolbar = view.alignmentToolbar;
463+
464+
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
465+
'Align table to the right',
466+
'Center table',
467+
'Align table to the left'
468+
] );
469+
470+
expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
471+
false, true, false
472+
] );
473+
474+
view.destroy();
475+
} );
476+
454477
it( 'should change the #horizontalAlignment value', () => {
455478
toolbar.items.last.fire( 'execute' );
456479
expect( view.alignment ).to.equal( 'right' );

‎tests/ui/colorinputview.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ describe( 'ColorInputView', () => {
7373
it( 'should be created', () => {
7474
expect( view._dropdownView ).to.be.instanceOf( DropdownView );
7575
expect( view._dropdownView.buttonView.element.classList.contains( 'ck-input-color__button' ) ).to.be.true;
76-
expect( view._dropdownView.panelPosition ).to.equal( 'sw' );
7776
} );
7877

7978
it( 'should bind #isEnabled to the view\'s #isReadOnly', () => {
@@ -107,6 +106,30 @@ describe( 'ColorInputView', () => {
107106
it( 'should have the remove color button', () => {
108107
expect( view._dropdownView.panelView.children.first ).to.be.instanceOf( ButtonView );
109108
} );
109+
110+
describe( 'position', () => {
111+
it( 'should be SouthWest in LTR', () => {
112+
locale.uiLanguageDirection = 'ltr';
113+
view = new ColorInputView( locale, {
114+
colorDefinitions: DEFAULT_COLORS,
115+
columns: 5
116+
} );
117+
view.render();
118+
119+
expect( view._dropdownView.panelPosition ).to.equal( 'sw' );
120+
} );
121+
122+
it( 'should be SouthEast in RTL', () => {
123+
locale.uiLanguageDirection = 'rtl';
124+
view = new ColorInputView( locale, {
125+
colorDefinitions: DEFAULT_COLORS,
126+
columns: 5
127+
} );
128+
view.render();
129+
130+
expect( view._dropdownView.panelPosition ).to.equal( 'se' );
131+
} );
132+
} );
110133
} );
111134

112135
describe( 'color grid', () => {

0 commit comments

Comments
 (0)
This repository has been archived.