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

fix: default language settings #1458

Merged
merged 2 commits into from
Apr 29, 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
6 changes: 4 additions & 2 deletions packages/nuxt-module/__tests__/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ describe("nuxt-module - ShopwarePWAModule runModule", () => {
it("should copy target static directory to project root directory after production build", async () => {
moduleObject.options.dev = false;
const afterBuildMethods: any[] = [];
moduleObject.nuxt.hook.mockImplementationOnce(
(hookName: string, method: Function) => afterBuildMethods.push(method)
moduleObject.nuxt.hook.mockImplementation(
(hookName: string, method: Function) => {
hookName === "build:done" && afterBuildMethods.push(method);
}
);
await runModule(moduleObject, {});
expect(moduleObject.nuxt.hook).toBeCalledWith(
Expand Down
10 changes: 5 additions & 5 deletions packages/nuxt-module/plugins/domain.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Middleware from "./middleware";
import VueCompositionAPI, { computed, ref } from "@vue/composition-api";
import { useSessionContext } from "@shopware-pwa/composables";
import Vue from "vue";
import { computed } from "@vue/composition-api";
import { useSessionContext, useSharedState } from "@shopware-pwa/composables";
const FALLBACK_DOMAIN = "<%= options.fallbackDomain %>" || "/";
const FALLBACK_LOCALE = "<%= options.fallbackLocale %>";
const PWA_HOST = "<%= options.pwaHost %>";
const domainsList = require("sw-plugins/domains");
Vue.use(VueCompositionAPI);

const currentDomainData = ref();
// register domains based routing and configuration
export default ({ app, route }, inject) => {
const { sharedRef } = useSharedState(app);
const currentDomainData = sharedRef("sw-current-domain");

const routeDomainUrl = computed(() => route.meta?.[0]?.url);
const routeDomain = computed(() =>
Object.values(domainsList).find(
Expand Down
7 changes: 6 additions & 1 deletion packages/nuxt-module/plugins/i18n.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { useSharedState } from "@shopware-pwa/composables";
import Vue from "vue";
import VueI18n from "vue-i18n";

Vue.use(VueI18n);

export default ({ app }, inject) => {
const { sharedRef } = useSharedState(app);
const currentDomainData = sharedRef("sw-current-domain");
// Set i18n instance on app
// This way we can use it in middleware and pages asyncData/fetch
const i18n = new VueI18n({
locale: "en-GB",
locale:
patzick marked this conversation as resolved.
Show resolved Hide resolved
currentDomainData.value?.languageLocaleCode ||
"<%= options.defaultLanguage %>",
fallbackLocale: "<%= options.defaultLanguage %>",
messages: {
// <% options.availableLocales.forEach(function(availableLocale) { %>
Expand Down
11 changes: 6 additions & 5 deletions packages/nuxt-module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export async function runModule(
);
}

/* In here instantiate new routing */
await setupDomains(moduleObject, shopwarePwaConfig);

moduleObject.addPlugin({
src: path.join(__dirname, "..", "plugins", "price-filter.js"),
fileName: "price-filter.js",
Expand Down Expand Up @@ -116,6 +119,9 @@ export async function runModule(
});
});

// locales
extendLocales(moduleObject, shopwarePwaConfig);

moduleObject.addPlugin({
fileName: "api-client.js",
src: path.join(__dirname, "..", "plugins", "api-client.js"),
Expand Down Expand Up @@ -161,9 +167,6 @@ export async function runModule(
);
});

// locales
extendLocales(moduleObject, shopwarePwaConfig);

moduleObject.extendBuild((config: WebpackConfig, ctx: WebpackContext) => {
const swPluginsDirectory = path.join(
moduleObject.options.rootDir,
Expand All @@ -177,8 +180,6 @@ export async function runModule(
});

extendCMS(moduleObject, shopwarePwaConfig);
/* In here instantiate new routing */
setupDomains(moduleObject, shopwarePwaConfig);

moduleObject.options.build = moduleObject.options.build || {};
moduleObject.options.build.babel = moduleObject.options.build.babel || {};
Expand Down