Sfoglia il codice sorgente

Other: Fix localization support.

Maciej Gołaszewski 8 anni fa
parent
commit
bfec1144ee

+ 10 - 0
packages/ckeditor5-font/lang/contexts.json

@@ -0,0 +1,10 @@
+{
+	"Font Size": "Tooltip for the font size drop-down.",
+	"Normal": "Drop-down option label for the normal font size.",
+	"Tiny": "Drop-down option label for the 'tiny' font size preset.",
+	"Small": "Drop-down option label for the 'small' font size preset.",
+	"Big": "Drop-down option label for the 'big' font size preset.",
+	"Huge": "Drop-down option label for the 'huge' font size preset.",
+	"Font Family": "Tooltip for the font family drop-down.",
+	"Default": "Drop-down option label for the default font family."
+}

+ 38 - 0
packages/ckeditor5-font/lang/translations/pl.po

@@ -0,0 +1,38 @@
+# Copyright (c) Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+msgid ""
+msgstr ""
+"Language: pl\n"
+"Language-Team: Polish (https://www.transifex.com/ckeditor/teams/11143/pl/)\n"
+"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && (n%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n"
+
+msgctxt "Tooltip for the font size drop-down."
+msgid "Font Size"
+msgstr "Rozmiar czcionki"
+
+msgctxt "Drop-down option label for the normal font size."
+msgid "Normal"
+msgstr "Normalny"
+
+msgctxt "Drop-down option label for the 'tiny' font size preset."
+msgid "Tiny"
+msgstr "Tyci"
+
+msgctxt "Drop-down option label for the 'small' font size preset."
+msgid "Small"
+msgstr "Mały"
+
+msgctxt "Drop-down option label for the 'big' font size preset."
+msgid "Big"
+msgstr "Duży"
+
+msgctxt "Drop-down option label for the 'huge' font size preset."
+msgid "Huge"
+msgstr "Ogromny"
+
+msgctxt "Tooltip for the font family drop-down."
+msgid "Font Family"
+msgstr "Czcionka"
+
+msgctxt "Drop-down option label for the default font family."
+msgid "Default"
+msgstr "Domyślna"

+ 3 - 13
packages/ckeditor5-font/src/fontfamily/fontfamilyui.js

@@ -95,22 +95,12 @@ export default class FontFamilyUI extends Plugin {
 		const editor = this.editor;
 		const t = editor.t;
 
-		const localizedTitles = {
-			Default: t( 'Default' ),
-			Tiny: t( 'Tiny' ),
-			Small: t( 'Small' ),
-			Big: t( 'Big' ),
-			Huge: t( 'Huge' )
-		};
-
 		const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) );
 
 		return options.map( option => {
-			const title = localizedTitles[ option.title ];
-
-			if ( title && title != option.title ) {
-				// Clone the option to avoid altering the original `config.fontFamily.options`.
-				option = Object.assign( {}, option, { title } );
+			// The only title to localize is "Default" others are font names.
+			if ( option.title === 'Default' ) {
+				option.title = t( 'Default' );
 			}
 
 			return option;

+ 2 - 1
packages/ckeditor5-font/src/fontsize/fontsizeui.js

@@ -91,6 +91,7 @@ export default class FontSizeUI extends Plugin {
 		const t = editor.t;
 
 		const localizedTitles = {
+			Normal: t( 'Normal' ),
 			Tiny: t( 'Tiny' ),
 			Small: t( 'Small' ),
 			Big: t( 'Big' ),
@@ -103,7 +104,7 @@ export default class FontSizeUI extends Plugin {
 			const title = localizedTitles[ option.title ];
 
 			if ( title && title != option.title ) {
-				// Clone the option to avoid altering the original `config.fontSize.options`.
+				// Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
 				option = Object.assign( {}, option, { title } );
 			}
 

+ 62 - 0
packages/ckeditor5-font/tests/fontfamily/fontfamilyui.js

@@ -12,12 +12,29 @@ import fontFamilyIcon from '../../theme/icons/font-family.svg';
 
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
 
 testUtils.createSinonSandbox();
 
 describe( 'FontFamilyUI', () => {
 	let editor, command, element;
 
+	before( () => {
+		addTranslations( 'en', {
+			'Font Family': 'Font Family',
+			'Default': 'Default'
+		} );
+
+		addTranslations( 'pl', {
+			'Font Family': 'Czcionka',
+			'Default': 'Domyślna'
+		} );
+	} );
+
+	after( () => {
+		clearTranslations();
+	} );
+
 	beforeEach( () => {
 		element = document.createElement( 'div' );
 		document.body.appendChild( element );
@@ -81,5 +98,50 @@ describe( 'FontFamilyUI', () => {
 				expect( dropdown.buttonView.isEnabled ).to.be.true;
 			} );
 		} );
+
+		describe( 'localization', () => {
+			beforeEach( () => {
+				return localizedEditor( [ 'default', 'Arial' ] );
+			} );
+
+			it( 'works for the #buttonView', () => {
+				const buttonView = dropdown.buttonView;
+
+				expect( buttonView.tooltip ).to.equal( 'Czcionka' );
+			} );
+
+			it( 'works for the listView#items in the panel', () => {
+				const listView = dropdown.listView;
+
+				expect( listView.items.map( item => item.label ) ).to.deep.equal( [
+					'Domyślna',
+					'Arial'
+				] );
+			} );
+
+			function localizedEditor( options ) {
+				const editorElement = document.createElement( 'div' );
+				document.body.appendChild( editorElement );
+
+				return ClassicTestEditor
+					.create( editorElement, {
+						plugins: [ FontFamilyEditing, FontFamilyUI ],
+						toolbar: [ 'fontFamily' ],
+						language: 'pl',
+						fontFamily: {
+							options
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						dropdown = editor.ui.componentFactory.create( 'fontFamily' );
+						command = editor.commands.get( 'fontFamily' );
+
+						editorElement.remove();
+
+						return editor.destroy();
+					} );
+			}
+		} );
 	} );
 } );

+ 85 - 0
packages/ckeditor5-font/tests/fontsize/fontsizeui.js

@@ -12,12 +12,38 @@ import fontSizeIcon from '../../theme/icons/font-size.svg';
 
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import { _clear as clearTranslations, add as addTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
+import { normalizeOptions } from '../../src/fontsize/utils';
 
 testUtils.createSinonSandbox();
 
 describe( 'FontSizeUI', () => {
 	let editor, command, element;
 
+	before( () => {
+		addTranslations( 'en', {
+			'Font Size': 'Font Size',
+			'Normal': 'Normal',
+			'Tiny': 'Tiny',
+			'Small': 'Small',
+			'Big': 'Big',
+			'Huge': 'Huge'
+		} );
+
+		addTranslations( 'pl', {
+			'Font Size': 'Rozmiar czcionki',
+			'Normal': 'Normalny',
+			'Tiny': 'Tyci',
+			'Small': 'Mały',
+			'Big': 'Duży',
+			'Huge': 'Ogromny'
+		} );
+	} );
+
+	after( () => {
+		clearTranslations();
+	} );
+
 	beforeEach( () => {
 		element = document.createElement( 'div' );
 		document.body.appendChild( element );
@@ -81,5 +107,64 @@ describe( 'FontSizeUI', () => {
 				expect( dropdown.buttonView.isEnabled ).to.be.true;
 			} );
 		} );
+
+		describe( 'localization', () => {
+			beforeEach( () => {
+				return localizedEditor( [ 'tiny', 'small', 'normal', 'big', 'huge' ] );
+			} );
+
+			it( 'does not alter normalizeOptions() internals', () => {
+				const options = normalizeOptions( [ 'tiny', 'small', 'normal', 'big', 'huge' ] );
+				expect( options ).to.deep.equal( [
+					{ title: 'Tiny', model: 'text-tiny', view: { name: 'span', class: 'text-tiny' } },
+					{ title: 'Small', model: 'text-small', view: { name: 'span', class: 'text-small' } },
+					{ title: 'Normal', model: undefined },
+					{ title: 'Big', model: 'text-big', view: { name: 'span', class: 'text-big' } },
+					{ title: 'Huge', model: 'text-huge', view: { name: 'span', class: 'text-huge' } }
+				] );
+			} );
+
+			it( 'works for the #buttonView', () => {
+				const buttonView = dropdown.buttonView;
+
+				expect( buttonView.tooltip ).to.equal( 'Rozmiar czcionki' );
+			} );
+
+			it( 'works for the listView#items in the panel', () => {
+				const listView = dropdown.listView;
+
+				expect( listView.items.map( item => item.label ) ).to.deep.equal( [
+					'Tyci',
+					'Mały',
+					'Normalny',
+					'Duży',
+					'Ogromny'
+				] );
+			} );
+
+			function localizedEditor( options ) {
+				const editorElement = document.createElement( 'div' );
+				document.body.appendChild( editorElement );
+
+				return ClassicTestEditor
+					.create( editorElement, {
+						plugins: [ FontSizeEditing, FontSizeUI ],
+						toolbar: [ 'fontSize' ],
+						language: 'pl',
+						fontSize: {
+							options
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						dropdown = editor.ui.componentFactory.create( 'fontSize' );
+						command = editor.commands.get( 'fontSize' );
+
+						editorElement.remove();
+
+						return editor.destroy();
+					} );
+			}
+		} );
 	} );
 } );