1cf923a5af
* Initial plan * Add localization support to NameChangeModal component Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Add NameChangeModal translations to English language file Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * fix(i18n): fix localization keys * chore(test): add i18n test * chore(i18n): update translation script * chore(i18n): reorgnize translation keys and update components * chore: fix linting warnings * chore(i18n): update all the language files * feat(i18n): add last live ago i18n key --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gabek <414923+gabek@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com>
186 lines
3.9 KiB
TypeScript
186 lines
3.9 KiB
TypeScript
import { Meta, StoryObj } from '@storybook/react';
|
|
import { Translation } from '../components/ui/Translation/Translation';
|
|
import { Localization } from '../types/localization';
|
|
|
|
const meta: Meta<typeof Translation> = {
|
|
title: 'owncast/Components/Translation',
|
|
component: Translation,
|
|
parameters: {
|
|
chromatic: { diffThreshold: 0.8 },
|
|
},
|
|
argTypes: {
|
|
translationKey: {
|
|
control: 'text',
|
|
description: 'The translation key to use for the text',
|
|
},
|
|
vars: {
|
|
control: 'object',
|
|
description: 'Variables to interpolate into the translation',
|
|
},
|
|
className: {
|
|
control: 'text',
|
|
description: 'CSS class name to apply to the component',
|
|
},
|
|
count: {
|
|
control: 'number',
|
|
description:
|
|
'Count for pluralization support (1 = singular with _one key, others = plural with original key)',
|
|
},
|
|
defaultText: {
|
|
control: 'text',
|
|
description: 'Default text to use when translation is missing',
|
|
},
|
|
},
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof Translation>;
|
|
|
|
export const SimpleTranslation: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.chatOffline,
|
|
},
|
|
};
|
|
|
|
export const TranslationWithVariable: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.lastLiveAgo,
|
|
vars: {
|
|
timeAgo: '2 hours',
|
|
},
|
|
},
|
|
};
|
|
|
|
export const ComplexHTMLTranslation: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.helloWorld,
|
|
vars: {
|
|
name: 'Gabe',
|
|
},
|
|
},
|
|
};
|
|
|
|
export const ComplexHTMLMessage: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.offlineNotifyOnly,
|
|
vars: {
|
|
streamer: 'MyAwesomeStream',
|
|
},
|
|
},
|
|
};
|
|
|
|
export const ComplexMessage: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.complexMessage,
|
|
vars: {
|
|
count: 42,
|
|
status: 'live',
|
|
},
|
|
},
|
|
};
|
|
|
|
export const WithCustomClass: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.helloWorld,
|
|
vars: {
|
|
name: 'Styled User',
|
|
},
|
|
className: 'custom-translation-style',
|
|
},
|
|
};
|
|
|
|
export const TestDifferentLanguages: Story = {
|
|
args: {
|
|
translationKey: Localization.Frontend.helloWorld,
|
|
vars: {
|
|
name: 'Test User',
|
|
},
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story: 'Test different languages by adding ?lang=de or ?lang=fr to the URL',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export const PluralizationSingular: Story = {
|
|
args: {
|
|
translationKey: Localization.Testing.itemCount,
|
|
count: 1,
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story:
|
|
'Pluralization example with singular form (count = 1) - looks for _one key first, falls back to original key',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export const PluralizationPlural: Story = {
|
|
args: {
|
|
translationKey: Localization.Testing.itemCount,
|
|
count: 5,
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story: 'Pluralization example with plural form (count > 1) - uses original key directly',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export const PluralizationWithVariables: Story = {
|
|
args: {
|
|
translationKey: Localization.Testing.messageCount,
|
|
count: 3,
|
|
vars: {
|
|
sender: 'Alice',
|
|
},
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story: 'Pluralization with additional variables',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export const PluralizationFallback: Story = {
|
|
args: {
|
|
translationKey: Localization.Testing.noPluralKey,
|
|
count: 2,
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story:
|
|
'Pluralization fallback when no _one key exists (uses original key for both singular and plural)',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export const PluralizationWithDefaultText: Story = {
|
|
args: {
|
|
translationKey: 'non_existent_plural_key' as any,
|
|
count: 4,
|
|
defaultText: 'This is test number {{count}} for {{name}}',
|
|
vars: {
|
|
name: 'Bob',
|
|
},
|
|
},
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
story: 'Pluralization with default text fallback',
|
|
},
|
|
},
|
|
},
|
|
};
|