1 export { getLangAttribute } from '@proton/shared/lib/i18n/helper';
3 export const getLanguage = (locale: string) => locale.split(/[_-]/)[0];
5 const localeMapping = {
12 const getLanguageLocale = (locale: string) => {
13 const result = localeMapping[locale as keyof typeof localeMapping] || locale;
14 return result.replace('_', '-').toLowerCase();
17 export const getLocaleMap = (localeFiles: string[]) => {
20 const getLocaleWithoutExt = (localePath: string) => {
21 return localePath.replace(ext, '');
24 const map = localeFiles.reduce<{ [key: string]: string[] }>((acc, localePath) => {
25 if (!localePath.endsWith(ext)) {
28 const fullLocale = getLocaleWithoutExt(localePath);
29 const language = getLanguage(fullLocale);
33 acc[language].push(localePath);
37 return localeFiles.reduce<{ [key: string]: string }>((acc, localePath) => {
38 if (!localePath.endsWith(ext) || localePath.includes('en_US')) {
42 const fullLocale = getLocaleWithoutExt(localePath);
43 const replacedLocale = getLanguageLocale(fullLocale);
44 const language = getLanguage(replacedLocale);
45 let shortLocale = language;
46 if (map[language].length > 1) {
47 shortLocale = replacedLocale;
50 acc[fullLocale] = shortLocale;
56 export default getLanguageLocale;