浏览代码

Code refactoring: color config localization.

Aleksander Nowodzinski 6 年之前
父节点
当前提交
bb4db5e1ae
共有 2 个文件被更改,包括 9 次插入8 次删除
  1. 4 2
      packages/ckeditor5-font/src/ui/colorui.js
  2. 5 6
      packages/ckeditor5-font/src/utils.js

+ 4 - 2
packages/ckeditor5-font/src/ui/colorui.js

@@ -11,6 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
 import {
 	addColorTableToDropdown,
+	normalizeOptions,
 	getLocalizedColorOptions
 } from '../utils';
 
@@ -74,14 +75,15 @@ export default class ColorUI extends Plugin {
 		const editor = this.editor;
 		const t = editor.t;
 		const command = editor.commands.get( this.commandName );
-		const options = getLocalizedColorOptions( editor, this.componentName );
+		const colorsConfig = normalizeOptions( editor.config.get( this.componentName ).colors );
+		const localizedColors = getLocalizedColorOptions( editor, colorsConfig );
 
 		// Register UI component.
 		editor.ui.componentFactory.add( this.componentName, locale => {
 			const dropdownView = createDropdown( locale );
 			const colorTableView = addColorTableToDropdown( {
 				dropdownView,
-				colors: options.map( option => ( {
+				colors: localizedColors.map( option => ( {
 					label: option.label,
 					color: option.model,
 					options: {

+ 5 - 6
packages/ckeditor5-font/src/utils.js

@@ -111,18 +111,17 @@ export function addColorTableToDropdown( { dropdownView, colors, columns, remove
 }
 
 /**
- * Returns configuration options as defined in the `editor.config[ featureName ]` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
+ * Returns color configuration options as defined in the `editor.config.(fontColor|fontBackgroundColor).colors`
+ * but processed to account for editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
  * or {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig} in the correct language.
  *
  * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
  * when the user configuration is defined because the editor does not exist yet.
  *
  * @param {module:core/editor/editor~Editor} editor An editor instance.
- * @param {String} featureName Determines which config (`editor.config[ featureName ]`) colors to localize.
- * @returns {Array.<module:font/fontbackgroundcolor~FontBackgroundColorConfig>|Array.<module:font/fontcolor~FontColorConfig>}.
+ * @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}.
  */
-export function getLocalizedColorOptions( editor, featureName ) {
+export function getLocalizedColorOptions( editor, options ) {
 	const t = editor.t;
 	const localizedColorNames = {
 		Black: t( 'Black' ),
@@ -142,7 +141,7 @@ export function getLocalizedColorOptions( editor, featureName ) {
 		Purple: t( 'Purple' )
 	};
 
-	return normalizeOptions( editor.config.get( featureName ).colors ).map( colorOption => {
+	return options.map( colorOption => {
 		const label = localizedColorNames[ colorOption.label ];
 
 		if ( label && label != colorOption.label ) {