diff --git a/package.json b/package.json index a75878a..5217b9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eartharoid/i18n", - "version": "1.0.3", + "version": "1.0.4", "description": "Simple and lightweight message localisation", "main": "dist/index.js", "types": "types.d.ts", @@ -39,4 +39,4 @@ "lodash.isequal": "^4.5.0", "typescript": "^4.7.4" } -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index bc938fa..90da666 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,6 +88,9 @@ module.exports = class I18n { message: string, ...args: MessageArgs ): string | undefined { + // fallback to default locale if provided one is an empty string + locale ||= this.default_locale; + if (!this.locales.includes(locale)) throw new Error(`A locale with the name of "${locale}" does not exist`); // || instead of ?? as empty strings should fallback