UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

66 lines (42 loc) 1.8 kB
import {expect} from "chai" import {Formatter} from "../../../source/i18n/formatter.mjs"; import {Translations} from "../../../source/i18n/translations.mjs"; describe('Formatter', function () { describe('example', function () { it('should run with marker', function () { const translations = new Translations('en') .assignTranslations({ thekey: "${animal} has eaten the ${food}!" }); const f = new Formatter({}, translations); expect(f.format("i18n{thekey::animal=dog::food=cake}")).to.be.equal('dog has eaten the cake!'); // ↦ dog has eaten the cake! }); it('should run without marker', function () { const translations = new Translations('en') .assignTranslations({ thekey: "${animal} has eaten the ${food}!" }); // missing marker expect(new Formatter({}, translations).format("thekey::animal=dog::food=cake")).to.be.equal('dog has eaten the cake!'); // ↦ dog has eaten the cake! }); }); describe('format', function () { [ ['i18n{translationkey::a=3::b=5}', 'test is 3 and 5'], ].forEach(function (data) { let a = data.shift() let b = data.shift() it('format ' + a + ' should ' + b, function () { const translations = new Translations('de').assignTranslations({ translationkey: "test is ${a} and ${b}" }) expect( new Formatter({}, translations).format(a) ).to.equal(b) }); }); }) }) ;