Skip to content

Commit

Permalink
i18n: translate entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
jingsam committed Sep 1, 2024
1 parent bd6d259 commit 6d58b22
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
24 changes: 9 additions & 15 deletions apps/studio/components/interfaces/Database/Tables/TableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import SchemaSelector from 'components/ui/SchemaSelector'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { ENTITY_TYPE, ENTITY_TYPE_LABELS } from 'data/entity-types/entity-type-constants'
import { useForeignTablesQuery } from 'data/foreign-tables/foreign-tables-query'
import { useMaterializedViewsQuery } from 'data/materialized-views/materialized-views-query'
import { useTablesQuery } from 'data/tables/tables-query'
Expand Down Expand Up @@ -189,11 +189,7 @@ const TableList = ({
isSuccessTables && isSuccessViews && isSuccessMaterializedViews && isSuccessForeignTables

const formatTooltipText = (entityType: string) => {
return Object.entries(ENTITY_TYPE)
.find(([, value]) => value === entityType)?.[0]
?.toLowerCase()
?.split('_')
?.join(' ')
return ENTITY_TYPE_LABELS[entityType as ENTITY_TYPE]
}

return (
Expand Down Expand Up @@ -236,7 +232,7 @@ const TableList = ({
}}
/>
<Label_Shadcn_ htmlFor={key} className="capitalize text-xs">
{key.toLowerCase().replace('_', ' ')}
{ENTITY_TYPE_LABELS[value]}
</Label_Shadcn_>
</div>
<Button
Expand Down Expand Up @@ -322,17 +318,17 @@ const TableList = ({
<>
<p className="text-sm text-foreground">还未创建表</p>
<p className="text-sm text-foreground-light">
在模式 "{selectedSchema}" 中未找到任何{' '}
在模式 "{selectedSchema}" 中未找到任何
{visibleTypes.length === 5
? '表'
: visibleTypes.length === 1
? `${formatTooltipText(visibleTypes[0])}s`
? `${formatTooltipText(visibleTypes[0])}`
: `${visibleTypes
.slice(0, -1)
.map((x) => `${formatTooltipText(x)}s`)
.map((x) => `${formatTooltipText(x)}`)
.join(
', '
)}${formatTooltipText(visibleTypes[visibleTypes.length - 1])}s`}{' '}
''
)}${formatTooltipText(visibleTypes[visibleTypes.length - 1])}`}
</p>
</>
)}
Expand Down Expand Up @@ -379,9 +375,7 @@ const TableList = ({
'text-foreground-light bg-border-stronger'
)}
>
{Object.entries(ENTITY_TYPE)
.find(([, value]) => value === x.type)?.[0]?.[0]
?.toUpperCase()}
{ENTITY_TYPE_LABELS[x.type]}
</div>
)}
</TooltipTrigger_Shadcn_>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import InfiniteList from 'components/ui/InfiniteList'
import SchemaSelector from 'components/ui/SchemaSelector'
import { useSchemasQuery } from 'data/database/schemas-query'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { ENTITY_TYPE, ENTITY_TYPE_LABELS } from 'data/entity-types/entity-type-constants'
import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
import { useTableQuery } from 'data/tables/table-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
Expand Down Expand Up @@ -225,7 +225,7 @@ const TableEditorMenu = () => {
}}
/>
<Label_Shadcn_ htmlFor={key} className="capitalize text-xs">
{key.toLowerCase().replace('_', ' ')}
{ENTITY_TYPE_LABELS[value]}
</Label_Shadcn_>
</div>
<Button
Expand Down
8 changes: 8 additions & 0 deletions apps/studio/data/entity-types/entity-type-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ export enum ENTITY_TYPE {
FOREIGN_TABLE = 'f',
PARTITIONED_TABLE = 'p',
}

export const ENTITY_TYPE_LABELS: Record<ENTITY_TYPE, string> = {
r: '表',
v: '视图',
m: '物化视图',
f: '外部表',
p: '分区表',
}

0 comments on commit 6d58b22

Please sign in to comment.