8
0

utils.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module heading/utils
  7. */
  8. /**
  9. * Returns heading options as defined in `config.heading.options` but processed to consider
  10. * the editor localization, i.e. to display {@link module:heading/heading~HeadingOption}
  11. * in the correct language.
  12. *
  13. * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
  14. * when the user configuration is defined because the editor does not exist yet.
  15. *
  16. * @param {module:core/editor/editor~Editor} editor
  17. * @returns {Array.<module:heading/heading~HeadingOption>}.
  18. */
  19. export function getLocalizedOptions( editor ) {
  20. const t = editor.t;
  21. const localizedTitles = {
  22. Paragraph: t( 'Paragraph' ),
  23. 'Heading 1': t( 'Heading 1' ),
  24. 'Heading 2': t( 'Heading 2' ),
  25. 'Heading 3': t( 'Heading 3' ),
  26. 'Heading 4': t( 'Heading 4' ),
  27. 'Heading 5': t( 'Heading 5' ),
  28. 'Heading 6': t( 'Heading 6' )
  29. };
  30. return editor.config.get( 'heading.options' ).map( option => {
  31. const title = localizedTitles[ option.title ];
  32. if ( title && title != option.title ) {
  33. option.title = title;
  34. }
  35. return option;
  36. } );
  37. }