mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 18:10:43 +01:00
chore: remove unused methods
This commit is contained in:
parent
5db1dbc3a4
commit
4cc2088bef
@ -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('-')
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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([
|
||||
|
Loading…
Reference in New Issue
Block a user