diff --git a/CHANGELOG.md b/CHANGELOG.md index f90400b..4d3f899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [3.7.3](https://github.com/kaisermann/svelte-i18n/compare/v3.4.0...v3.7.3) (2023-09-03) + +### Bug Fixes + +* use IntlMessageFormat.resolveLocale ([2e42e58](https://github.com/kaisermann/svelte-i18n/commit/2e42e58d2f9e30000d3f1eebd98498ec27203528)) + + + ## [3.7.2](https://github.com/kaisermann/svelte-i18n/compare/v3.4.0...v3.7.2) (2023-09-03) diff --git a/jest.config.js b/jest.config.js index 7e02856..f038dae 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,11 +7,6 @@ module.exports = { // [...] preset: 'ts-jest/presets/default-esm', // or other ESM presets transform: { - '\\.ts$': [ - 'ts-jest', - { - useESM: true, - }, - ], + '\\.ts$': ['ts-jest', { useESM: true }], }, }; diff --git a/package.json b/package.json index 8edcb61..0daef11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n", - "version": "3.7.2", + "version": "3.7.3", "main": "dist/runtime.cjs.js", "module": "dist/runtime.esm.js", "types": "dist/runtime.d.ts", @@ -88,7 +88,6 @@ "typescript": "^5.2.2" }, "dependencies": { - "@formatjs/intl-getcanonicallocales": "^2.2.1", "cli-color": "^2.0.3", "deepmerge": "^4.2.2", "esbuild": "^0.19.2", diff --git a/src/runtime/configs.ts b/src/runtime/configs.ts index d4277b2..aa3c264 100644 --- a/src/runtime/configs.ts +++ b/src/runtime/configs.ts @@ -1,4 +1,4 @@ -import { getCanonicalLocales } from '@formatjs/intl-getcanonicallocales'; +import IntlMessageFormat from 'intl-messageformat'; import { $locale, getCurrentLocale, getPossibleLocales } from './stores/locale'; import { hasLocaleQueue } from './modules/loaderQueue'; @@ -84,14 +84,14 @@ export function init(opts: ConfigureOptionsInit) { if (opts.initialLocale) { try { - const canonicalizedLocale = getCanonicalLocales(opts.initialLocale); - - // Ensure the passed locale is in the canonical form - if (canonicalizedLocale.length >= 1) { - initialLocale = canonicalizedLocale[0]; + if (IntlMessageFormat.resolveLocale(opts.initialLocale)) { + initialLocale = opts.initialLocale; } - // eslint-disable-next-line no-empty - } catch (e) {} + } catch { + console.warn( + `[svelte-i18n] The initial locale "${opts.initialLocale}" is not a valid locale.`, + ); + } } if (rest.warnOnMissingMessages) { diff --git a/test/runtime/stores/formatters.test.ts b/test/runtime/stores/formatters.test.ts index 3444022..d4c400f 100644 --- a/test/runtime/stores/formatters.test.ts +++ b/test/runtime/stores/formatters.test.ts @@ -68,7 +68,7 @@ describe('format message', () => { }); it('formats a message with interpolated values and invalid initial locale', () => { - init({ fallbackLocale: 'en', initialLocale: '()' }); + init({ fallbackLocale: 'en', initialLocale: '(definitely-not-valid)' }); expect(formatMessage({ id: 'photos', values: { n: 0 } })).toBe( 'You have no photos.',