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

feat(i18n): add i18n support #951

Merged
merged 34 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca53310
feat(i18n): add i18n support
Feb 25, 2019
f4cdec4
feat(i18n): extending language files
Feb 25, 2019
d3d039b
feat(i18n): calendar-header
Feb 25, 2019
36aada3
Merge branch 'master' into feat/i18n
gergelyke Feb 25, 2019
42ad35f
docs(i18n): add cta
Feb 25, 2019
4c0d09e
feat(i18n): co-locate locale files
Feb 25, 2019
d8ef6b2
Merge branch 'master' into feat/i18n
gergelyke Feb 25, 2019
bdb6726
fix(i18n): remove unused import
Feb 25, 2019
f7ac2f3
feat(i18n): breadcrumb and accordion
Feb 25, 2019
03d1973
feat(i18n): buttongrup
Feb 25, 2019
2ba26bb
fix(i18n): breadcrumb prop
Feb 25, 2019
d72da0d
Merge branch 'master' into feat/i18n
gergelyke Feb 25, 2019
f541e2e
feat(i18n): file-uploader
Feb 25, 2019
635028d
feat(i18n): modal
Feb 25, 2019
b9ff5c9
feat(i18n): pagination
Feb 26, 2019
bf02490
feat(i18n): select
Feb 26, 2019
46d561c
feat(i18n): toast
Feb 26, 2019
4ef8859
Merge branch 'master' into feat/i18n
gergelyke Feb 26, 2019
41e1b78
Merge branch 'master' into feat/i18n
gergelyke Feb 26, 2019
029d327
Merge branch 'master' into feat/i18n
gergelyke Feb 26, 2019
cffbcb9
feat(i18n): fix ButtonGroup tests
tajo Feb 27, 2019
bd7fb02
Merge branch 'master' into feat/i18n
gergelyke Feb 27, 2019
f07ffcd
Merge branch 'master' into feat/i18n
gergelyke Feb 27, 2019
2f971f9
fix(i18n): breadcrumbs
Feb 27, 2019
083752e
fix(i18n): test coverage
Feb 27, 2019
6ef7e2e
fix(i18n): flow types
Feb 27, 2019
a040d5f
docs(i18n): add example
Feb 27, 2019
b2c2cff
fix(i18n): update snapshots
Feb 28, 2019
c21f011
Merge branch 'master' into feat/i18n
gergelyke Feb 28, 2019
6a0c288
Merge branch 'master' into feat/i18n
gergelyke Feb 28, 2019
c353798
fix(i18n): pagination
Feb 28, 2019
a2ab15d
docs(i18n): more docs
Feb 28, 2019
4ee5e45
Merge branch 'master' into feat/i18n
gergelyke Feb 28, 2019
290357f
Update src/button-group/button-group.js
chasestarr Feb 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions documentation-site/pages/getting-started/internationalization.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

import Layout from '../../components/layout';
import en_US from '../../../src/locale/en_US.js'

export default Layout;

# Internationalization

Base UI supports English as the default language. Following the instructions below, you
can use other languages too.

```javascript
import { LocaleProvider } from 'baseui';
import {huHU} from '{YOUR_PROJECT}/hu.json';
import App from '{YOUR_PROJECT}/app.js';

return (
<LocaleProvider locale={huHU}>
<App />
</LocaleProvider>
);
```

If you'd like to contribute a locale, please send a Pull Request based
on the [en_US](https://github.com/uber-web/baseui/tree/master/src/locale) locale.
4 changes: 4 additions & 0 deletions documentation-site/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const routes = [
text: 'Comparison with other component libraries',
path: '/getting-started/comparison',
},
{
text: 'Internationalization',
path: '/getting-started/internationalization',
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"dependencies": {
"date-fns": "2.0.0-alpha.27",
"focus-trap": "^4.0.2",
"just-extend": "^4.0.2",
"memoize-one": "^5.0.0",
"popper.js": "^1.14.3",
"react-dropzone": "^9.0.0",
Expand Down
19 changes: 19 additions & 0 deletions src/accordion/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

export type AccordionLocaleT = {|
collapse: string,
expand: string,
|};

const locale = {
collapse: 'Collapse',
expand: 'Expand',
};

export default locale;
57 changes: 32 additions & 25 deletions src/accordion/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import {LocaleContext} from '../locale/index.js';
import {getOverrides, mergeOverrides} from '../helpers/overrides.js';
import {
Plus as PlusIcon,
Expand Down Expand Up @@ -91,31 +92,37 @@ class Panel extends React.Component<PanelPropsT> {
);
const ToggleIconComponent = expanded ? CheckIndeterminateIcon : PlusIcon;
return (
<PanelContainer {...sharedProps} {...panelContainerProps}>
<Header
tabIndex={0}
role="button"
aria-expanded={expanded}
aria-disabled={disabled || null}
{...sharedProps}
{...headerProps}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
>
{title}
<ToggleIconComponent
size={16}
title={expanded ? 'Collapse' : 'Expand'}
{...sharedProps}
{...toggleIconProps}
// $FlowFixMe
overrides={toggleIconOverrides}
/>
</Header>
<Content {...sharedProps} {...contentProps}>
{children}
</Content>
</PanelContainer>
<LocaleContext.Consumer>
{locale => (
<PanelContainer {...sharedProps} {...panelContainerProps}>
<Header
tabIndex={0}
role="button"
aria-expanded={expanded}
aria-disabled={disabled || null}
{...sharedProps}
{...headerProps}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
>
{title}
<ToggleIconComponent
size={16}
title={
expanded ? locale.accordion.collapse : locale.accordion.expand
}
{...sharedProps}
{...toggleIconProps}
// $FlowFixMe
overrides={toggleIconOverrides}
/>
</Header>
<Content {...sharedProps} {...contentProps}>
{children}
</Content>
</PanelContainer>
)}
</LocaleContext.Consumer>
);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LICENSE file in the root directory of this source tree.

import React, {Children} from 'react';

import {LocaleContext} from '../locale/index.js';
import type {BreadcrumbsPropsT} from './types.js';
import {StyledRoot, StyledSeparator, StyledIcon} from './styled-components.js';
import {getOverrides} from '../helpers/overrides.js';
Expand Down Expand Up @@ -37,9 +38,13 @@ function Breadcrumbs({children, overrides = {}}: BreadcrumbsPropsT) {
});

return (
<Root aria-label="Breadcrumbs navigation" {...baseRootProps}>
{childrenWithSeparators}
</Root>
<LocaleContext.Consumer>
{locale => (
<Root aria-label={locale.breadcrumbs.ariaLabel} {...baseRootProps}>
{childrenWithSeparators}
</Root>
)}
</LocaleContext.Consumer>
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/breadcrumbs/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

export type BreadcrumbLocaleT = {|
ariaLabel: string,
|};

const locale = {
ariaLabel: 'Breadcrumbs navigation',
};

export default locale;
71 changes: 40 additions & 31 deletions src/button-group/button-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';

import {KIND, SIZE, SHAPE} from '../button/index.js';
import {getOverrides} from '../helpers/overrides.js';
import {LocaleContext} from '../locale/index.js';

import {StyledRoot} from './styled-components.js';
import type {PropsT} from './types.js';
Expand Down Expand Up @@ -54,43 +55,51 @@ export default function ButtonGroup(props: PropsT) {
const [Root, rootProps] = getOverrides(overrides.Root, StyledRoot);

return (
<Root aria-label={props.ariaLabel} {...rootProps}>
{React.Children.map(props.children, (child, index) => {
if (!React.isValidElement(child)) {
return null;
}

return React.cloneElement(child, {
disabled: props.disabled ? true : child.props.disabled,
isSelected: isSelected(props.selected, index),
kind: KIND.tertiary,
onClick: event => {
if (props.disabled) {
return;
<LocaleContext.Consumer>
{locale => (
<Root
aria-label={props.ariaLabel || locale.buttongroup.ariaLabel}
{...rootProps}
>
{React.Children.map(props.children, (child, index) => {
if (!React.isValidElement(child)) {
return null;
}

if (child.props.onClick) {
child.props.onClick(event);
}

if (props.onClick) {
props.onClick(event, index);
}
},
overrides: {
BaseButton: {style: getBorderRadii(index, props.children.length)},
...child.props.overrides,
},
shape: props.shape,
size: props.size,
});
})}
</Root>
return React.cloneElement(child, {
disabled: props.disabled ? true : child.props.disabled,
isSelected: isSelected(props.selected, index),
kind: KIND.tertiary,
onClick: event => {
if (props.disabled) {
return;
}

if (child.props.onClick) {
child.props.onClick(event);
}

if (props.onClick) {
props.onClick(event, index);
}
},
overrides: {
BaseButton: {
style: getBorderRadii(index, props.children.length),
},
...child.props.overrides,
},
shape: props.shape,
size: props.size,
});
})}
</Root>
)}
</LocaleContext.Consumer>
);
}

ButtonGroup.defaultProps = {
ariaLabel: 'button group',
disabled: false,
onClick: () => {},
shape: SHAPE.default,
Expand Down
17 changes: 17 additions & 0 deletions src/button-group/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

export type ButtonGroupLocaleT = {|
ariaLabel: string,
|};

const locale = {
ariaLabel: 'button group',
};

export default locale;
26 changes: 16 additions & 10 deletions src/datepicker/calendar-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LICENSE file in the root directory of this source tree.
import * as React from 'react';
import {ArrowLeft, ArrowRight} from '../icon/index.js';
import {Select} from '../select/index.js';
import {LocaleContext} from '../locale/index.js';
import {
StyledCalendarHeader,
StyledPrevButton,
Expand All @@ -27,6 +28,7 @@ import {
import {getOverrides, mergeOverrides} from '../helpers/overrides.js';
import type {HeaderPropsT} from './types.js';
import type {SharedStylePropsT} from '../select/types.js';
import type {LocaleT} from '../locale/types.js';

const navBtnStyle = ({$theme}) => ({
cursor: 'pointer',
Expand Down Expand Up @@ -59,7 +61,7 @@ export default class CalendarHeader extends React.Component<HeaderPropsT> {
this.props.onMonthChange({date: subMonths(this.props.date, 1)});
};

renderPreviousMonthButton = () => {
renderPreviousMonthButton = ({locale}: {locale: LocaleT}) => {
const {date, overrides = {}} = this.props;
const allPrevDaysDisabled = monthDisabledBefore(date, this.props);

Expand All @@ -81,7 +83,7 @@ export default class CalendarHeader extends React.Component<HeaderPropsT> {
}
return (
<PrevButton
aria-label="Previous month"
aria-label={locale.datepicker.previousMonth}
tabIndex={0}
onClick={clickHandler}
{...prevButtonProps}
Expand All @@ -98,7 +100,7 @@ export default class CalendarHeader extends React.Component<HeaderPropsT> {
);
};

renderNextMonthButton = () => {
renderNextMonthButton = ({locale}: {locale: LocaleT}) => {
const {date, overrides = {}} = this.props;
const allNextDaysDisabled = monthDisabledAfter(date, this.props);

Expand Down Expand Up @@ -126,7 +128,7 @@ export default class CalendarHeader extends React.Component<HeaderPropsT> {
}
return (
<NextButton
aria-label="Next month"
aria-label={locale.datepicker.nextMonth}
tabIndex={0}
onClick={clickHandler}
{...nextButtonProps}
Expand Down Expand Up @@ -273,12 +275,16 @@ export default class CalendarHeader extends React.Component<HeaderPropsT> {
StyledCalendarHeader,
);
return (
<CalendarHeader {...calendarHeaderProps}>
{this.renderPreviousMonthButton()}
{this.renderMonthDropdown()}
{this.renderYearDropdown()}
{this.renderNextMonthButton()}
</CalendarHeader>
<LocaleContext.Consumer>
{locale => (
<CalendarHeader {...calendarHeaderProps}>
{this.renderPreviousMonthButton({locale})}
{this.renderMonthDropdown()}
{this.renderYearDropdown()}
{this.renderNextMonthButton({locale})}
</CalendarHeader>
)}
</LocaleContext.Consumer>
);
}
}