Skip to content

Commit

Permalink
Merge pull request #1396 from navikt/feat/new-translation-export
Browse files Browse the repository at this point in the history
Feat/new translation export
  • Loading branch information
magnurh-cx authored Jan 17, 2025
2 parents b2fe09c + 0756fbc commit 20b906c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/bygger/src/old_translations/global/GlobalCsvLink.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GlobalTranslationMap } from '@navikt/skjemadigitalisering-shared-domain';
import { useEffect, useState } from 'react';
import { ReactElement, useEffect, useState } from 'react';
import { CSVLink } from 'react-csv';
import { getAllPredefinedOriginalTexts, transformGlobalTranslationsToCsvData } from './utils';

interface Props {
allGlobalTranslations: GlobalTranslationMap;
languageCode: string;
children?: ReactElement | string;
}

interface CsvData {
Expand All @@ -18,7 +19,7 @@ interface CsvHeader {
key: string;
}

const GlobalCsvLink = ({ allGlobalTranslations, languageCode }: Props) => {
const GlobalCsvLink = ({ allGlobalTranslations, languageCode, children }: Props) => {
const [csvData, setCsvData] = useState<CsvData[]>([]);
const [csvHeaders, setCsvHeaders] = useState<CsvHeader[]>([]);

Expand All @@ -42,7 +43,7 @@ const GlobalCsvLink = ({ allGlobalTranslations, languageCode }: Props) => {
separator=";"
enclosingCharacter='"'
>
Eksporter
{children ? children : 'Eksporter'}
</CSVLink>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { GlobalTranslationMap, TranslationResource, TranslationTag } from '@navikt/skjemadigitalisering-shared-domain';
import { ReactElement, useMemo } from 'react';
import { useGlobalTranslations } from '../../context/translations/GlobalTranslationsContext';
import GlobalCsvLink from '../../old_translations/global/GlobalCsvLink';

interface Props {
language: 'en' | 'nn';
children: ReactElement | string;
}

const ExportGlobalTranslationsButton = ({ language, children }: Props) => {
const { translationsPerTag } = useGlobalTranslations();

const translationsFormioFormat: GlobalTranslationMap = useMemo(() => {
const resources: TranslationResource[] = Object.entries(translationsPerTag).map(([tag, translations]) => ({
id: 'id',
name: tag,
scope: 'global',
tag: tag as TranslationTag,
translations: translations.reduce(
(acc, { key, nb, ...translation }) => ({
...acc,
[nb ?? key]: { value: translation[language], scope: 'global' },
}),
{},
),
}));
return { [language]: resources };
}, [language, translationsPerTag]);

return (
<GlobalCsvLink allGlobalTranslations={translationsFormioFormat} languageCode={language}>
{children}
</GlobalCsvLink>
);
};

export default ExportGlobalTranslationsButton;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from 'react';
import UserFeedback from '../../components/UserFeedback';
import { useEditGlobalTranslations } from '../../context/translations/EditGlobalTranslationsContext';
import { useGlobalTranslations } from '../../context/translations/GlobalTranslationsContext';
import ExportGlobalTranslationsButton from '../components/ExportGlobalTranslationsButton';

const GlobalTranslationButtonsColumn = () => {
const [isProcessing, setIsProcessing] = useState<'SAVING' | 'PUBLISHING'>();
Expand Down Expand Up @@ -45,9 +46,8 @@ const GlobalTranslationButtonsColumn = () => {
>
Publisér
</Button>
<Button variant="tertiary" disabled={!!isProcessing} onClick={() => {}} type="button" size="small">
Eksporter
</Button>
<ExportGlobalTranslationsButton language={'nn'}>{'Eksporter nynorsk'}</ExportGlobalTranslationsButton>
<ExportGlobalTranslationsButton language={'en'}>{'Eksporter engelsk'}</ExportGlobalTranslationsButton>
<UserFeedback />
</VStack>
);
Expand Down

0 comments on commit 20b906c

Please sign in to comment.