Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Adds useAcceptLanguages() hook#909

Merged
cartogram merged 3 commits intomasterfrom
get-locale
Aug 30, 2019
Merged

Adds useAcceptLanguages() hook#909
cartogram merged 3 commits intomasterfrom
get-locale

Conversation

@cartogram
Copy link
Copy Markdown
Contributor

@cartogram cartogram commented Aug 26, 2019

Description

Fixes (issue #931)

Type of change

  • Patch: Bug/ Documentation fix (non-breaking change which fixes an issue or adds documentation)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have prefixed my pull request title with the corresponding emoji from this guide

@cartogram cartogram requested a review from lemonmade August 26, 2019 21:26
Comment thread packages/react-network/src/manager.ts Outdated

getLocale(fallback = 'en') {
const acceptsLanguages = this.getHeader(Header.AcceptLanguage);
const locales = acceptsLanguages ? acceptsLanguages.split(',') : [fallback];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The split(',') is most-definitely not enough, but want to get a general approval for this PR before getting a more robust parseLanguages thing there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good example of something I've seen a bunch in our projects lately. This is (IMO) the wrong place to have this kind of abstraction. It is something most users of the package won't need, or, if they do need it, it is something to do with our usage of projects together, and so the abstraction should live there instead. If we want all consumers of react-i18n to be able to get this feature, we put this logic in that library instead (it can useHeader and do this logic itself). If it's something we want to happen automatically in react-server, it can live in that library instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like this being in react-i18n, it seems very weird for that library to depend on @shopify/react-network

Comment thread packages/react-network/src/test/manager.test.ts Outdated
Copy link
Copy Markdown
Contributor

@lemonmade lemonmade left a comment

Choose a reason for hiding this comment

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

Header normalization logic looks good but I am not a fan of this as the place for the locale related info

Comment thread packages/react-network/src/manager.ts Outdated

getLocale(fallback = 'en') {
const acceptsLanguages = this.getHeader(Header.AcceptLanguage);
const locales = acceptsLanguages ? acceptsLanguages.split(',') : [fallback];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good example of something I've seen a bunch in our projects lately. This is (IMO) the wrong place to have this kind of abstraction. It is something most users of the package won't need, or, if they do need it, it is something to do with our usage of projects together, and so the abstraction should live there instead. If we want all consumers of react-i18n to be able to get this feature, we put this logic in that library instead (it can useHeader and do this logic itself). If it's something we want to happen automatically in react-server, it can live in that library instead.

Comment thread packages/react-i18n/src/hooks.tsx Outdated

import {useLazyRef} from '@shopify/react-hooks';

import {useRequestHeader, Header} from '@shopify/react-network';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this a dependency we want to add to @shopify/react-i18n? It seems weird to me that react-i18n would have this

Comment thread packages/react-i18n/src/hooks.tsx Outdated
return [i18n, shareTranslationsComponent.current];
}

export function useAcceptLanguages(fallback = 'en') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like this should be part of @shopify/react-network, or some other package that handles the concerns of specifically using @shopify/react-i18n with @shopify/react-network. Maybe even @shopify/react-server?

Comment thread packages/react-network/src/manager.ts Outdated

getLocale(fallback = 'en') {
const acceptsLanguages = this.getHeader(Header.AcceptLanguage);
const locales = acceptsLanguages ? acceptsLanguages.split(',') : [fallback];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like this being in react-i18n, it seems very weird for that library to depend on @shopify/react-network

@cartogram cartogram changed the title adds getLocale to react-network Adds useAcceptLanguages() hook Aug 29, 2019
@cartogram
Copy link
Copy Markdown
Contributor Author

@lemonmade @TheMallen re-did this as a stand-alone hook in react-network, how does this look/ feel?

Comment thread packages/react-network/src/hooks.ts Outdated
Comment thread packages/react-network/src/test/hooks.test.tsx Outdated
Comment thread packages/react-network/src/test/hooks.test.tsx Outdated
Copy link
Copy Markdown
Contributor

@marutypes marutypes left a comment

Choose a reason for hiding this comment

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

very simple very nice

@cartogram cartogram dismissed lemonmade’s stale review August 30, 2019 18:01

made requested changes

@cartogram cartogram merged commit b727c88 into master Aug 30, 2019
@cartogram cartogram deleted the get-locale branch August 30, 2019 18:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants