Skip to content

Commit

Permalink
[i18n]: localize missing content in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jingsam committed Jul 18, 2024
1 parent 5b713ba commit 66b48f1
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const PolicyDefinition = ({
<div className="flex w-1/3 flex-col space-y-2">
<div className="flex items-center space-x-2">
<label className="text-base text-foreground-light" htmlFor="policy-name">
USING expression
USING 表达式
</label>
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
Expand All @@ -54,25 +54,22 @@ const PolicyDefinition = ({
].join(' ')}
>
<p className="text-xs text-foreground">
This expression will be added to queries that refer to the table if
row-level security is enabled.
如果启用了行级安全性,此表达式将添加到对表的查询中。
</p>
<p className="text-xs text-foreground">
Rows for which the expression returns true will be visible. Any rows for
which the expression returns false or null will not be visible to the user
(in a SELECT), and will not be available for modification (in an UPDATE or
DELETE).
对于返回 true 的表达式的行对将用户可见。对于返回 false 或 null 的表达式的行,将对用户不可见
(SELECT 操作),并且也不能修改(UPDATE 或 DELETE操作)。
</p>
<p className="text-xs text-foreground">
Such rows are silently suppressed - no error is reported.
这些行将被静默限制,不会报告错误。
</p>
</div>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</div>
<p className="text-sm text-foreground-lighter">
Provide a SQL conditional expression that returns a boolean.
提供一个返回布尔值的 SQL 条件表达式。
</p>
</div>
<div className={`w-2/3 ${showCheck(operation) ? 'h-32' : 'h-56'}`}>
Expand All @@ -85,7 +82,7 @@ const PolicyDefinition = ({
<div className="flex w-1/3 flex-col space-y-2">
<div className="flex items-center space-x-2">
<label className="text-base text-foreground-light" htmlFor="policy-name">
WITH CHECK expression
WITH CHECK 表达式
</label>
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
Expand All @@ -101,25 +98,23 @@ const PolicyDefinition = ({
].join(' ')}
>
<p className="text-xs text-foreground">
This expression will be used in INSERT and UPDATE queries against the table
if row-level security is enabled.
如果启用额行级安全性,
此表达式将在对表的 INSERT 和 UPDATE 查询中使用。
</p>
<p className="text-xs text-foreground">
Only rows for which the expression evaluates to true will be allowed. An
error will be thrown if the expression evaluates to false or null for any of
the records inserted or any of the records that result from the update.
只有对于表达式返回为 true 的行才会被允许操作。如果表达式返回为 false 或 null,
对于任何插入操作的新记录或者更新操作返回的记录将会抛出错误。
</p>
<p className="text-xs text-foreground">
Note that this expression is evaluated against the proposed new contents of
the row, not the original contents.
请注意,此表达式是针对新行的数据进行求值,而不是行的原先的数据。
</p>
</div>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</div>
<p className="text-sm text-foreground-lighter">
Provide a SQL conditional expression that returns a boolean.
提供一个返回布尔值的 SQL 条件表达式。
</p>
</div>
<div className={`w-2/3 ${showUsing(operation) ? 'h-32' : 'h-56'}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const PolicyEditorFooter = ({
<div className="flex w-full items-center justify-end gap-2">
{showTemplates && (
<Button type="default" onClick={onViewTemplates}>
View templates
查看模版
</Button>
)}
<Button type="primary" onClick={onReviewPolicy}>
Review
检查
</Button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const getGeneralPolicyTemplates = (schema: string, table: string): Policy
{
id: 'policy-1',
preview: false,
templateName: 'Enable read access to everyone',
templateName: '允许任何人读取表',
description:
'This policy gives read access to your table for all users via the SELECT operation.',
'此策略允许所有用户通过 SELECT 操作读取您的表。',
statement: `
create policy "Enable read access for all users"
on "${schema}"."${table}"
for select using (true);`.trim(),
name: 'Enable read access for all users',
name: '允许所有用户读取表',
definition: 'true',
check: '',
command: 'SELECT',
Expand All @@ -34,14 +34,14 @@ for select using (true);`.trim(),
{
id: 'policy-2',
preview: false,
templateName: 'Enable insert access for authenticated users only',
description: 'This policy gives insert access to your table for all authenticated users only.',
templateName: '仅允许经过身份验证的用户插入数据',
description: '此策略仅允许经过身份验证的用户向您的表中插入数据。',
statement: `
create policy "Enable insert for authenticated users only"
on "${schema}"."${table}"
for insert to authenticated
with check (true);`.trim(),
name: 'Enable insert for authenticated users only',
name: '仅允许经过身份验证的用户插入数据',
definition: '',
check: 'true',
command: 'INSERT',
Expand All @@ -50,9 +50,9 @@ with check (true);`.trim(),
{
id: 'policy-3',
preview: false,
templateName: 'Enable update access for users based on their email *',
templateName: '基于用户的电子邮件允许用户更新数据 *',
description:
'This policy assumes that your table has a column "email", and allows users to update rows which the "email" column matches their email.',
'此策略假定您的表有“email”列,只允许用户更新匹配其电子邮件的行。',
statement: `
create policy "Enable update for users based on email"
on "${schema}"."${table}"
Expand All @@ -61,7 +61,7 @@ for update using (
) with check (
(select auth.jwt()) ->> 'email' = email
);`.trim(),
name: 'Enable update for users based on email',
name: '基于用户的电子邮件允许用户更新数据',
definition: `(select auth.jwt()) ->> 'email' = email`,
check: `(select auth.jwt()) ->> 'email' = email`,
command: 'UPDATE',
Expand All @@ -70,16 +70,16 @@ for update using (
{
id: 'policy-4',
preview: false,
templateName: 'Enable delete access for users based on their user ID *',
templateName: '基于用户的 ID 允许用户删除数据 *',
description:
'This policy assumes that your table has a column "user_id", and allows users to delete rows which the "user_id" column matches their ID',
'此策略假定您的表有“user_id”列,只允许用户删除匹配其 ID 的行。',
statement: `
create policy "Enable delete for users based on user_id"
on "${schema}"."${table}"
for delete using (
(select auth.uid()) = user_id
);`.trim(),
name: 'Enable delete for users based on user_id',
name: '基于 user_id 允许用户删除数据',
definition: '(select auth.uid()) = user_id',
check: '',
command: 'DELETE',
Expand All @@ -88,16 +88,16 @@ for delete using (
{
id: 'policy-5',
preview: false,
templateName: 'Enable insert access for users based on their user ID *',
templateName: '基于用户的 ID 允许用户插入数据 *',
description:
'This policy assumes that your table has a column "user_id", and allows users to insert rows which the "user_id" column matches their ID',
'此策略假定您的表有“user_id”列,只允许用户插入匹配其 ID 的行。',
statement: `
create policy "Enable insert for users based on user_id"
on "${schema}"."${table}"
for insert with check (
(select auth.uid()) = user_id
);`.trim(),
name: 'Enable insert for users based on user_id',
name: '基于 user_id 允许用户插入数据',
definition: '',
check: '(select auth.uid()) = user_id',
command: 'INSERT',
Expand All @@ -106,12 +106,12 @@ for insert with check (
{
id: 'policy-6',
preview: true,
name: 'Policy with table joins',
templateName: 'Policy with table joins',
name: '使用表关联的策略',
templateName: '使用表关联的策略',
description: `
Query across tables to build more advanced RLS rules
跨表查询以构建更高级的 RLS 规则
Assuming 2 tables called \`teams\` and \`members\`, you can query both tables in the policy to control access to the members table.`,
假定有两张表,分别称为 \`teams\` \`members\`,您可以在策略中查询这两个表以控制对 members 表的访问权限。`,
statement: `
create policy "Members can update team details if they belong to the team"
on teams for update using (
Expand All @@ -128,11 +128,11 @@ on teams for update using (
{
id: 'policy-7',
preview: true,
templateName: 'Policy with security definer functions',
templateName: '使用 security definer 函数的策略',
description: `
Useful in a many-to-many relationship where you want to restrict access to the linking table.
在多对多的表关系中很有用,您希望限制对关联表的访问权限。
Assuming 2 tables called \`teams\` and \`members\`, you can use a security definer function in combination with a policy to control access to the members table.`.trim(),
假定有两张表,分别称为 \`teams\` \`members\`,您可以在策略中使用 security definer 函数来控制对 members 表的访问权限。`.trim(),
statement: `
create or replace function get_teams_for_user(user_id uuid)
returns setof bigint as $$
Expand All @@ -145,7 +145,7 @@ for all using (
team_id in (select get_teams_for_user(auth.uid()))
);
`.trim(),
name: 'Policy with security definer functions',
name: '使用 security definer 函数的策略',
definition: 'team_id in (select get_teams_for_user(auth.uid()))',
check: '',
command: 'ALL',
Expand All @@ -154,12 +154,12 @@ for all using (
{
id: 'policy-8',
preview: true,
name: 'Policy to implement Time To Live (TTL)',
templateName: 'Policy to implement Time To Live (TTL)',
name: '实现 TTL 功能的策略',
templateName: '实现 TTL 功能的策略',
description: `
Implement a TTL-like feature that you see in Instagram stories or Snapchat where messages expire after a day.
实现类似于 Instagram storie 或 Snapchat 中的消息在一天后过期的 TTL 功能。
Rows under the table are available only if they have been created within the last 24 hours.`,
表中的行仅在创建后 24 小时内可用。`,
statement: `
create policy "Stories are live for a day"
on "${schema}"."${table}"
Expand All @@ -179,14 +179,14 @@ export const getRealtimePolicyTemplates = (): PolicyTemplate[] => {
{
id: 'policy-broadcast-1',
preview: false,
templateName: 'Allow listening for broadcasts for authenticated users only',
description: 'This policy allows listening for broadcasts for authenticated users only.',
templateName: '仅允许通过身份验证的用户监听广播消息',
description: '此策略仅允许通过身份验证的用户监听广播消息。',
statement: `
create policy "Allow listening for broadcasts for authenticated users only"
on realtime.messages for select
to authenticated
using ( realtime.messages.extension = 'broadcast' );`.trim(),
name: 'Allow listening for broadcasts for authenticated users only',
name: '仅允许通过身份验证的用户监听广播消息',
definition: "realtime.messages.extension = 'broadcast'",
check: '',
command: 'SELECT',
Expand All @@ -195,14 +195,14 @@ using ( realtime.messages.extension = 'broadcast' );`.trim(),
{
id: 'policy-broadcast-2',
preview: false,
templateName: 'Allow pushing broadcasts for authenticated users only',
description: 'This policy allows pushing broadcasts for authenticated users only.',
templateName: '仅允许通过身份验证的用户推送广播消息',
description: '此策略仅允许通过身份验证的用户推送广播消息。',
statement: `
create policy "Allow pushing broadcasts for authenticated users only"
ON realtime.messages for insert
TO authenticated
with check ( realtime.messages.extension = 'broadcast' );`.trim(),
name: 'Allow pushing broadcasts for authenticated users only',
name: '仅允许通过身份验证的用户推送广播消息',
definition: "realtime.messages.extension = 'broadcast'",
check: "realtime.messages.extension = 'broadcast'",
command: 'INSERT',
Expand All @@ -211,13 +211,13 @@ with check ( realtime.messages.extension = 'broadcast' );`.trim(),
{
id: 'policy-broadcast-3',
preview: false,
templateName: 'Allow listening for broadcasts from a specific channel',
description: 'This policy allows listening for broadcasts from a specific channel.',
templateName: '仅允许从特定频道监听广播消息',
description: '此策略仅允许从特定频道监听广播消息。',
statement: `
create policy "Allow listening for broadcasts from a specific channel"
on realtime.messages for select
using ( realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channel_name' );`.trim(),
name: 'Allow listening for broadcasts from a specific channel',
name: '仅允许从特定频道监听广播消息',
definition: `realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channel_name'`,
check: '',
command: 'SELECT',
Expand All @@ -226,13 +226,13 @@ using ( realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channe
{
id: 'policy-broadcast-4',
preview: false,
templateName: 'Allow pushing broadcasts to specific channel',
description: 'This policy allow pushing broadcasts to specific channel.',
templateName: '仅允许向特定频道推送广播消息',
description: '此策略仅允许向特定频道推送广播消息。',
statement: `
create policy "Allow pushing broadcasts to specific channel"
ON realtime.messages for insert
with check ( realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channel_name' );`.trim(),
name: 'Allow pushing broadcasts to specific channel',
name: '仅允许向特定频道推送广播消息',
definition: `realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channel_name'`,
check: `realtime.messages.extension = 'broadcast' AND realtime.topic() = 'channel_name'`,
command: 'INSERT',
Expand All @@ -241,15 +241,14 @@ with check ( realtime.messages.extension = 'broadcast' AND realtime.topic() = 'c
{
id: 'policy-presences-1',
preview: false,
templateName: 'Allow listening for presences on all channels for authenticated users only',
description:
'This policy enables listening for presences on all channels for all authenticated users only.',
templateName: '仅允许通过身份验证的用户监听所有频道的在线状态',
description: '此策略仅允许通过身份验证的用户监听所有频道的在线状态。',
statement: `
create policy "Allow listening for presences on all channels for authenticated users only"
on realtime.messages for select
to authenticated
using ( realtime.messages.extension = 'presence' );`.trim(),
name: 'Allow listening for presences on all channels for authenticated users only',
name: '仅允许通过身份验证的用户监听所有频道的在线状态',
definition: "realtime.messages.extension = 'presence'",
check: '',
command: 'SELECT',
Expand All @@ -258,16 +257,15 @@ using ( realtime.messages.extension = 'presence' );`.trim(),
{
id: 'policy-presences-2',
preview: false,
templateName: 'Allow broadcasting presences on all channels for authenticated users only',
description:
'This policy enables broadcasting presences on all channels for all authenticated users only.',
templateName: '仅允许通过身份验证的用户向所有频道广播在线状态',
description: '此策略仅允许通过身份验证的用户向所有频道广播在线状态。',
statement: `
create policy "Allow broadcasting presences on all channels for authenticated users only"
ON realtime.messages for insert
TO authenticated
with check ( realtime.messages.extension = 'presence' );
;`.trim(),
name: 'Allow broadcasting presences on all channels for authenticated users only',
name: '仅允许通过身份验证的用户向所有频道广播在线状态',
definition: "realtime.messages.extension = 'presence'",
check: "realtime.messages.extension = 'presence'",
command: 'INSERT',
Expand All @@ -276,13 +274,13 @@ with check ( realtime.messages.extension = 'presence' );
{
id: 'policy-presences-3',
preview: false,
templateName: 'Allow listening for presences from a specific channel',
description: 'This policy enables listening for presences from a specific channel.',
templateName: '仅允许从特定频道监听在线状态',
description: '此策略仅允许从特定频道监听在线状态。',
statement: `
create policy "Allow listening for presences from a specific channel"
on realtime.messages for select
using ( realtime.messages.extension = 'presence' AND realtime.topic() = 'channel_name' );`.trim(),
name: 'Allow listening for presences from a specific channel',
name: '仅允许从特定频道监听在线状态',
definition: `realtime.messages.extension = 'presence' AND realtime.topic() = 'channel_name'`,
check: '',
command: 'SELECT',
Expand All @@ -291,14 +289,14 @@ using ( realtime.messages.extension = 'presence' AND realtime.topic() = 'channel
{
id: 'policy-presences-4',
preview: false,
templateName: 'Publish presence to a specific channel',
description: 'This policy allows publishing presence to a specific channel.',
templateName: '向特定频道发布在线状态',
description: '此策略允许向特定频道发布在线状态。',
statement: `
create policy "Publish presence to a specific channel"
ON realtime.messages for insert
with check ( realtime.messages.extension = 'presence' AND realtime.topic() = 'channel_name' );
;`.trim(),
name: 'Publish presence to a specific channel',
name: '向特定频道发布在线状态',
definition: `realtime.messages.extension = 'presence' AND realtime.topic() = 'channel_name'`,
check: `realtime.messages.extension = 'presence' AND realtime.topic() = 'channel_name'`,
command: 'INSERT',
Expand Down
Loading

0 comments on commit 66b48f1

Please sign in to comment.