Skip to content

Commit 10df503

Browse files
authored
S2 Translations (#6878)
1 parent a02fe15 commit 10df503

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1052
-41
lines changed

.storybook-s2/constants.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Based on https://adobe.sharepoint.com/sites/global/SitePages/Languages%20Supported.aspx
2+
export let locales = [
3+
{label: 'Auto', value: ''},
4+
// Tier 1
5+
{label: 'French (France)', value: 'fr-FR'},
6+
{label: 'French (Canada)', value: 'fr-CA'},
7+
{label: 'German (Germany)', value: 'de-DE'},
8+
{label: 'English (Great Britain)', value: 'en-GB'},
9+
{label: 'English (United States)', value: 'en-US'},
10+
{label: 'Japanese (Japan)', value: 'ja-JP'},
11+
// // Tier 2
12+
{label: 'Danish (Denmark)', value: 'da-DK'},
13+
{label: 'Dutch (Netherlands)', value: 'nl-NL'},
14+
{label: 'Finnish (Finland)', value: 'fi-FI'},
15+
{label: 'Italian (Italy)', value: 'it-IT'},
16+
{label: 'Norwegian (Norway)', value: 'nb-NO'},
17+
{label: 'Spanish (Spain)', value: 'es-ES'},
18+
{label: 'Swedish (Sweden)', value: 'sv-SE'},
19+
{label: 'Portuguese (Brazil)', value: 'pt-BR'},
20+
// // Tier 3
21+
{label: 'Chinese (Simplified)', value: 'zh-CN'},
22+
{label: 'Chinese (Traditional)', value: 'zh-TW'},
23+
{label: 'Korean (Korea)', value: 'ko-KR'},
24+
// // Tier 4
25+
{label: 'Bulgarian (Bulgaria)', value: 'bg-BG'},
26+
{label: 'Croatian (Croatia)', value: 'hr-HR'},
27+
{label: 'Czech (Czech Republic)', value: 'cs-CZ'},
28+
{label: 'Estonian (Estonia)', value: 'et-EE'},
29+
{label: 'Hungarian (Hungary)', value: 'hu-HU'},
30+
{label: 'Latvian (Latvia)', value: 'lv-LV'},
31+
{label: 'Lithuanian (Lithuania)', value: 'lt-LT'},
32+
{label: 'Polish (Poland)', value: 'pl-PL'},
33+
{label: 'Romanian (Romania)', value: 'ro-RO'},
34+
{label: 'Russian (Russia)', value: 'ru-RU'},
35+
{label: 'Serbian (Serbia)', value: 'sr-SP'},
36+
{label: 'Slovakian (Slovakia)', value: 'sk-SK'},
37+
{label: 'Slovenian (Slovenia)', value: 'sl-SI'},
38+
{label: 'Turkish (Turkey)', value: 'tr-TR'},
39+
{label: 'Ukrainian (Ukraine)', value: 'uk-UA'},
40+
// // Tier 5
41+
{label: 'Arabic (United Arab Emirates)', value: 'ar-AE'}, // ar-SA??
42+
{label: 'Greek (Greece)', value: 'el-GR'},
43+
{label: 'Hebrew (Israel)', value: 'he-IL'}
44+
];
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, {useEffect, useState} from 'react';
2+
import {addons} from '@storybook/preview-api';
3+
import {makeDecorator} from '@storybook/preview-api';
4+
import {getQueryParams} from '@storybook/preview-api';
5+
import {Provider} from '@react-spectrum/s2';
6+
7+
document.body.style.margin = '0';
8+
9+
const providerValuesFromUrl = Object.entries(getQueryParams()).reduce((acc, [k, v]) => {
10+
if (k.includes('providerSwitcher-')) {
11+
return { ...acc, [k.replace('providerSwitcher-', '')]: v };
12+
}
13+
return acc;
14+
}, {});
15+
16+
function ProviderUpdater(props) {
17+
let [localeValue, setLocale] = useState(providerValuesFromUrl.locale || undefined);
18+
19+
useEffect(() => {
20+
let channel = addons.getChannel();
21+
let providerUpdate = (event) => {
22+
setLocale(event.locale);
23+
};
24+
25+
channel.on('provider/updated', providerUpdate);
26+
channel.emit('rsp/ready-for-update');
27+
return () => {
28+
channel.removeListener('provider/updated', providerUpdate);
29+
};
30+
}, []);
31+
32+
return (
33+
<Provider locale={localeValue}>
34+
{props.children}
35+
</Provider>
36+
);
37+
}
38+
39+
export const withProviderSwitcher = makeDecorator({
40+
name: 'withProviderSwitcher',
41+
parameterName: 'providerSwitcher',
42+
wrapper: (getStory, context, {options, parameters}) => {
43+
options = {...options, ...parameters};
44+
return (
45+
<ProviderUpdater options={options} context={context}>
46+
{getStory(context)}
47+
</ProviderUpdater>
48+
);
49+
}
50+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
import {addons, types} from '@storybook/manager-api';
3+
import {getQueryParams} from '@storybook/preview-api';
4+
import {locales} from '../../constants';
5+
import React, {useEffect, useState} from 'react';
6+
7+
const providerValuesFromUrl = Object.entries(getQueryParams()).reduce((acc, [k, v]) => {
8+
if (k.includes('providerSwitcher-')) {
9+
return { ...acc, [k.replace('providerSwitcher-', '')]: v };
10+
}
11+
return acc;
12+
}, {});
13+
14+
function ProviderFieldSetter({api}) {
15+
let [values, setValues] = useState({locale: providerValuesFromUrl.locale || undefined});
16+
let channel = addons.getChannel();
17+
let onLocaleChange = (e) => {
18+
let newValue = e.target.value || undefined;
19+
setValues((old) => {
20+
let next = {...old, locale: newValue};
21+
channel.emit('provider/updated', next);
22+
return next;
23+
});
24+
};
25+
useEffect(() => {
26+
let storySwapped = () => {
27+
channel.emit('provider/updated', values);
28+
};
29+
channel.on('rsp/ready-for-update', storySwapped);
30+
return () => {
31+
channel.removeListener('rsp/ready-for-update', storySwapped);
32+
};
33+
});
34+
35+
useEffect(() => {
36+
api.setQueryParams({
37+
'providerSwitcher-locale': values.locale || ''
38+
});
39+
});
40+
41+
return (
42+
<div style={{display: 'flex', alignItems: 'center', fontSize: '12px'}}>
43+
<div style={{marginRight: '10px'}}>
44+
<label htmlFor="locale">Locale: </label>
45+
<select id="locale" name="locale" onChange={onLocaleChange} value={values.locale}>
46+
{locales.map(locale => <option key={locale.label} value={locale.value}>{locale.label}</option>)}
47+
</select>
48+
</div>
49+
</div>
50+
)
51+
}
52+
53+
addons.register('ProviderSwitcher', (api) => {
54+
addons.add('ProviderSwitcher', {
55+
title: 'viewport',
56+
type: types.TOOL,
57+
match: ({ viewMode }) => {
58+
console.log('viewMode', viewMode);
59+
return viewMode === 'story' || viewMode === 'docs'
60+
},
61+
render: () => <ProviderFieldSetter api={api} />,
62+
});
63+
});

.storybook-s2/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const config: StorybookConfig = {
2323
"@storybook/addon-links",
2424
"@storybook/addon-essentials",
2525
"@storybook/addon-interactions",
26+
'./custom-addons/provider/register',
2627
// "@storybook/addon-styling-webpack",
2728
"storybook-dark-mode"
2829
],

.storybook-s2/preview.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { store } from 'storybook-dark-mode/dist/esm/Tool';
55
import { addons } from '@storybook/preview-api';
66
import { DocsContainer } from '@storybook/addon-docs';
77
import React, { useEffect, useState } from 'react';
8+
import {withProviderSwitcher} from './custom-addons/provider';
89
import './global.css';
910

1011
const channel = addons.getChannel();
@@ -103,4 +104,10 @@ export const parameters = {
103104
layout: 'fullscreen',
104105
};
105106

107+
108+
109+
export const decorators = [
110+
withProviderSwitcher
111+
];
112+
106113
export default preview;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"contextualhelp.help": "مساعدة",
3+
"contextualhelp.info": "معلومات",
4+
"dialog.alert": "تنبيه",
5+
"dialog.dismiss": "تجاهل",
6+
"dropzone.replaceMessage": "للاستبدال، قم بإفلات الملف",
7+
"inlinealert.informative": "معلومات",
8+
"inlinealert.negative": "خطأ",
9+
"inlinealert.notice": "تحذير",
10+
"inlinealert.positive": "تم بنجاح",
11+
"label.(optional)": "(اختياري)",
12+
"label.(required)": "(مطلوب)",
13+
"menu.moreActions": "المزيد من الإجراءات",
14+
"picker.placeholder": "حدد خيارًا...",
15+
"slider.maximum": "أقصى",
16+
"slider.minimum": "أدنى",
17+
"tag.noTags": "بدون"
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"contextualhelp.help": "Помощ",
3+
"contextualhelp.info": "Информация",
4+
"dialog.alert": "Сигнал",
5+
"dialog.dismiss": "Отхвърляне",
6+
"dropzone.replaceMessage": "Пуснете файл за замяна",
7+
"inlinealert.informative": "Информация",
8+
"inlinealert.negative": "Грешка",
9+
"inlinealert.notice": "Предупреждение",
10+
"inlinealert.positive": "Успешно",
11+
"label.(optional)": "(незадължително)",
12+
"label.(required)": "(задължително)",
13+
"menu.moreActions": "Повече действия",
14+
"picker.placeholder": "Изберете опция",
15+
"slider.maximum": "Максимум",
16+
"slider.minimum": "Минимум",
17+
"tag.noTags": "Нито един"
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"contextualhelp.help": "Nápověda",
3+
"contextualhelp.info": "Informace",
4+
"dialog.alert": "Výstraha",
5+
"dialog.dismiss": "Odstranit",
6+
"dropzone.replaceMessage": "Přetáhněte soubor k nahrazení",
7+
"inlinealert.informative": "Informace",
8+
"inlinealert.negative": "Chyba",
9+
"inlinealert.notice": "Varování",
10+
"inlinealert.positive": "Úspěch",
11+
"label.(optional)": "(volitelně)",
12+
"label.(required)": "(požadováno)",
13+
"menu.moreActions": "Další akce",
14+
"picker.placeholder": "Vyberte vhodnou možnost...",
15+
"slider.maximum": "Maximum",
16+
"slider.minimum": "Minimum",
17+
"tag.noTags": "Žádný"
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"contextualhelp.help": "Hjælp",
3+
"contextualhelp.info": "Oplysninger",
4+
"dialog.alert": "Advarsel",
5+
"dialog.dismiss": "Luk",
6+
"dropzone.replaceMessage": "Drop fil for at erstatte",
7+
"inlinealert.informative": "Oplysninger",
8+
"inlinealert.negative": "Fejl",
9+
"inlinealert.notice": "Advarsel",
10+
"inlinealert.positive": "Fuldført",
11+
"label.(optional)": "(valgfrit)",
12+
"label.(required)": "(obligatorisk)",
13+
"menu.moreActions": "Flere handlinger",
14+
"picker.placeholder": "Vælg en mulighed ...",
15+
"slider.maximum": "Maksimum",
16+
"slider.minimum": "Minimum",
17+
"tag.noTags": "Ingen"
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"contextualhelp.help": "Hilfe",
3+
"contextualhelp.info": "Informationen",
4+
"dialog.alert": "Warnhinweis",
5+
"dialog.dismiss": "Schließen",
6+
"dropzone.replaceMessage": "Datei zum Ersetzen ablegen",
7+
"inlinealert.informative": "Informationen",
8+
"inlinealert.negative": "Fehler",
9+
"inlinealert.notice": "Warnung",
10+
"inlinealert.positive": "Erfolg",
11+
"label.(optional)": "(optional)",
12+
"label.(required)": "(erforderlich)",
13+
"menu.moreActions": "Mehr Aktionen",
14+
"picker.placeholder": "Option auswählen...",
15+
"slider.maximum": "Maximum",
16+
"slider.minimum": "Minimum",
17+
"tag.noTags": "Keine"
18+
}

0 commit comments

Comments
 (0)