mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
Add Locale, BuiltInLocale, TranslationParams, Translations, and Translator reference pages plus createTranslator. Cross-link types from concept and guides; fix React examples and register-locale satisfies pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
2.0 KiB
Plaintext
67 lines
2.0 KiB
Plaintext
---
|
|
title: TranslationParams
|
|
description: Typed contract for translation keys and their placeholder arguments
|
|
---
|
|
|
|
import DocsLink from '@/components/docs/DocsLink.astro';
|
|
|
|
`TranslationParams` maps every opaque translation key to its argument shape. Keys with `never` accept only `t('key')`. Keys with an object accept `t('key', { … })` with typed placeholder names.
|
|
|
|
## Import
|
|
|
|
```ts
|
|
import type { TranslationParams } from '@videojs/core/i18n';
|
|
```
|
|
|
|
## Definition
|
|
|
|
```ts
|
|
type TranslationParams = {
|
|
play: never;
|
|
pause: never;
|
|
seekForward: { seconds: number | string };
|
|
timeRemainingPhrase: { duration: string };
|
|
// …
|
|
};
|
|
```
|
|
|
|
English defaults and the full key list live in `packages/core/src/core/i18n/locales/en.ts`. The authoritative TypeScript map is `packages/core/src/core/i18n/types.ts`.
|
|
|
|
## Parametric keys
|
|
|
|
| Key | Placeholders | Example English value |
|
|
| --- | --- | --- |
|
|
| `seekForward` | `{seconds}` | `Seek forward {seconds} seconds` |
|
|
| `seekBackward` | `{seconds}` | `Seek backward {seconds} seconds` |
|
|
| `playbackRateAria` | `{rate}` | `Playback rate {rate}` |
|
|
| `timeSliderValueTextRange` | `{current}`, `{duration}` | `{current} of {duration}` |
|
|
| `timeRemainingPhrase` | `{duration}` | `{duration} remaining` |
|
|
| `volumeSliderValueTextMuted` | `{percent}` | `{percent}, muted` |
|
|
| `indicatorVolumeWithValue` | `{value}` | `Volume {value}` |
|
|
|
|
All other keys are plain strings with no parameters.
|
|
|
|
## Usage with Translator
|
|
|
|
```ts
|
|
const t: Translator = createTranslator(translations, 'es');
|
|
|
|
t('play');
|
|
t('seekForward', { seconds: 10 });
|
|
t('timeRemainingPhrase', { duration: '1 minute' });
|
|
```
|
|
|
|
TypeScript rejects missing placeholders when defining <DocsLink slug="reference/translations">`Translations`</DocsLink> overlays:
|
|
|
|
```ts
|
|
registerI18n('es', {
|
|
seekForward: 'Adelantar', // error: missing {seconds}
|
|
});
|
|
```
|
|
|
|
## Related
|
|
|
|
- <DocsLink slug="reference/translations">`Translations`</DocsLink>
|
|
- <DocsLink slug="reference/translator">`Translator`</DocsLink>
|
|
- <DocsLink slug="concepts/i18n">Internationalization</DocsLink> — opaque keys overview
|