Skip to content
Open
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
26 changes: 0 additions & 26 deletions src/hooks/useLanguage.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,19 @@
import { useCallback, useEffect, useState } from 'preact/hooks';
import {
ConsentManagerSupportedTranslationValue,
LocaleValue,

Check failure on line 4 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

'LocaleValue' is declared but its value is never read.
LOCALE_KEY,
LOCALE_TRANSLATION_MAP,

Check failure on line 6 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

'LOCALE_TRANSLATION_MAP' is declared but its value is never read.
TranslatedMessages,
Translations,
} from '@transcend-io/internationalization';
import { settings } from '../settings';
import { getUserLocales } from '../utils/get-user-locales';

Check failure on line 11 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find module '../utils/get-user-locales' or its corresponding type declarations.
import { substituteHtml } from '../utils/substitute-html';
import { invertSafe } from '@transcend-io/type-utils';

Check failure on line 13 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

'invertSafe' is declared but its value is never read.

export const loadedTranslations: Translations = Object.create(null);

/** Mapping of AWS base translation keys to list of Transcend locales that should use them */
export const INVERTED_TRANSLATE_LOCALE = invertSafe(LOCALE_TRANSLATION_MAP);

const getDuplicativeLocales = (lang: LocaleValue): LocaleValue[] =>
INVERTED_TRANSLATE_LOCALE[LOCALE_TRANSLATION_MAP[lang]];

/**
* Get nearest matching locale from a list of supported locales
*
* @param preferred - Sorted locale list in order of most preferable to least preferable
* @param supported - List of supported locales to match from
* @returns Nearest supported locale, sorted by preferred locale list
*/
export const getNearestSupportedLocale = (
preferred: LocaleValue[],
supported: LocaleValue[],
): LocaleValue | undefined => {
// eslint-disable-next-line no-restricted-syntax
for (const preferredLocale of preferred) {
if (supported.includes(preferredLocale)) {
return preferredLocale;
}
}
return undefined;
};

/**
* Picks a default language for the user
*
Expand All @@ -59,16 +33,16 @@
* e.g. instead of just having en, include en-US, en-GB, en-AU, etc
*/
const extendedSupportedLanguages = supportedLocales.flatMap((lang) =>
getDuplicativeLocales(lang),

Check failure on line 36 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find name 'getDuplicativeLocales'.
);
const nearestExtendedLanguage =
getNearestSupportedLocale(preferredLocales, extendedSupportedLanguages) ||

Check failure on line 39 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find name 'getNearestSupportedLocale'.
LOCALE_KEY.En;

let nearestTranslation = nearestExtendedLanguage;
if (!(supportedLocales as string[]).includes(nearestTranslation)) {
nearestTranslation =
getDuplicativeLocales(nearestTranslation).find((lang) =>

Check failure on line 45 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Parameter 'lang' implicitly has an 'any' type.

Check failure on line 45 in src/hooks/useLanguage.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find name 'getDuplicativeLocales'.
supportedLocales.includes(
lang as ConsentManagerSupportedTranslationValue,
),
Expand Down
23 changes: 0 additions & 23 deletions src/utils/get-user-locales.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/utils/sort-locales-by-preference.ts

This file was deleted.

Loading