Skip to content

Commit dc32989

Browse files
filipsobolbartoszherba
authored andcommitted
docs: add Getting started section
1 parent 9b5e81b commit dc32989

File tree

15 files changed

+705
-16
lines changed

15 files changed

+705
-16
lines changed

docs/.vuepress/config.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ module.exports = {
5151
'@vuepress/active-header-links',
5252
'@vuepress/search',
5353
],
54+
55+
/**
56+
* Ref: https://v1.vuepress.vuejs.org/config/#markdown
57+
*/
58+
markdown: {
59+
extendMarkdown: md => {
60+
md.use(require('markdown-it-video'), {
61+
youtube: { width: 740, height: 416.25 }, // 16:9 ratio, where 740px is the width of the page content
62+
});
63+
}
64+
},
65+
5466
themeConfig: {
5567
sidebarDepth: 0,
5668
repo: 'https://github.com/vuestorefront/magento2/',
@@ -75,14 +87,26 @@ module.exports = {
7587
],
7688
},
7789
{
78-
title: 'Getting started',
90+
title: 'Installation & Setup',
7991
collapsable: false,
8092
children: [
81-
['/getting-started/installation', 'Installation'],
82-
['/getting-started/configure-magento', 'Configuring Magento'],
83-
['/getting-started/configure-integration', 'Configuring Vue Storefront'],
93+
['/installation-setup/installation', 'Installation'],
94+
['/installation-setup/configure-magento', 'Configuring Magento'],
95+
['/installation-setup/configure-integration', 'Configuring Vue Storefront'],
8496
],
8597
},
98+
{
99+
title: 'Getting started',
100+
collapsable: false,
101+
children: [
102+
['/getting-started/introduction', 'Introduction'],
103+
['/getting-started/project-structure', 'Project structure'],
104+
['/getting-started/configuration', 'Configuration'],
105+
['/getting-started/layouts-and-routing', 'Layouts and Routing'],
106+
['/getting-started/theme', 'Theme'],
107+
['/getting-started/internationalization', 'Internationalization']
108+
]
109+
},
86110
{
87111
title: 'Composition',
88112
collapsable: false,

docs/.vuepress/styles/index.styl

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,46 @@ a code {
2626
font-weight: bold;
2727
}
2828

29-
div.theme-default-content:not(.custom) {
30-
max-width: 1024px;
29+
q {
30+
position: relative;
31+
display: block;
32+
margin: 30px 0;
33+
padding: 40px 20px;
34+
border-radius: 8px;
3135
}
3236

37+
@media (max-width: 959px) {
38+
q {
39+
margin: 20px 0;
40+
padding: 40px 0;
41+
}
42+
}
43+
44+
q::before,
45+
q::after {
46+
position: absolute;
47+
font-size: 40px;
48+
line-height: 1;
49+
color: #9CA3AF;
50+
}
51+
52+
53+
q::before {
54+
content: '❝';
55+
top: 5px;
56+
left: 0;
57+
}
58+
59+
q::after {
60+
content: '❞';
61+
bottom: -5px;
62+
right: 0;
63+
}
64+
65+
q p {
66+
margin: 0px;
67+
font-size: 1.1rem;
68+
font-weight: 500;
69+
font-style: italic;
70+
text-align: center;
71+
}
39.4 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Configuration
2+
3+
Whenever starting a new project or jumping into an existing one, you should look into the configuration files first. They control almost every aspect of the application, including installed integrations.
4+
5+
## Mandatory configuration files
6+
7+
Every Vue Storefront project must contain two configuration files described below. They control both client and server parts of the application.
8+
9+
### `nuxt.config.js`
10+
11+
**The `nuxt.config.js` file is the starting point of every project.** It contains general configuration, including routes, global middlewares, internationalization, or build information. This file also registers modules and plugins to add or extend framework features. Because almost every Vue Storefront integration has a module or plugin, you can identify which integrations are used by looking at this file.
12+
13+
You can learn more about this file and available configuration options on the [Nuxt configuration file](https://nuxtjs.org/docs/directory-structure/nuxt-config/) page.
14+
15+
### `middleware.config.js`
16+
17+
The `middleware.config.js` file is as essential as `nuxt.config.js`, but much simpler and likely smaller. It configures the Server Middleware used for communication with e-commerce platforms and contains sensitive credentials, custom endpoints, queries, etc.
18+
19+
### `.env`
20+
21+
The `.env` file contains environmental variables used in both `nuxt.config.js` and `middleware.config.js` files for configuration that differs per environment. New projects come with a `.env.example` that you can rename (or clone) to the `.env` file and configure.
22+
23+
## Optional configuration files
24+
25+
Your project might include some additional configuration files not described above. Let's walk through the most common ones.
26+
27+
- [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) configures compiler used to strongly type the project using TypeScript language. It defines a list of files and directories to be included and excluded from analysis and compiling.
28+
29+
- [`babel.config.js`](https://babeljs.io/docs/en/config-files) configures Babel compiler used to make the code backward compatible with older browsers and environments.
30+
31+
- [`ecosystem.config.js`](https://pm2.keymetrics.io/docs/usage/application-declaration/) configures PM2 Process Management that runs and manages Node application.
32+
33+
- [`jest.config.js`](https://jestjs.io/docs/configuration) configures Jest testing framework, used for writing and running unit tests.
34+
35+
## What's next
36+
37+
As the next step, we will learn about [Layouts and Routing](./layouts-and-routing.html) and show what routes come predefined in every Vue Storefront project and how to register custom ones.
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Internationalization
2+
3+
If you're building a shop for an international brand, you likely want it translated to different languages and using different currencies. In this document, you will learn how we're approaching internationalization in Vue Storefront and how to configure your application to use it.
4+
5+
::: warning i18n is not multi-tenancy!
6+
This document only explains how to make a single shop instance available for multiple countries. If you need to build a system for multiple tenants, we suggest creating an instance of Vue Storefront for each tenant and sharing common resources through an NPM package.
7+
:::
8+
9+
## How it works by default?
10+
11+
By default, we are using the [`nuxt-i18n`](https://i18n.nuxtjs.org/) module for handling both translations and currencies. It's preinstalled in the [default theme](/getting-started/theme.html#what-s-makes-a-default-theme) and is configured for English and German translations out of the box.
12+
13+
The `nuxt-i18n` module adds the `$t('key')` and `$n(number)` helpers to translate strings and format the currencies.
14+
15+
You can find the translation keys in the `lang` directory of your project and configuration for currencies in `nuxt.config.js`.
16+
17+
::: tip
18+
Even though the module is included in the default theme, it's not required. You can [disable it](#configuring-modules-separately) and handle internationalization yourself.
19+
:::
20+
21+
To provide a unified way to configure internationalization across the application for different modules and integrations, we have introduced the `i18n` field in each module's configuration. It has the same format as the `nuxt-i18n` options. You can add any configuration there, and it will be propagated to all other Vue Storefront modules.
22+
23+
All Vue Storefront integrations have the `useNuxtI18nConfig` property set to `true`. It means that they will use the same configuration as you provided for `nuxt-i18n` in the `i18n` field of your `nuxt.config.js`.
24+
25+
```js
26+
// nuxt.config.js
27+
28+
export default {
29+
buildModules: [
30+
[
31+
'@vue-storefront/{INTEGRATION}/nuxt',
32+
{
33+
// other comfiguration options
34+
i18n: {
35+
useNuxtI18nConfig: true,
36+
},
37+
},
38+
],
39+
],
40+
i18n: {
41+
locales: [
42+
{
43+
code: 'en',
44+
label: 'English',
45+
file: 'en.js',
46+
iso: 'en',
47+
},
48+
{
49+
code: 'de',
50+
label: 'German',
51+
file: 'de.js',
52+
iso: 'de',
53+
},
54+
],
55+
defaultLocale: 'en',
56+
},
57+
};
58+
```
59+
60+
## Configuring modules separately
61+
62+
You can provide your own i18n configuration for a specific module by setting `useNuxtI18nConfig` to `false`.
63+
64+
```js
65+
// nuxt.config.js
66+
67+
export default {
68+
[
69+
'@vue-storefront/{INTEGRATION}/nuxt',
70+
{
71+
i18n: {
72+
useNuxtI18nConfig: false,
73+
locales: [
74+
{
75+
code: 'en',
76+
label: 'English',
77+
file: 'en.js',
78+
iso: 'en',
79+
},
80+
{
81+
code: 'de',
82+
label: 'German',
83+
file: 'de.js',
84+
iso: 'de',
85+
},
86+
],
87+
defaultLocale: 'en'
88+
}
89+
}
90+
];
91+
}
92+
```
93+
94+
## CDN and cookies
95+
96+
The server's response cannot contain the `Set-Cookie` header to make CDNs cache the website correctly.
97+
98+
To achieve that, we've made our own mechanism for handling cookies responsible for storing `locale`, `currency`, and `country`. This mechanism also handles language detection and redirecting to the proper locale. For this reason, `@nuxtjs/i18n` language detection is disabled by default.
99+
100+
```js
101+
// nuxt.config.js
102+
export default {
103+
i18n: {
104+
detectBrowserLanguage: false,
105+
},
106+
};
107+
```
108+
109+
If you don't want to redirect users, you can disable this mechanism, as described in the section below.
110+
111+
## Disabling the auto-redirect mechanism
112+
113+
The `@vue-storefront/nuxt` module includes an auto-redirect mechanism that performs a server-side redirect to different URLs based on the target locale.
114+
115+
You can disable this by setting `autoRedirectByLocale` to `false` in the `i18n` configuration object.
116+
117+
```js
118+
// nuxt.config.js
119+
120+
export default {
121+
i18n: {
122+
autoRedirectByLocale: false,
123+
},
124+
};
125+
```
126+
127+
## Currency detection
128+
129+
In addition to language detection, we also set currency based on locale. You can configure it in `nuxt.config.js` with the `vueI18n.numberFormats` property.
130+
131+
For more configuration options of `numberFormats` entries, check the [Intl.NumberFormat()](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/intl/numberformat) documentation.
132+
133+
```js
134+
// nuxt.config.js
135+
136+
export default {
137+
i18n: {
138+
vueI18n: {
139+
numberFormats: {
140+
en: {
141+
currency: {
142+
style: 'currency',
143+
currency: 'USD',
144+
currencyDisplay: 'symbol',
145+
},
146+
},
147+
// ...other locales
148+
},
149+
},
150+
},
151+
};
152+
```
153+
154+
**Please note that only one currency can be set for each locale.**
155+
156+
If this is a limitation for you, or if you don't want to have currencies tied to locales, you can disable this mechanism and provide your own.
157+
158+
To disable it, set `autoChangeCookie.currency` to `false` as described in the section below.
159+
160+
## Configuring the Auto Cookie Change
161+
162+
You can configure how `@vue-storefront/nuxt` handles cookie changes when the locale changes with the `autoChangeCookie` object.
163+
164+
The `autoChangeCookie` object holds three properties directly linked to `currency`, `locale`, and `country`. These properties control how the module handles changing cookies.
165+
166+
If set to `false`, the module won't change any cookies based on configurations or browser locale, and the integration will have to handle it.
167+
168+
```js
169+
// nuxt.config.js
170+
171+
export default {
172+
buildModules: [
173+
[
174+
'@vue-storefront/{INTEGRATION}/nuxt',
175+
{
176+
i18n: {
177+
useNuxtI18nConfig: true,
178+
},
179+
},
180+
],
181+
],
182+
i18n: {
183+
locales: [
184+
{
185+
code: 'en',
186+
label: 'English',
187+
file: 'en.js',
188+
iso: 'en',
189+
},
190+
{
191+
code: 'de',
192+
label: 'German',
193+
file: 'de.js',
194+
iso: 'de',
195+
},
196+
],
197+
defaultLocale: 'en',
198+
autoChangeCookie: {
199+
currency: false,
200+
locale: false,
201+
country: false,
202+
},
203+
},
204+
};
205+
```
206+
207+
## Configuring cookie attributes
208+
209+
You can overwrite the default `locale`, `currency`, and `country` cookie attributes set by `@vue-storefront/nuxt` or add custom attributes.
210+
211+
To do so, add the `cookieOptions` object to the `i18n` configuration object in the `nuxt.config.js` file and specify the attributes you'd like the cookies to have.
212+
213+
```js
214+
// nuxt.config.js
215+
216+
export default {
217+
i18n: {
218+
cookieOptions: {
219+
// default attributes used by the `@vue-storefront/nuxt` module
220+
path: '/',
221+
sameSite: 'lax',
222+
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)),
223+
},
224+
},
225+
};
226+
```

0 commit comments

Comments
 (0)