Skip to content

Errors

To help while developing, Two-Mi18n throws errors when something is wrong. They are all prefixed with the text [Two-Mi18n].

Validation of the translation object.

Too help validating the translation object, some errors are thrown in the constructor of TwoMi18n.

The translations object is not defined.

This error is thrown when the translation object is not defined.

const twoMi18n = new TwoMi18n();
// Error: [Two-Mi18n] Something is wrong with the translation object:
// The translations object is not defined.

The ‘default’ property is not defined.

This error is thrown when the default property is not defined in the translation object. The default property is required.

Example:

const translations = {
en: {
hello: "Hello",
},
fr: {
hello: "Bonjour",
},
};
const twoMi18n = new TwoMi18n(translations);
// Error: [Two-Mi18n] Something is wrong with the translation object:
// The 'default' property is not defined.

The default language “x” is not defined in the translations object.

This error is thrown when the default language is not defined in the translation object.

const translations = {
default: "en",
fr: {
hello: "Bonjour",
},
};
const twoMi18n = new TwoMi18n(translations);
// Error: [Two-Mi18n] Something is wrong with the translation object:
// The default language "en" is not defined in the translations object.

No language specified

This error is thrown when no language is passed in parameter of the methods translate or translateHTML.

twoMi18n.translate("hello" /*, ... */);
// Error: [Two-Mi18n] No language specified.
twoMi18n.translateHTML(/* ... */);
// Error: [Two-Mi18n] No language specified.