|
1 | | -# Astro Starter Kit: Basics |
2 | 1 |
|
3 | | -```sh |
4 | | -npm create astro@latest -- --template basics |
| 2 | +# Documentation |
| 3 | +- Project is created in `astro` framework. |
| 4 | +- Project is based on Typescript mixed with Javascript language. |
| 5 | +- All the project components files are created in `.astro` format. |
| 6 | +- Project uses `i18n` for easy translations. |
| 7 | + |
| 8 | +# Running project in dev mode |
| 9 | +Run commands to setup project: |
| 10 | +`npm install` |
| 11 | +`npm run dev` |
| 12 | + |
| 13 | +Project should be stationed on `localhost` on `:4321` port. |
| 14 | + |
| 15 | +# Project file tree |
| 16 | +``` |
| 17 | +agency-v2 |
| 18 | + node_modules |
| 19 | + public |
| 20 | + static |
| 21 | + locales |
| 22 | + de.json // German translation ( not implemented ) |
| 23 | + en.json // English translations |
| 24 | + pl.json // Polish translations |
| 25 | + src |
| 26 | + assets // All of the project static images directory |
| 27 | + ... |
| 28 | + components // Multi-use components directory |
| 29 | + ... |
| 30 | + i18n // Functionalities of i18n mechanic directory |
| 31 | + ui.ts // Simple variables for language definition |
| 32 | + utils.ts // Functions for i18n mechanics |
| 33 | + layouts // Predefined components for layouts and site content directory |
| 34 | + Content.astro // Predefined main page content for all language based views |
| 35 | + Layout.astro // Predefined layout for every view |
| 36 | + pages // Astro views for given langauage directory ( default polish language ) |
| 37 | + en // Site content for english view directory |
| 38 | + about.astro // About view |
| 39 | + index.astro // Main view |
| 40 | + about.astro // About view in Polish |
| 41 | + index.astro // Main view in Polish |
| 42 | + scripts // Helper modules for site functionality directory |
| 43 | + api.ts // API requests file |
| 44 | + helpers.ts // Helper functions |
| 45 | + NavbarScripts.js // Navbar functions |
| 46 | + sections // Site sections directory |
| 47 | + ... |
| 48 | + global.css // All of the site predefined colors and css |
| 49 | + types.ts // All of the site types in one file |
| 50 | + i18next-parser.config.js // Config for i18n parser |
| 51 | +``` |
| 52 | +# i18n parser mechanic |
| 53 | +i18n `.json` files can be found in `public/static/locales/` directory. |
| 54 | +Each file represents specific language which contains translations for every sentence/word. |
| 55 | +## i18n parser run mechanic |
| 56 | +Firstly, run `npm run i18n` in your console. |
| 57 | +The parser checks every file for defined translations, then it adds them to language `.json` files with every value set to `__NOT_TRANSLATED__` by default. |
| 58 | + |
| 59 | +## Use case for translations defined in custom tags |
| 60 | + |
| 61 | +```ts |
| 62 | +--- |
| 63 | +import { getLangFromUrl, useTranslations } from "../i18n/utils"; |
| 64 | + |
| 65 | +const lang = getLangFromUrl(Astro.url); |
| 66 | +const t = useTranslations(lang); |
| 67 | +--- |
| 68 | + |
| 69 | +<CustomTag> |
| 70 | + <!-- t("Object.key") --> |
| 71 | + <p>{t("Object.key")}</p> |
| 72 | +</CustomTag> |
5 | 73 | ``` |
| 74 | +If you put translation in custom tag, then the `i18next-parser` won't see it. You need to put translation function inside comment, preferably above the tag you are using it in. |
6 | 75 |
|
7 | | -> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun! |
8 | | -
|
9 | | -## 🚀 Project Structure |
10 | | - |
11 | | -Inside of your Astro project, you'll see the following folders and files: |
12 | | - |
13 | | -```text |
14 | | -/ |
15 | | -├── public/ |
16 | | -│ └── favicon.svg |
17 | | -├── src |
18 | | -│ ├── assets |
19 | | -│ │ └── astro.svg |
20 | | -│ ├── components |
21 | | -│ │ └── Welcome.astro |
22 | | -│ ├── layouts |
23 | | -│ │ └── Layout.astro |
24 | | -│ └── pages |
25 | | -│ └── index.astro |
26 | | -└── package.json |
| 76 | +## English example |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "ExampleTranslationsHeader": { |
| 81 | + "ExampleTitle": "Translation" |
| 82 | + }, |
| 83 | + "ExampleTranslationsObjectForSpecificContentList": { |
| 84 | + "ExampleTitle": "Translation", |
| 85 | + "ExampleDescription": "Translation" |
| 86 | + } |
| 87 | +} |
27 | 88 | ``` |
28 | 89 |
|
29 | | -To learn more about the folder structure of an Astro project, refer to [our guide on project structure](https://docs.astro.build/en/basics/project-structure/). |
| 90 | +## Polish example |
| 91 | + |
| 92 | +```json |
| 93 | +{ |
| 94 | + "ExampleTranslationsHeader": { |
| 95 | + "ExampleTitle": "Tłumaczenie" |
| 96 | + }, |
| 97 | + "ExampleTranslationsObjectForSpecificContentList": { |
| 98 | + "ExampleTitle": "Tłumaczenie", |
| 99 | + "ExampleDescription": "Tłumaczenie" |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | +The name of given object and key of translation stay in the same langauge, in this case english. |
| 104 | +Only the translations should always refer to given language. |
| 105 | + |
| 106 | +## Use case for i18n in server-side rendering |
| 107 | + |
| 108 | +```ts |
| 109 | +--- |
| 110 | +import { getLangFromUrl, useTranslations } from "../i18n/utils"; |
| 111 | + |
| 112 | +const lang = getLangFromUrl(Astro.url); |
| 113 | +const t = useTranslations(lang); |
| 114 | +--- |
| 115 | + |
| 116 | +<div> |
| 117 | + <p>{t("Object.key")}</p> |
| 118 | +</div> |
| 119 | +``` |
| 120 | + |
| 121 | +## Use case for i18n in client-side rendering |
| 122 | + |
| 123 | +```html |
| 124 | +--- |
| 125 | +--- |
| 126 | + |
| 127 | +<div> |
| 128 | + <p id="paragraph"></p> |
| 129 | +</div> |
| 130 | + |
| 131 | +<script> |
| 132 | + import { getLangFromUrl, useTranslations } from "../i18n/utils"; |
| 133 | +
|
| 134 | + const lang = getLangFromUrl(new URL(window.location.href)); |
| 135 | + const t = useTranslations(lang); |
| 136 | +
|
| 137 | + const paragraph = document.querySelector("#paragraph"); |
| 138 | + paragraph.innerText = t("Object.key"); |
| 139 | +</script> |
| 140 | +``` |
| 141 | + |
| 142 | +The use case for server-side and client-side differs. |
| 143 | +Variable `lang` that is assigned to `getLandFromUrl` gets different prop. |
| 144 | + |
| 145 | +Argument `Astro.url` only works on server-side. |
| 146 | +So in client-side you need to use `new URL(window.location.href)` to get language from url. |
| 147 | + |
| 148 | +# All of the project used dependencies |
30 | 149 |
|
31 | | -## 🧞 Commands |
| 150 | +### Icons |
| 151 | +Icons are used thru `<Icon />` tag. |
| 152 | +Icons libraries used in project are: |
32 | 153 |
|
33 | | -All commands are run from the root of the project, from a terminal: |
| 154 | +`uil` ( Unicons ), |
| 155 | +`tabler` ( Tabler Icons ), |
34 | 156 |
|
35 | | -| Command | Action | |
36 | | -| :------------------------ | :----------------------------------------------- | |
37 | | -| `npm install` | Installs dependencies | |
38 | | -| `npm run dev` | Starts local dev server at `localhost:4321` | |
39 | | -| `npm run build` | Build your production site to `./dist/` | |
40 | | -| `npm run preview` | Preview your build locally, before deploying | |
41 | | -| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | |
42 | | -| `npm run astro -- --help` | Get help using the Astro CLI | |
| 157 | +### Carousel library |
43 | 158 |
|
44 | | -## 👀 Want to learn more? |
| 159 | +Carousel component is based on `embla-carousel`. |
| 160 | +Component is using plugin `Autoscroll` defined by `embla-carousel`. |
45 | 161 |
|
46 | | -Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). |
|
0 commit comments