From b29a025d33228c2e2fd2546af330e04616bcb6b0 Mon Sep 17 00:00:00 2001 From: Rafik El Hadi Houari Date: Fri, 22 Oct 2021 03:32:47 +0100 Subject: [PATCH] fix fallbackLocale --- CHANGELOG.md | 11 +++++++++-- packages/main/package.json | 2 +- packages/main/src/index.ts | 22 ++++++++-------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af27f16..43b2627 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +## [2.2.0] - 2021-10-22 + +## Fixed + +- Fix fallbackLocale. + ## [2.1.1] - 2021-10-22 ## Fixed @@ -70,7 +76,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - First version -[unreleased]: https://github.com/pinecone-router/router/compare/2.1.1...HEAD +[unreleased]: https://github.com/pinecone-router/router/compare/2.2.0...HEAD [0.0.0]: https://github.com/pinecone-router/router/compare/0.0.0...0.0.0 [0.0.1]: https://github.com/pinecone-router/router/compare/0.0.0...0.0.1 [0.0.2]: https://github.com/pinecone-router/router/compare/0.0.1...0.0.2 @@ -78,4 +84,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [1.0.0]: https://github.com/pinecone-router/router/compare/0.0.3...1.0.0 [2.0.0]: https://github.com/pinecone-router/router/compare/1.0.0...2.0.0 [2.1.0]: https://github.com/pinecone-router/router/compare/2.0.0...2.1.0 -[2.1.0]: https://github.com/pinecone-router/router/compare/2.1.0...2.1.1 \ No newline at end of file +[2.1.1]: https://github.com/pinecone-router/router/compare/2.1.0...2.1.1 +[2.2.0]: https://github.com/pinecone-router/router/compare/2.1.1...2.2.0 \ No newline at end of file diff --git a/packages/main/package.json b/packages/main/package.json index 64c865a..6cd31e9 100755 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -3,7 +3,7 @@ "description": "Internationalization (i18n) support for Alpine.js", "license": "MIT", "author": "Rafik El Hadi Houari", - "version": "2.1.1", + "version": "2.2.0", "repository": { "type": "git", "url": "https://github.com/rehhouari/alpinejs-i18n" diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index e41093b..1524b08 100755 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -2,7 +2,7 @@ const localeChange = new Event('alpine-i18n:locale-change') const i18nReady = new Event('alpine-i18n:ready') const AlpineI18n = { - version: '2.1.1', + version: '2.2.0', /** * setter for the current locale @@ -61,20 +61,14 @@ const AlpineI18n = { * @returns string */ t(name: string, vars?: { [name: string]: any }) { - let message: string = name + let message: string = ''; try { - message = name - .split('.') - .reduce((o, i) => o[i], this.messages[this.locale]); - } catch (error) { - console.warn('AlpineI18n: key ' + name + ' not found. Using fallbackLocale.') - if (this.fallbackLocale.length) { - message = name - .split('.') - .reduce((o, i) => o[i], this.messages[this.fallbackLocale]); - } else { - return name - } + message = name.split(".").reduce((o, i) => o[i], this.messages[this.locale]); + } catch {} + if (!message && this.fallbackLocale.length) { + message = name.split(".").reduce((o, i) => o[i], this.messages[this.fallbackLocale]); + } else if (!message) { + return name; } for (const key in vars) {