Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike: i18n coverage/test cases in Storybook #3368

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .storybook/decorators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export { withIconSpriteSheet } from "./icon-sprites.js";
export { withLanguageWrapper } from "./language.js";
export { withReducedMotionWrapper } from "./reduce-motion.js";
export { withTestingPreviewWrapper } from "./testing-preview.js";
export { withTextDirectionWrapper } from "./text-direction.js";

/* This is exported but must be opted-into on a component-by-component basis */
export { withUnderlayWrapper } from "./underlay.js";
Expand Down
17 changes: 12 additions & 5 deletions .storybook/decorators/language.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeDecorator, useEffect } from "@storybook/preview-api";
import { fetchContainers } from "./helpers.js";
import { makeDecorator, useEffect } from '@storybook/preview-api';
import { fetchContainers } from "./helpers";
/* global Typekit */

/**
Expand All @@ -17,9 +17,14 @@ export const withLanguageWrapper = makeDecorator({
viewMode,
} = context;

useEffect(() => {
const isNotEnglish = lang && lang !== "en-US";
const isNotEnglish = lang && lang !== "en-US";
const isRTL = ["ar", "fa", "he"].includes(lang);

// Add a textDirection property to the globals for use in the story
context.globals.textDirection = isRTL ? "rtl" : "ltr";


useEffect(() => {
// If it is US-language or unset use the rok6rmo Adobe font web project id (smaller size),
// otherwise use the mge7bvf kit with all the language settings (larger size)
const kitId = isNotEnglish ? "mge7bvf" : "rok6rmo";
Expand Down Expand Up @@ -55,10 +60,12 @@ export const withLanguageWrapper = makeDecorator({
} catch (e) {/* empty */}
}

// Set the language and direction on the relevant containers
for (const container of fetchContainers(id, viewMode === "docs")) {
container.lang = lang;
container.dir = !isRTL ? "ltr" : "rtl";
}
}, [lang]);
}, [lang, isNotEnglish, isRTL, viewMode, id]);

return StoryFn(context);
},
Expand Down
30 changes: 0 additions & 30 deletions .storybook/decorators/text-direction.js

This file was deleted.

154 changes: 154 additions & 0 deletions .storybook/intl/translations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"ar": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "اسم المستخدم",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "محمد_أحمد",
"treeview.value": ""
},
"en": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "Username",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "john_doe",
"treeview.value": ""
},
"fa": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "نام کاربری",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "علی_رضا",
"treeview.value": ""
},
"he": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "שם משתמש",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "דני123",
"treeview.value": ""
},
"ja": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "ユーザー名",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "山田太郎",
"treeview.value": ""
},
"ko": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "사용자 이름",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "김철수",
"treeview.value": ""
},
"th": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "ชื่อผู้ใช้",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "สมชาย",
"treeview.value": ""
},
"zh": {
"accordion.text": "",
"actionbutton.text": "",
"assetcard.name": "",
"assetlist.file": "",
"badge.label": "",
"button.label": "",
"combobox.text": "",
"fieldlabel.label": "用户名",
"helptext.text": "",
"logicbutton.button": "",
"menu.menuItem": "",
"millercolumns.file": "",
"picker.placeholder": "",
"search.value": "",
"tag.label": "",
"textfield.value": "张伟",
"treeview.value": ""
}
}
40 changes: 39 additions & 1 deletion .storybook/modes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

const modes = {
"Light | LTR": {
color: "light",
lang: "en_US",
context: "legacy",
},
"Context: Express": {
scale: "medium",
color: "light",
textDirection: "ltr",
context: "express",
},
"Dark | RTL": {
color: "dark",
textDirection: "rtl",
lang: "ar",
},
"S1 | Light | LTR": {
context: "legacy",
Expand All @@ -40,3 +47,34 @@ export const disableDefaultModes = {
return acc;
}, {}),
};

export const mobile = {
"Mobile": {
scale: "large",
},
};

export const viewports = {
small: {
width: 480,
},
};

export const i18n = {
// This is the default language, so we don't need to specify it here
// "English": {
// lang: "en_US",
// },
"Hebrew": {
lang: "he",
},
"Japanese": {
lang: "ja",
},
"Korean": {
lang: "ko",
},
"Arabic": {
lang: "ar",
},
};
3 changes: 3 additions & 0 deletions .storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"exports": {
".": "./preview.js",
"./blocks": "./blocks/index.js",
"./blocks/*": "./blocks/*",
"./decorators": "./decorators/index.js",
"./decorators/*": "./decorators/*",
"./deprecated/*": "./deprecated/*",
Expand All @@ -20,6 +21,8 @@
"./modes/*": "./modes/*",
"./package.json": "./package.json",
"./preview": "./preview.js",
"./templates/*": "./templates/*",
"./translations": "./intl/translations.json",
"./types": "./types/index.js",
"./types/*": "./types/*"
},
Expand Down
5 changes: 3 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
withLanguageWrapper,
withReducedMotionWrapper,
withTestingPreviewWrapper,
withTextDirectionWrapper
} from "./decorators";
import translations from "./intl/translations.json";
import {
FontLoader,
IconLoader,
Expand All @@ -35,6 +35,8 @@ setConsoleOptions({
],
});

export { translations };

/** @type import('@storybook/types').StorybookParameters & import('@storybook/types').API_Layout */
export const parameters = {
layout: "centered",
Expand Down Expand Up @@ -124,7 +126,6 @@ export default {
decorators: [
withLanguageWrapper,
withReducedMotionWrapper,
withTextDirectionWrapper,
withContextWrapper,
withTestingPreviewWrapper,
withArgEvents,
Expand Down
27 changes: 9 additions & 18 deletions .storybook/types/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ export default {
dynamicTitle: true,
},
},
textDirection: {
title: "Text direction",
description: "Direction of the content flow",
defaultValue: "ltr",
type: "string",
toolbar: {
items: [
{ value: "ltr", title: "Left to right" },
{ value: "rtl", title: "Right to left" },
],
dynamicTitle: true,
},
},
// @todo https://jira.corp.adobe.com/browse/CSS-314
reducedMotion: {
title: "Reduce motion",
Expand All @@ -77,14 +64,18 @@ export default {
lang: {
title: "Language",
description: "Language of the content",
defaultValue: "en-US",
defaultValue: "en_US",
type: "string",
toolbar: {
items: [
{ value: "en-US", title: "🇺🇸", right: "English (US)" },
{ value: "ja", title: "🇯🇵", right: "日本語" },
{ value: "ko", title: "🇰🇷", right: "한국어" },
{ value: "zh", title: "🇨🇳", right: "中文" },
{ value: "en_US", title: "English", right: "English (US)" },
{ value: "he", title: "Hebrew", right: "עִברִית" },
{ value: "ja", title: "Japanese", right: "日本語" },
{ value: "ko", title: "Korean", right: "한국어" },
{ value: "ar", title: "Arabic", right: "عربي" },
{ value: "zh", title: "Chinese", right: "中文" },
{ value: "fa", title: "Persian", right: "فارسی" },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see Persian on the list of supported locales, we certainly still could support it though!

{ value: "th", title: "Thai", right: "ไทย" },
],
dynamicTitle: true,
},
Expand Down
Loading
Loading