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

feat(i18n): add i18n support #951

merged 34 commits into from
Feb 28, 2019

Conversation

gergelyke
Copy link
Contributor

this is a PoC implementation for the i18n support - please let me know what you think, and if everyone is onboard, I'll extend it for the rest of the codebase in this PR

if (__DEV__ && this.props['aria-label']) {
// eslint-disable-next-line no-console
console.warn(
`Providing i18n data through properties will be removed in the next major version. Please use the LocalProvider.`,
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to remove the props? They are straightforward to use and can be handy for some tweaks and overrides even when the LocalProvider is used. Also, it's not a big overhead for us and seems like an unnecessary breaking change that requires a lot of grunt work to fix.

// The only thing I would change is to group them into a single this.props.translate object so it's consistent across all components and doesn't pollute the top-level props but that ship already sailed.

Copy link
Contributor Author

@gergelyke gergelyke Feb 25, 2019

Choose a reason for hiding this comment

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

That can work too - the idea behind it was to make sure we only have a single API interface to maintain (and make it straightforward from a consumer point of view too, which way they have to if they wany i18n), but I guess we can go either way.

What do you think @nadiia @tajo @schnerd @chasestarr ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's keep the props as they are - I am going to update this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree on keeping the aria attr in props 👍 For those who don't use i18n would be slightly too much work to do in order to change those if removed, specifically for an input case, for example.

};

export type LocaleT = {|
datepicker: DatepickerLocaleT,
Copy link
Member

@tajo tajo Feb 25, 2019

Choose a reason for hiding this comment

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

Should we be overriding the English locale and keeping all LocaleT props optional?

Copy link
Member

Choose a reason for hiding this comment

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

I mean user can do that but it should be a deepMerge and seems nice to do it by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes perfect sense 👍

@@ -170,7 +162,7 @@ export default class Datepicker extends React.Component<
<InputComponent
aria-disabled={this.props.disabled}
aria-label={
locale.datepicker.ariaLabel || this.props['aria-label']
this.props['aria-label'] || locale.datepicker.ariaLabel
Copy link
Member

Choose a reason for hiding this comment

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

Nice. I wanted to point this one out. 👍

src/locale/en_US.js Outdated Show resolved Hide resolved
src/locale/types.js Outdated Show resolved Hide resolved
Copy link
Contributor

@nadiia nadiia left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

Copy link
Contributor

@schnerd schnerd left a comment

Choose a reason for hiding this comment

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

This looks great!

const {overrides = {}} = props;
const [Root, rootProps] = getOverrides(overrides.Root, StyledRoot);

return (
<Root aria-label={props.ariaLabel} {...rootProps}>
<Root
Copy link
Collaborator

Choose a reason for hiding this comment

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

could context consumer be placed here rather than in the wrapper component? not sure why locale needs to be provided through props

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, sadly enyzme does not fully support contexts, so sadly the test framework affected our production code :(

is this correct @tajo ?

Copy link
Member

Choose a reason for hiding this comment

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

Yea, this is a workaround for Enzyme. It can't shallow render the renderProp.

Copy link
Collaborator

Choose a reason for hiding this comment

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

could we simply mount and avoid the indirection? i've found that code bases grow in puzzling ways when ad hoc refactoring to enable test patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, 100%.

We've tried that too, it won't work - I think Vojtech will want to bring up the issues with enzyme, and start a chat on what we can do about it

for now, would you be ok with it as is, and fix it once we figure out what to do with enzyme?

Copy link
Collaborator

Choose a reason for hiding this comment

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

for sure - i would personally prefer to remove the test than add the additional indirection, but up to you

{...sharedProps}
{...getOverrideProps(CloseOverride)}
{...getOverrideProps(DialogOverride)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

😮 👍

@gergelyke gergelyke merged commit 26a8b9a into master Feb 28, 2019
@baseui-probot-app-workflow baseui-probot-app-workflow bot deleted the feat/i18n branch February 28, 2019 21:43
yogurtandjam pushed a commit to yogurtandjam/baseui that referenced this pull request Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants