Skip to content

Commit

Permalink
Replace canonical lib (#229)
Browse files Browse the repository at this point in the history
* fix: use IntlMessageFormat.resolveLocale

* 3.7.3-0

* 3.7.3

* chore: update changelog
  • Loading branch information
kaisermann authored Sep 3, 2023
1 parent a029de6 commit c903ec0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
7 changes: 1 addition & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
},
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/runtime/configs.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/stores/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit c903ec0

Please sign in to comment.