Skip to content

Commit

Permalink
Fix duplicated translations languge name
Browse files Browse the repository at this point in the history
  • Loading branch information
osamasayed committed Sep 9, 2024
1 parent 24c38e5 commit 792d1f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/components/MediaMaker/Settings/TranslationSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import IconCancel from '@/icons/cancel.svg';
import IconSearch from '@/icons/search.svg';
import { MediaSettingsProps } from '@/types/Media/MediaSettings';
import { makeTranslationsUrl } from '@/utils/apiPaths';
import filterTranslations from '@/utils/filter-translations';
import filterTranslations, { getTranslations } from '@/utils/filter-translations';
import { getLocaleName } from '@/utils/locale';
import { TranslationsResponse } from 'types/ApiResponses';
import AvailableTranslation from 'types/AvailableTranslation';
Expand Down Expand Up @@ -107,7 +107,10 @@ const TranslationSelectionBody: React.FC<Props> = ({ selectedTranslations, onSet
? filterTranslations(data.translations, searchQuery)
: data.translations;

const translationByLanguages = groupBy(filteredTranslations, 'languageName');
const translationByLanguages = groupBy(
getTranslations(filteredTranslations),
'languageName',
);
const selectedTranslationLanguage = getLocaleName(lang).toLowerCase();
const selectedTranslationGroup = translationByLanguages[selectedTranslationLanguage];
const translationByLanguagesWithoutSelectedLanguage = omit(translationByLanguages, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import SearchQuerySource from '@/types/SearchQuerySource';
import { makeTranslationsUrl } from '@/utils/apiPaths';
import { logValueChange, logItemSelectionChange, logEmptySearchResults } from '@/utils/eventLogger';
import filterTranslations from '@/utils/filter-translations';
import filterTranslations, { getTranslations } from '@/utils/filter-translations';
import { getLocaleName } from '@/utils/locale';
import { TranslationsResponse } from 'types/ApiResponses';
import PreferenceGroup from 'types/auth/PreferenceGroup';
Expand Down Expand Up @@ -147,7 +147,10 @@ const TranslationSelectionBody = () => {
});
}

const translationByLanguages = groupBy(filteredTranslations, 'languageName');
const translationByLanguages = groupBy(
getTranslations(filteredTranslations),
'languageName',
);
const selectedTranslationLanguage = getLocaleName(lang).toLowerCase();
const selectedTranslationGroup = translationByLanguages[selectedTranslationLanguage];
const translationByLanguagesWithoutSelectedLanguage = omit(translationByLanguages, [
Expand Down
15 changes: 15 additions & 0 deletions src/utils/filter-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,19 @@ const filterTranslations = (
return filteredTranslations;
};

/**
* Transforms an array of translations by converting the language name to lowercase.
* This is to temporarily fix the issue when BE returns the same language names
* but in different cases (e.g. 'Dutch' and 'dutch').
*
* @param {AvailableTranslation[]} translations - The array of translations to be transformed.
* @returns {AvailableTranslation[]} The transformed array of translations with language names in lowercase.
*/
export const getTranslations = (translations: AvailableTranslation[]): AvailableTranslation[] => {
return translations.map((translation) => ({
...translation,
languageName: translation.languageName.toLowerCase(),
}));
};

export default filterTranslations;

0 comments on commit 792d1f5

Please sign in to comment.