8
0

translation-service.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @license Copyright (c) 2003-2019, 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. afterEach( () => {
  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 use provided language if only one is provided', () => {
  36. add( 'pl', {
  37. 'OK': 'OK',
  38. 'Cancel [context: reject]': 'Anuluj'
  39. } );
  40. const translation = translate( 'de', 'Cancel [context: reject]' );
  41. expect( translation ).to.be.equal( 'Anuluj' );
  42. } );
  43. it( 'should be able to merge translations', () => {
  44. add( 'pl', {
  45. 'OK': 'OK',
  46. 'Cancel [context: reject]': 'Anuluj'
  47. } );
  48. add( 'en_US', {
  49. 'OK': 'OK',
  50. 'Cancel [context: reject]': 'Cancel'
  51. } );
  52. const translationPL = translate( 'pl', 'Cancel [context: reject]' );
  53. const translationEN = translate( 'en', 'Cancel [context: reject]' );
  54. expect( translationPL ).to.be.equal( 'Anuluj' );
  55. expect( translationEN ).to.be.equal( 'Cancel' );
  56. } );
  57. } );