Skip to content

Commit

Permalink
Merge pull request #2 from itzJOHv/main
Browse files Browse the repository at this point in the history
feat: fallback to default locale if provided is empty
  • Loading branch information
eartharoid authored Jun 27, 2022
2 parents 8652421 + ff8e9cc commit 12d83fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -39,4 +39,4 @@
"lodash.isequal": "^4.5.0",
"typescript": "^4.7.4"
}
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12d83fd

Please sign in to comment.