Skip to content

Commit

Permalink
reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
eligrey committed Oct 18, 2024
1 parent b901f51 commit 4bda86b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/hooks/useLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,6 @@ export const getNearestSupportedLanguage = (
),
);

/**
* Picks a default language for the user
*
* @param supportedLanguages - Set of supported languages
* @returns the language key of the best default language for this user
*/
export function pickDefaultLanguage(
supportedLanguages: ConsentManagerLanguageKey[],
): ConsentManagerLanguageKey {
if (settings.locale && supportedLanguages.includes(settings.locale)) {
return settings.locale;
}

const preferredLanguages = getUserLanguages();
return (
getNearestSupportedLanguage(preferredLanguages, sortSupportedLanguagesByPreference(supportedLanguages)) ||
ConsentManagerLanguageKey.En
);
}

/**
* Sorts the supported languages by the user's preferences
*
Expand All @@ -120,6 +100,26 @@ export const sortSupportedLanguagesByPreference = (
return rank(a) - rank(b);
});

/**
* Picks a default language for the user
*
* @param supportedLanguages - Set of supported languages
* @returns the language key of the best default language for this user
*/
export function pickDefaultLanguage(
supportedLanguages: ConsentManagerLanguageKey[],
): ConsentManagerLanguageKey {
if (settings.locale && supportedLanguages.includes(settings.locale)) {
return settings.locale;
}

const preferredLanguages = getUserLanguages();
return (
getNearestSupportedLanguage(preferredLanguages, sortSupportedLanguagesByPreference(supportedLanguages)) ||
ConsentManagerLanguageKey.En
);
}

/**
* Fetch message translations
*
Expand Down

0 comments on commit 4bda86b

Please sign in to comment.