@mcendon/astro-translate 1.0.0-RC1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +42 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,18 @@
1
- # `astro-translate` The i18n integration for Astro 🧑‍🚀
1
+ # 🗣 `astro-translate` The translation integration for Astro 🚀
2
2
 
3
3
  <p align="center">
4
4
  <a href="https://github.com/mcendon/astro-translate#readme" target="_blank">
5
5
  <picture>
6
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mcendon/astro-translate/main/logos/astro-translate-dark.png">
7
- <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/mcendon/astro-translate/main/logos/astro-translate-light.png">
8
- <img alt="@mcendon/astro-translate" src="https://raw.githubusercontent.com/mcendon/astro-translate/HEAD/logos/astro-translate-light.png" width="400" height="225" style="max-width: 100%;">
6
+ <img alt="@mcendon/astro-translate" src="https://raw.githubusercontent.com/mcendon/astro-translate/main/logos/astro-translate.png" width="400" height="400" style="max-width: 100%;">
9
7
  </picture>
10
8
  </a>
11
9
  </p>
12
10
 
13
- <p align="center">
14
- Built with ❤️ for all Astro crewmates 🧑‍🚀
15
- </p>
16
-
17
11
  <p align="center">
18
12
  <a href="https://www.npmjs.com/package/@mcendon/astro-translate"><img src="https://img.shields.io/npm/dt/@mcendon/astro-translate.svg" alt="Total Downloads"></a>
19
13
  <!-- https://github.com/@mcendon/astro-translate/@mcendon/astro-translate/releases -->
20
14
  <a href="https://www.npmjs.com/package/@mcendon/astro-translate?activeTab=versions"><img src="https://img.shields.io/npm/v/@mcendon/astro-translate.svg" alt="Latest Release"></a>
21
- <a href="https://github.com/mcendon/astro-translate/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/@mcendon/astro-translate.svg" alt="License"></a>
15
+ <a href="https://github.com/mcendon/astro-translate/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/@mcendon/astro-translate" alt="License"></a>
22
16
  </p>
23
17
 
24
18
  ---
@@ -32,6 +26,7 @@ Provide an internationalization (i18n) integration for Astro that:
32
26
  - Is adapter agnostic
33
27
  - Is UI framework agnostic
34
28
  - Is compatible with [`@astrojs/sitemap`](https://www.npmjs.com/package/@astrojs/sitemap)
29
+ - Is compatible with [Astro 7.0](https://astro.build/blog/astro-7/) and [Vite 8](https://vite.dev/blog/announcing-vite8)
35
30
 
36
31
  ## Quick start
37
32
 
@@ -40,7 +35,7 @@ Provide an internationalization (i18n) integration for Astro that:
40
35
  Install via [npm](https://www.npmjs.com/package/@mcendon/astro-translate):
41
36
 
42
37
  ```shell
43
- npm install @mcendon/astro-translate
38
+ npm install @mcendon/astro-translate@latest
44
39
  ```
45
40
 
46
41
  ### Configure
@@ -139,6 +134,43 @@ switch (locale) {
139
134
 
140
135
  Several helper functions are included to make handling locales easier.
141
136
 
137
+ ### `getTranslateHelper(locale)`
138
+
139
+ Provides a `t()` translate function for server-rendered pages using JSON translation files. Drop your translation files as `src/i18n/{locale}.json` and the helper will load them eagerly at build time.
140
+
141
+ ```json
142
+ // src/i18n/en.json
143
+ {
144
+ "greeting": "Hello!",
145
+ "nested.welcome": "Welcome {{name}}"
146
+ }
147
+ ```
148
+
149
+ ```astro
150
+ ---
151
+ import { getLocale, getTranslateHelper } from "@mcendon/astro-translate";
152
+ import Layout from "../layouts/Layout.astro";
153
+
154
+ const locale = getLocale(Astro.url);
155
+ const t = getTranslateHelper(locale);
156
+ ---
157
+
158
+ <Layout title={t("greeting")}>
159
+ <!-- Supports interpolation using {{name}} -->
160
+ <h1>{t("nested.welcome", { name: "World" })}</h1>
161
+ </Layout>
162
+
163
+ <!--
164
+ <h1>Welcome World</h1>
165
+ -->
166
+ ```
167
+
168
+ Resolution priority for a given key:
169
+
170
+ 1. The locale's translation file
171
+ 2. The `defaultLocale` translation file (fallback)
172
+ 3. The raw key itself (if neither file contains it)
173
+
142
174
  ### Astro config options
143
175
 
144
176
  Please see the official Astro docs for more details:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcendon/astro-translate",
3
- "version": "1.0.0-RC1",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "description": "The translate integration for Astro",
6
6
  "keywords": [