Skip to content

Commit

Permalink
Bugfix/BUS 939 fix language switching (#94)
Browse files Browse the repository at this point in the history
* Create new component for formatting links according to the current locale

* Synchronize the back-end language with the front-end language

* Accept RouteObject for the `to` prop

* Lint

* Rename `FormattedLink` to `LocaleLink`

* Add usage example

* Expand language synchronization comment

* Remove redundant script tag
  • Loading branch information
dd-ast authored Dec 13, 2024
1 parent 88b3c7a commit c38ec87
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 64 deletions.
8 changes: 4 additions & 4 deletions components/Account/AccountLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ const handleLogin = async (fields: FormkitLoginFields) => {
v-if="!signedIn"
class="mt-2 flex justify-between"
>
<NuxtLink
<LocaleLink
v-if="showCreateLink"
to="/account/register"
class="hover:text-brand-primary"
>
{{ $t('account.login.createAccountLink') }}
</NuxtLink>
</LocaleLink>

<NuxtLink
<LocaleLink
v-if="showRecoverLink"
to="/account/recover"
class="hover:text-brand-primary"
:class="{ 'text-right': showCreateLink }"
@click="$emit('closeModal')"
>
{{ $t('account.login.recoverPasswordLink') }}
</NuxtLink>
</LocaleLink>
</div>
</template>
4 changes: 2 additions & 2 deletions components/Account/AccountRecoverPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const handlePasswordChange = async (fields: FormkitFields) => {
<template>
<template v-if="!hashIsValid">
<p class="text-center text-status-danger">{{ $t('account.recoverPassword.recover.linkNotValid') }}</p>
<NuxtLink
<LocaleLink
to="/account/recover"
class="m-auto mt-4 flex w-1/2 items-center justify-center rounded bg-brand-primary px-4 py-2 text-white hover:bg-brand-primary-dark"
>
{{ $t('account.recoverPassword.recover.requestNewLink') }}
</NuxtLink>
</LocaleLink>
</template>

<FormKit
Expand Down
4 changes: 2 additions & 2 deletions components/Account/AccountResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ const getEnvironmentStorefrontUrl = (): string => {
<p>
{{ $t('account.recoverPassword.request.successMessage') }}
</p>
<NuxtLink
<LocaleLink
to="/account/login"
class="mt-4 flex w-full justify-center rounded bg-brand-primary px-4 py-2 text-white hover:bg-brand-primary-dark"
>
{{ $t('account.recoverPassword.request.loginButtonLabel') }}
</NuxtLink>
</LocaleLink>
</template>
</template>
4 changes: 2 additions & 2 deletions components/Account/AccountSideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const navItems = ref([
class="mt-4 pb-4 pl-2"
:class="{ 'border-b border-gray': index !== navItems.length - 1 }"
>
<NuxtLink
<LocaleLink
:to="item.path"
class="text-lg"
:class="{ 'font-bold': isActive(item.path, true) }"
>
{{ item.label }}
</NuxtLink>
</LocaleLink>
</li>
<li>
<FormKit
Expand Down
4 changes: 2 additions & 2 deletions components/Account/Order/AccountOrderItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ onMounted(async () => {
{{ status }}
</div>

<NuxtLink
<LocaleLink
v-if="isPaymentNeeded"
class="rounded-md bg-brand-primary px-2 py-2 text-white"
:to="`/account/order/edit/${orderId}`"
>
{{ $t('account.orders.changePaymentMethod') }}
</NuxtLink>
</LocaleLink>
</div>

<div class="gap-12 text-left lg:flex">
Expand Down
8 changes: 4 additions & 4 deletions components/Checkout/CheckoutLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const debounceUpdate = useDebounceFn(updateQuantity, 600);

<template>
<div class="mr-4 h-24 w-24 flex-shrink-0 overflow-hidden rounded-md border border-gray-medium bg-gray-light">
<NuxtLink
<LocaleLink
v-if="!isPromotion"
:to="getProductRoute(lineItem)"
>
Expand All @@ -113,7 +113,7 @@ const debounceUpdate = useDebounceFn(updateQuantity, 600);
class="h-full w-full object-cover object-center"
/>
</template>
</NuxtLink>
</LocaleLink>
<div
v-else-if="isPromotion"
class="flex h-full w-full items-center justify-center"
Expand All @@ -128,11 +128,11 @@ const debounceUpdate = useDebounceFn(updateQuantity, 600);
<div class="flex flex-1 flex-col">
<div>
<div class="flex flex-col justify-between gap-4 lg:flex-row">
<NuxtLink :to="getProductRoute(lineItem)">
<LocaleLink :to="getProductRoute(lineItem)">
<p>
{{ lineItem.label }}
</p>
</NuxtLink>
</LocaleLink>

<span v-if="itemTotalPrice">
{{ getFormattedPrice(itemTotalPrice) }}
Expand Down
8 changes: 4 additions & 4 deletions components/Cms/Element/CmsElementCategoryNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ const { isActive } = useActivePath();
:key="item.id"
class="mt-4 border-b border-gray pb-4 pl-2"
>
<NuxtLink
<LocaleLink
:to="getCategoryRoute(item)"
class="text-lg"
:class="{ 'font-bold': isActive(item.seoUrls) }"
>
{{ getTranslatedProperty(item, 'name') }}
</NuxtLink>
</LocaleLink>
<ul v-if="item.children && item.children.length">
<li
v-for="child in item.children"
:key="child.id"
class="ml-3 mt-2 text-base"
>
<NuxtLink
<LocaleLink
:to="getCategoryRoute(child)"
:class="{ 'font-bold': isActive(child.seoUrls) }"
>
{{ getTranslatedProperty(child, 'name') }}
</NuxtLink>
</LocaleLink>
</li>
</ul>
</li>
Expand Down
4 changes: 2 additions & 2 deletions components/Error/ErrorNotFound.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
{{ $t('error.404.detail') }}
</p>

<NuxtLink
<LocaleLink
class="bg-brand-primary p-4 text-white hover:bg-brand-primary-dark"
:to="'/'"
>
{{ $t('global.homepageLinkLabel') }}
</NuxtLink>
</LocaleLink>
</ErrorLayout>
</template>
4 changes: 2 additions & 2 deletions components/Error/ErrorServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ defineProps<{
{{ $t('error.server.detail') }}
</p>

<NuxtLink
<LocaleLink
class="bg-brand-primary p-4 text-white hover:bg-brand-primary-dark"
:to="'/'"
>
{{ $t('global.homepageLinkLabel') }}
</NuxtLink>
</LocaleLink>
</main>
</template>
4 changes: 2 additions & 2 deletions components/Error/ErrorUnknown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ defineProps<{
{{ $t('error.unknown.detail') }}
</p>

<NuxtLink
<LocaleLink
class="bg-brand-primary p-4 text-white hover:bg-brand-primary-dark"
:to="'/'"
>
{{ $t('global.homepageLinkLabel') }}
</NuxtLink>
</LocaleLink>
</ErrorLayout>
</template>
2 changes: 1 addition & 1 deletion components/LanguageSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const onLanguageChange = async (option: Event) => {
}
};
const languageOptions = computed(() => entityArrayToOptions<Schemas['language']>(languages.value, 'name', true) ?? []);
const languageOptions = computed(() => entityArrayToOptions<Schemas['Language']>(languages.value, 'name', true) ?? []);
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions components/Layout/Header/LayoutHeaderCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const { cartItemsWithProduct, cartItemsCount } = storeToRefs(cartItemsStore);
<CheckoutSummary :reduced-display="true" />
</div>

<NuxtLink
<LocaleLink
to="/checkout/cart"
class="mt-4 flex items-center justify-center rounded-md bg-brand-primary px-6 py-3 text-white"
@click="offcanvasCartController.close()"
>
{{ $t('checkout.offcanvasCart.toCartButtonLabel') }}
</NuxtLink>
</LocaleLink>
</template>
</LazyLayoutSidebar>
</template>
4 changes: 2 additions & 2 deletions components/Layout/Header/LayoutHeaderWishlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { count: wishlistCount } = useWishlist();
</script>

<template>
<NuxtLink
<LocaleLink
to="/wishlist"
class="relative"
>
Expand All @@ -15,5 +15,5 @@ const { count: wishlistCount } = useWishlist();
:number="wishlistCount"
class="absolute bottom-2.5 left-3"
/>
</NuxtLink>
</LocaleLink>
</template>
8 changes: 4 additions & 4 deletions components/Layout/Header/Search/LayoutHeaderSearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ onMounted(() => {
v-if="showSuggest"
class="z-1 container fixed left-0 right-0 rounded-b-md border-t border-gray-medium bg-white p-0 shadow-md"
>
<NuxtLink
<LocaleLink
v-for="product in getProducts?.slice(0, displayTotal)"
:key="product.id"
:to="getProductRoute(product)"
@click="onClickProduct(product)"
>
<LayoutHeaderSearchSuggestions :product="product" />
</NuxtLink>
</LocaleLink>

<div class="bg-gray-light text-center text-sm hover:bg-gray-medium">
<div
Expand All @@ -144,7 +144,7 @@ onMounted(() => {
</div>

<template v-else>
<NuxtLink
<LocaleLink
v-if="getTotal > 0"
:to="'/search?search=' + typingQuery"
class="block w-full py-3"
Expand All @@ -157,7 +157,7 @@ onMounted(() => {
<template v-else>
<span>{{ $t('search.searchBar.oneResultLinkLabel') }}</span>
</template>
</NuxtLink>
</LocaleLink>

<div
v-else
Expand Down
8 changes: 4 additions & 4 deletions components/Layout/LayoutBreadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ withDefaults(
v-if="displayRoot"
class="inline-flex items-center gap-2"
>
<NuxtLink
<LocaleLink
:to="'/'"
class="inline-flex items-center gap-2 text-sm font-medium last:text-brand-primary hover:text-brand-primary"
>
Expand All @@ -33,7 +33,7 @@ withDefaults(
class="h-4 w-4"
/>
{{ $t('layout.breadcrumb.homeLinkLabel') }}
</NuxtLink>
</LocaleLink>

<FormKitIcon
v-if="breadcrumbs?.length > 0"
Expand All @@ -47,13 +47,13 @@ withDefaults(
:key="breadcrumb.path"
class="inline-flex items-center gap-2"
>
<NuxtLink
<LocaleLink
v-if="breadcrumb.path"
:to="breadcrumb.path"
class="inline-flex items-center text-sm font-medium last:text-brand-primary hover:text-brand-primary"
>
{{ breadcrumb.name }}
</NuxtLink>
</LocaleLink>

<span
v-else
Expand Down
12 changes: 6 additions & 6 deletions components/Layout/LayoutFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ onMounted(async () => {
>
<ul class="list-none">
<li class="mb-1 max-w-max font-bold hover:text-brand-primary hover:underline">
<NuxtLink
<LocaleLink
:target="
navigationElement.externalLink || navigationElement.linkNewTab ? '_blank' : ''
"
:to="getCategoryRoute(navigationElement)"
>
{{ getTranslatedProperty(navigationElement, 'name') }}
</NuxtLink>
</LocaleLink>
</li>
<li
v-for="navigationChild in navigationElement.children"
:key="navigationChild.id"
>
<NuxtLink
<LocaleLink
:target="navigationChild.externalLink || navigationChild.linkNewTab ? '_blank' : ''"
:to="getCategoryRoute(navigationChild)"
class="text-sm font-normal transition duration-200 hover:text-brand-primary hover:underline"
>
{{ getTranslatedProperty(navigationChild, 'name') }}
</NuxtLink>
</LocaleLink>
</li>
</ul>
</template>
Expand All @@ -58,13 +58,13 @@ onMounted(async () => {
v-for="navigationElement in serviceNavigationElements"
:key="navigationElement.id"
>
<NuxtLink
<LocaleLink
:target="navigationElement.externalLink || navigationElement.linkNewTab ? '_blank' : ''"
:to="getCategoryRoute(navigationElement)"
class="text-sm font-normal transition duration-200 hover:text-brand-primary hover:underline"
>
{{ getTranslatedProperty(navigationElement, 'name') }}
</NuxtLink>
</LocaleLink>
</template>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/Layout/LayoutLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const shopName = 'pond';
</script>

<template>
<NuxtLink
<LocaleLink
:aria-label="shopName"
:title="shopName"
:to="withLink ? '/' : ''"
Expand All @@ -36,5 +36,5 @@ const shopName = 'pond';
:alt="shopName"
:class="logoClasses"
/>
</NuxtLink>
</LocaleLink>
</template>
Loading

0 comments on commit c38ec87

Please sign in to comment.