Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace canonical lib #229

Merged
merged 4 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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