Skip to content

Commit

Permalink
fix fallbackLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
rehhouari committed Oct 22, 2021
1 parent f1984a5 commit b29a025
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,12 +76,13 @@ 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
[0.0.3]: https://github.com/pinecone-router/router/compare/0.0.2...0.0.3
[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
[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
2 changes: 1 addition & 1 deletion packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 8 additions & 14 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b29a025

Please sign in to comment.