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: language switcher #230

Merged
merged 23 commits into from
Jun 14, 2023
Merged

feat: language switcher #230

merged 23 commits into from
Jun 14, 2023

Conversation

mdanilowicz
Copy link
Collaborator

@mdanilowicz mdanilowicz commented May 24, 2023

Description

closes #222

Type of change

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

Screenshots (if applicable)

Additional context

@vercel
Copy link

vercel bot commented May 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
frontends-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2023 7:46am
shopware-frontends-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2023 7:46am

Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

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

Just one more thing with switching bug (in comment)

const data = await changeLanguage((option.target as HTMLSelectElement).value);

if (data.redirectUrl) {
window.location.replace(replaceToDevStorefront(data.redirectUrl));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe it should, as it should cause re-render without the need of loading all the assets. I'm fine with this if it's quick enough though :)
Wanted to test that, but I've found that there is some bug.

  1. I went to preview: https://frontends-demo-git-feat-gh-222-shopware-frontends.vercel.app/
  2. Switched language to "Polish"
  3. I landed on page https://demo-frontends.shopware.store/pl-PL
    image

Comment on lines 35 to 36
const { locale } = useI18n();
const { availableLocales } = useI18n();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const { locale } = useI18n();
const { availableLocales } = useI18n();
const { locale, availableLocales } = useI18n();

Copy link
Collaborator

@mkucmus mkucmus left a comment

Choose a reason for hiding this comment

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

Big thing! I left some comments to consider 🍉

vueI18n: {
fallbackLocale: "en-GB",
},
strategy: "prefix_except_default",
Copy link
Collaborator

Choose a reason for hiding this comment

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

needed explanation in vue-demo-store/README.md why's that and what configuration in the backend should look like to have it working smoothly 📝

@@ -156,7 +157,7 @@ onBeforeMount(async () => {
<NuxtLink
class="justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-brand-primary hover:bg-brand-dark focus:outline-none focus:ring-2 focus:ring-brand-primary mt-auto"
data-testid="my-account-change-default-billing-address-button"
to="/account/address"
:to="localePath(`/account/address`)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

also in the docs wee need to mention that our translation mechanism bases on locale path.
maybe globally in few words + linking to the nuxt module that we are using

Comment on lines 16 to 23
getAvailableLanguages(): Promise<EntityResult<"language", Language>>;
changeLanguage(languageId: string): Promise<ContextTokenResponse>;
getLanguageCodeFromId(languageId: string): string;
getLanguageIdFromCode(languageCode: string): string;
replaceToDevStorefront(url: string): string;
languages: Ref<Language[]>;
currentLanguage: Ref<string>;
currentPrefix: Ref<string>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add jsDocs for all exposed methods following #91

const data = await changeLanguage((option.target as HTMLSelectElement).value);

if (data.redirectUrl) {
window.location.replace(replaceToDevStorefront(data.redirectUrl));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would also add that data.redirectUrl contains only the domain (with or without prefix/suffix etc). but being on specific pretty url like /Summer-T-Shirt for polish store may have a path like /Wakacyjny-T-Shirt. The redirect for always a main page isn't enough here and we need to combine domain + current path (translated if exists) when switching the language. Sounds like a bigger task for separate issue, right?

Copy link
Collaborator

@patzick patzick left a comment

Choose a reason for hiding this comment

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

🌎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Language switcher
3 participants