You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.3 KiB
PHP
119 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Factory shared by source-language copy fragments.
|
|
*
|
|
* Fragments contain only stable keys, Chinese baselines and rendering
|
|
* contracts. Administrator-owned target translations never belong here.
|
|
*/
|
|
$surfaceFor = static function (
|
|
string $key,
|
|
string $page,
|
|
string $kind,
|
|
?string $toastTone,
|
|
?string $requested
|
|
): string {
|
|
if ($requested !== null) {
|
|
return $requested;
|
|
}
|
|
if (str_starts_with($key, 'common.tasks.')
|
|
|| str_starts_with($key, 'common.drawer.tasks.')) {
|
|
return 'task';
|
|
}
|
|
if (in_array($kind, ['aria_label', 'tooltip', 'placeholder'], true)) {
|
|
return 'accessibility';
|
|
}
|
|
if ($kind === 'confirmation'
|
|
|| str_contains($key, '.dialog.')
|
|
|| str_contains($key, '.drawer.')) {
|
|
return 'dialog';
|
|
}
|
|
if ($toastTone !== null
|
|
|| str_starts_with($kind, 'toast_')
|
|
|| in_array(
|
|
$kind,
|
|
['warning', 'notice', 'empty_state', 'status'],
|
|
true
|
|
)) {
|
|
return 'feedback';
|
|
}
|
|
if (str_starts_with($key, 'common.shell.')
|
|
|| str_starts_with($key, 'common.theme.')
|
|
|| str_starts_with($key, 'public.shell.')
|
|
|| in_array(
|
|
$key,
|
|
['common.action.refresh', 'common.action.load_more'],
|
|
true
|
|
)) {
|
|
return 'shared';
|
|
}
|
|
if (str_starts_with($page, 'auth.')) {
|
|
return 'admin';
|
|
}
|
|
return 'page';
|
|
};
|
|
|
|
$groupFor = static function (string $key, string $page, ?string $requested): string {
|
|
if ($requested !== null) {
|
|
return $requested;
|
|
}
|
|
if (str_starts_with($key, 'common.shell.')
|
|
|| str_starts_with($key, 'common.theme.')) {
|
|
return 'shell.user';
|
|
}
|
|
if (str_starts_with($key, 'public.shell.')) {
|
|
return 'shell.public';
|
|
}
|
|
if (str_starts_with($key, 'common.tasks.')
|
|
|| str_starts_with($key, 'common.drawer.tasks.')) {
|
|
return 'user.tasks';
|
|
}
|
|
if (str_starts_with($key, 'common.announcements.')
|
|
|| str_starts_with($key, 'common.drawer.announcements.')) {
|
|
return 'user.announcements';
|
|
}
|
|
if (str_starts_with($key, 'common.account.')
|
|
|| str_starts_with($key, 'common.drawer.account.')) {
|
|
return 'user.account';
|
|
}
|
|
if (str_starts_with($key, 'common.promotion.')) {
|
|
return 'user.invite';
|
|
}
|
|
return str_starts_with($key, 'common.') ? 'common.shared' : $page;
|
|
};
|
|
|
|
return static function (
|
|
string $key,
|
|
string $scope,
|
|
string $page,
|
|
string $source,
|
|
string $kind = 'label',
|
|
array $parameters = [],
|
|
string $criticality = 'required',
|
|
bool $allowHide = false,
|
|
?string $toastTone = null,
|
|
?string $editorSurface = null,
|
|
?string $editorGroup = null
|
|
) use ($surfaceFor, $groupFor): array {
|
|
return [
|
|
'key' => $key,
|
|
'scope' => $scope,
|
|
'page' => $page,
|
|
'kind' => $kind,
|
|
'source' => $source,
|
|
'format' => $parameters === [] ? 'plain_text' : 'icu',
|
|
'parameters' => $parameters,
|
|
'criticality' => $criticality,
|
|
'allow_hide' => $allowHide,
|
|
'toast_tone' => $toastTone,
|
|
'editor_surface' => $surfaceFor(
|
|
$key,
|
|
$page,
|
|
$kind,
|
|
$toastTone,
|
|
$editorSurface
|
|
),
|
|
'editor_group' => $groupFor($key, $page, $editorGroup),
|
|
];
|
|
};
|