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.
virt/web/resources/user-copy/entry.php

97 lines
2.7 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 $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';
}
return 'page';
};
$groupFor = static function (string $key, string $page, ?string $requested): string {
if ($requested !== null) {
return $requested;
}
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,
$kind,
$toastTone,
$editorSurface
),
'editor_group' => $groupFor($key, $page, $editorGroup),
];
};