-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c09a697
commit b4b4757
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/dnb-design-system-portal/src/shared/parts/TranslationsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import styled from '@emotion/styled' | ||
import { Table, Td, Th, Tr } from '@dnb/eufemia/src' | ||
import { extendDeep } from '@dnb/eufemia/src/shared/component-helper' | ||
import globalTranslations from '@dnb/eufemia/src/shared/locales' | ||
import formsTranslations from '@dnb/eufemia/src/extensions/forms/constants/locales' | ||
import { FormattedCode, formatName } from './PropertiesTable' | ||
|
||
const StyledTable = styled(Table)` | ||
td { | ||
white-space: nowrap; | ||
} | ||
` | ||
|
||
const allTranslations = extendDeep( | ||
{}, | ||
globalTranslations, | ||
formsTranslations, | ||
) | ||
|
||
export default function TranslationsTable({ name }: { name?: string }) { | ||
const entries = {} | ||
|
||
Object.entries(allTranslations).forEach(([locale, translations]) => { | ||
Object.entries(translations[name]).forEach(([key, translation]) => { | ||
entries[key] = Object.assign(entries[key] || {}, { | ||
[locale]: translation, | ||
}) | ||
}) | ||
}) | ||
|
||
const locales = Object.keys(allTranslations) | ||
const tableRows = Object.entries(entries).map(([key, values]) => { | ||
return ( | ||
<Tr key={key}> | ||
<Td> | ||
<FormattedCode variant="prop">{formatName(key)}</FormattedCode> | ||
</Td> | ||
{Object.entries(values).map(([locale, value], i) => { | ||
return <Td key={i + locale}>{formatName(value)}</Td> | ||
})} | ||
</Tr> | ||
) | ||
}) | ||
|
||
return ( | ||
<Table.ScrollView> | ||
<StyledTable> | ||
<thead> | ||
<Tr> | ||
<Th>Key</Th> | ||
{locales.map((locale) => ( | ||
<Th key={locale}>{locale}</Th> | ||
))} | ||
</Tr> | ||
</thead> | ||
<tbody>{tableRows}</tbody> | ||
</StyledTable> | ||
</Table.ScrollView> | ||
) | ||
} |