dialog i18 support (#915)

This commit is contained in:
Rozstone 2022-08-21 14:40:17 +08:00 committed by GitHub
parent 0699dcce17
commit ae4a1b6fbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 13 deletions

View file

@ -1,5 +1,6 @@
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'
import * as React from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { DialogState, useDialog } from '~hooks'
import { styled } from '~styles'
@ -42,13 +43,13 @@ export const AlertDialogDescription = StyledDescription
export const AlertDialogAction = AlertDialogPrimitive.Action
export const AlertDialogCancel = AlertDialogPrimitive.Cancel
const descriptions: Record<DialogState, string> = {
saveFirstTime: 'Do you want to save your current project?',
saveAgain: 'Do you want to save changes to your current project?',
}
export const AlertDialog = ({ container }: { container: any }) => {
const { setDialogState, dialogState, onCancel, onNo, onYes } = useDialog()
const intl = useIntl()
const descriptions: Record<DialogState, string> = {
saveFirstTime: intl.formatMessage({ id: 'dialog.save.firsttime' }),
saveAgain: intl.formatMessage({ id: 'dialog.save.again' }),
}
return (
<AlertDialogRoot open={dialogState !== null}>
@ -73,7 +74,7 @@ export const AlertDialog = ({ container }: { container: any }) => {
setDialogState(null)
}}
>
Cancel
<FormattedMessage id="dialog.cancel" />
</Button>
</AlertDialogCancel>
)}
@ -86,7 +87,7 @@ export const AlertDialog = ({ container }: { container: any }) => {
setDialogState(null)
}}
>
No
<FormattedMessage id="dialog.no" />
</Button>
</AlertDialogAction>
)}
@ -99,7 +100,7 @@ export const AlertDialog = ({ container }: { container: any }) => {
setDialogState(null)
}}
>
Yes
<FormattedMessage id="dialog.yes" />
</Button>
</AlertDialogAction>
)}

View file

@ -117,5 +117,10 @@
"distribute.x": "Distribute Horizontal",
"distribute.y": "Distribute Vertical",
"stretch.x": "Stretch Horizontal",
"stretch.y": "Stretch Vertical"
"stretch.y": "Stretch Vertical",
"dialog.save.firsttime": "Do you want to save your current project?",
"dialog.save.again": "Do you want to save changes to your current project?",
"dialog.cancel": "Cancel",
"dialog.no": "No",
"dialog.yes": "Yes"
}

View file

@ -44,7 +44,7 @@
"select.all": "选中全部",
"select.none": "取消选中",
"delete": "删除",
"new.project": "新工程",
"new.project": "新项目",
"open": "打开",
"save": "保存",
"save.as": "保存为",
@ -55,8 +55,8 @@
"duplicate": "复制",
"cancel": "取消",
"copy.invite.link": "复制邀请链接",
"create.multiplayer.project": "创建多人工程",
"copy.multiplayer.project": "复制到多人工程",
"create.multiplayer.project": "创建多人项目",
"copy.multiplayer.project": "复制到多人项目",
"select": "选择",
"eraser": "橡皮",
"draw": "画笔",
@ -103,5 +103,10 @@
"dark": "暗黑",
"copy.readonly.link": "复制只读链接",
"image": "图片",
"align.distribute": "对齐 / 分散"
"align.distribute": "对齐 / 分散",
"dialog.save.firsttime": "您是否想保存当前的项目?",
"dialog.save.again": "您是否想保存对当前项目的更改?",
"dialog.cancel": "取消",
"dialog.no": "否",
"dialog.yes": "是"
}