diff --git a/src/runtime/stores/locale.ts b/src/runtime/stores/locale.ts index 7888736..528ea6f 100644 --- a/src/runtime/stores/locale.ts +++ b/src/runtime/stores/locale.ts @@ -8,18 +8,6 @@ import { $isLoading } from './loading'; let current: string; const $locale = writable(null); -export function isFallbackLocale(localeA: string, localeB: string) { - return localeB.indexOf(localeA) === 0 && localeA !== localeB; -} - -export function isRelatedLocale(localeA: string, localeB: string) { - return ( - localeA === localeB || - isFallbackLocale(localeA, localeB) || - isFallbackLocale(localeB, localeA) - ); -} - function getSubLocales(refLocale: string) { return refLocale .split('-') diff --git a/test/runtime/includes/lookup.test.ts b/test/runtime/includes/lookup.test.ts index e4cf6b7..02f69e4 100644 --- a/test/runtime/includes/lookup.test.ts +++ b/test/runtime/includes/lookup.test.ts @@ -25,12 +25,20 @@ test('gets a deep message of a locale dictionary', () => { expect(lookup('deep.field', 'en')).toBe('lastname'); }); -test('gets a message from the fallback dictionary', () => { +test('gets a message from a generic fallback dictionary', () => { addMessages('en', { field: 'name' }); expect(lookup('field', 'en-US')).toBe('name'); }); +test('gets a message from a specific fallback dictionary', () => { + init({ fallbackLocale: 'en-GB' }); + + addMessages('en-GB', { field: 'name' }); + + expect(lookup('field', 'en-AU')).toBe('name'); +}); + test('gets an array', () => { addMessages('en', { careers: [ @@ -92,11 +100,3 @@ test('clears a locale lookup cache when new messages are added', () => { addMessages('en', { field: 'name2' }); expect(lookup('field', 'en')).toBe('name2'); }); - -test('fallback to fallback locale', () => { - init({ fallbackLocale: 'en-GB', initialLocale: 'en-AU' }); - - addMessages('en-GB', { field: 'name' }); - - expect(lookup('field', 'en-AU')).toBe('name'); -}); diff --git a/test/runtime/stores/locale.test.ts b/test/runtime/stores/locale.test.ts index 2b973e9..05642c3 100644 --- a/test/runtime/stores/locale.test.ts +++ b/test/runtime/stores/locale.test.ts @@ -2,11 +2,9 @@ import { get } from 'svelte/store'; import { lookup } from '../../../src/runtime/includes/lookup'; import { - isFallbackLocale, getPossibleLocales, getCurrentLocale, $locale, - isRelatedLocale, } from '../../../src/runtime/stores/locale'; import { getOptions, init } from '../../../src/runtime/configs'; import { register, isLoading } from '../../../src/runtime'; @@ -22,20 +20,6 @@ test('sets and gets the fallback locale', () => { expect(getOptions().fallbackLocale).toBe('en'); }); -test('checks if a locale is a fallback locale of another locale', () => { - expect(isFallbackLocale('en', 'en-US')).toBe(true); - expect(isFallbackLocale('en', 'en')).toBe(false); - expect(isFallbackLocale('it', 'en-US')).toBe(false); -}); - -test('checks if a locale is a related locale of another locale', () => { - expect(isRelatedLocale('en', 'en-US')).toBe(true); - expect(isRelatedLocale('pt-BR', 'pt')).toBe(true); - expect(isRelatedLocale('en', 'en')).toBe(true); - expect(isRelatedLocale('en', 'it-IT')).toBe(false); - expect(isRelatedLocale('en-US', 'it')).toBe(false); -}); - test('gets all possible locales from a reference locale', () => { expect(getPossibleLocales('en-US')).toEqual(['en-US', 'en']); expect(getPossibleLocales('az-Cyrl-AZ')).toEqual([