utils.js 1019 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Returns heading options as defined in `config.heading.options` but processed to consider
  3. * editor localization, i.e. to display {@link module:heading/heading~HeadingOption}
  4. * in the correct language.
  5. *
  6. * Note: The reason behind this method is that there's no way to use {@link module:utils/locale~Locale#t}
  7. * when the user config is defined because the editor does not exist yet.
  8. *
  9. * @private
  10. * @returns {Array.<module:heading/heading~HeadingOption>}.
  11. */
  12. export function getLocalizedOptions( editor ) {
  13. const t = editor.t;
  14. const localizedTitles = {
  15. Paragraph: t( 'Paragraph' ),
  16. 'Heading 1': t( 'Heading 1' ),
  17. 'Heading 2': t( 'Heading 2' ),
  18. 'Heading 3': t( 'Heading 3' )
  19. };
  20. return editor.config.get( 'heading.options' ).map( option => {
  21. const title = localizedTitles[ option.title ];
  22. if ( title && title != option.title ) {
  23. // Clone the option to avoid altering the original `config.heading.options`.
  24. option = Object.assign( {}, option, { title } );
  25. }
  26. return option;
  27. } );
  28. }