translation-service.js 1.7 KB

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