8
0

translation-service.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals window */
  6. import { translate, add, _clear } from '../src/translation-service';
  7. describe( 'translation-service', () => {
  8. afterEach( () => {
  9. _clear();
  10. } );
  11. it( 'should return english string if no translation exists', () => {
  12. const translation = translate( 'pl', 'Bold' );
  13. expect( translation ).to.be.equal( 'Bold' );
  14. } );
  15. it( 'should return english string without context if no translation exists', () => {
  16. const translation = translate( 'pl', 'Bold [context: bold]' );
  17. expect( translation ).to.be.equal( 'Bold' );
  18. } );
  19. it( 'should return translation if the translation for the concrete language is defined', () => {
  20. add( 'pl', {
  21. 'OK': 'OK',
  22. 'Cancel [context: reject]': 'Anuluj'
  23. } );
  24. const translation = translate( 'pl', 'Cancel [context: reject]' );
  25. expect( translation ).to.be.equal( 'Anuluj' );
  26. } );
  27. it( 'should return english string without context if the translations for the concrete language exist, ' +
  28. 'but translation doesn\'t', () => {
  29. add( 'pl', {
  30. 'OK': 'OK',
  31. 'Cancel [context: reject]': 'Anuluj'
  32. } );
  33. const translation = translate( 'pl', 'Bold [context: bold]' );
  34. expect( translation ).to.be.equal( 'Bold' );
  35. } );
  36. it( 'should use provided language if only one is provided', () => {
  37. add( 'pl', {
  38. 'OK': 'OK',
  39. 'Cancel [context: reject]': 'Anuluj'
  40. } );
  41. const translation = translate( 'de', 'Cancel [context: reject]' );
  42. expect( translation ).to.be.equal( 'Anuluj' );
  43. } );
  44. it( 'should be able to merge translations', () => {
  45. add( 'pl', {
  46. 'OK': 'OK',
  47. 'Cancel [context: reject]': 'Anuluj'
  48. } );
  49. add( 'en_US', {
  50. 'OK': 'OK',
  51. 'Cancel [context: reject]': 'Cancel'
  52. } );
  53. const translationPL = translate( 'pl', 'Cancel [context: reject]' );
  54. const translationEN = translate( 'en', 'Cancel [context: reject]' );
  55. expect( translationPL ).to.be.equal( 'Anuluj' );
  56. expect( translationEN ).to.be.equal( 'Cancel' );
  57. } );
  58. it( 'should expose `add` function globally', () => {
  59. expect( window.CKEDITOR_TRANSLATIONS ).to.be.an( 'object' );
  60. expect( window.CKEDITOR_TRANSLATIONS.add ).to.be.a( 'function' );
  61. } );
  62. } );