Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

fix(nuxt-module): proper i18n plugin injection #1334

Merged
merged 3 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/default-theme/src/logic/notifications/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useNotifications } from "@shopware-pwa/composables"

export const addToCartNotification = (product, rootContext) => {
export const addToCartNotification = (payload, rootContext) => {
const { pushSuccess } = useNotifications(rootContext)
pushSuccess(
rootContext.i18n.t("{productName} has been added to cart.", {
productName: product?.translated?.name || product?.name,
rootContext.$t("{productName} has been added to cart.", {
productName: payload?.product?.translated?.name || payload?.product?.name,
})
)
}
Expand All @@ -16,10 +16,10 @@ export const addPromotionCodeNotification = (result, rootContext) => {
if (err) {
switch (err.messageKey) {
case "promotion-discount-added":
pushSuccess(rootContext.i18n.t("Promotion code added successfully"))
pushSuccess(rootContext.$t("Promotion code added successfully"))
break
case "promotion-not-found":
pushError(rootContext.i18n.t("Promotion code does not exist"))
pushError(rootContext.$t("Promotion code does not exist"))
break
default:
pushError(err.message.toString())
Expand Down
7 changes: 5 additions & 2 deletions packages/nuxt-module/plugins/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import VueI18n from "vue-i18n";

Vue.use(VueI18n);

export default ({ app, store }) => {
export default ({ app, store }, inject) => {
// Set i18n instance on app
// This way we can use it in middleware and pages asyncData/fetch
app.i18n = new VueI18n({
const i18n = new VueI18n({
locale: store.state.locale,
fallbackLocale: "<%= options.defaultLanguage %>",
messages: {
Expand All @@ -15,4 +15,7 @@ export default ({ app, store }) => {
// <% }) %>
},
});

app.i18n = i18n;
inject("i18n", i18n);
};