export function _getOrderedOtherLocales( otherlocales: LocalesState, user: UserState, ): Array<api.types.OtherLocaleTranslation> { const translations = otherlocales.translations; if (!user.isAuthenticated) { return translations; } const preferredLocales = user.preferredLocales.reverse(); return translations.sort((a, b) => { let indexA = preferredLocales.indexOf(a.code); let indexB = preferredLocales.indexOf(b.code); if (indexA === -1 && indexB === -1) { return a.code > b.code ? 1 : 0; } else if (indexA < indexB) { return 1; } else if (indexA > indexB) { return -1; } else { return 0; } }); }
return otherlocales.translations.reduce((count, item) => { if (user.preferredLocales.indexOf(item.code) > -1) { return count + 1; } return count; }, 0);