Skip to content

Commit

Permalink
Fix hakukohde translation
Browse files Browse the repository at this point in the history
  • Loading branch information
SalamaGofore committed May 17, 2024
1 parent b2f1c17 commit 7d46879
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/app/(root)/haku-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import ListTable, {
} from '../components/table/list-table';
import { Haku } from '../lib/kouta-types';
import { useUserLanguage } from '../hooks/useAsiointiKieli';
import { Language } from '../lib/localization/localization-types';
import { translateName } from '../lib/localization/translation-utils';

export const HakuTable = ({
haut,
Expand All @@ -21,16 +23,20 @@ export const HakuTable = ({
sort: string;
setSort: (sort: string) => void;
}) => {
const getMatchingHakutapa = (hakutapaKoodiUri: string) =>
hakutavat.find((tapa: Koodi) => hakutapaKoodiUri.startsWith(tapa.koodiUri))
?.nimi.fi;
const getMatchingHakutapa =
(userLanguage: Language) => (hakutapaKoodiUri: string) => {
const matching = hakutavat.find((tapa: Koodi) =>
hakutapaKoodiUri.startsWith(tapa.koodiUri),
);
return matching ? translateName(matching.nimi, userLanguage) : undefined;
};

const userLanguage = useUserLanguage();

const columns = [
makeHakuColumn(userLanguage),
makeTilaColumn(),
makeHakutapaColumn(getMatchingHakutapa),
makeHakutapaColumn(getMatchingHakutapa(userLanguage)),
makeKoulutuksenAlkamiskausiColumn(),
makeCountColumn({
title: 'Hakukohteet',
Expand Down
3 changes: 2 additions & 1 deletion src/app/lib/koodisto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ async function getKoodit(koodisto: string): Promise<Koodi[]> {
metadata: [{ nimi: string; kieli: string }],
): string => {
const matchingData = metadata.find(
(m: { nimi: string; kieli: string }) => m.kieli === language,
(m: { nimi: string; kieli: string }) =>
m.kieli.toLowerCase() === language,
);
return matchingData ? matchingData.nimi : '';
};
Expand Down

0 comments on commit 7d46879

Please sign in to comment.