|
1 | 1 | # @inlang/paraglide-js |
2 | 2 |
|
| 3 | +## 2.1.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- 4255bd5: Provide functions for getting the preferred language on server and client. |
| 8 | + |
| 9 | + This defines two new functions for getting the preferred language: |
| 10 | + |
| 11 | + - `extractLocaleFromHeader`: Extracts the locale from the accept-language header on the server. |
| 12 | + - `extractLocaleFromNavigator`: Extracts the locale from the navigator.languages array on the client. |
| 13 | + |
| 14 | + The code was already present in the `@inlang/paraglide-js` package, but it was not exported. Now it is exported so that |
| 15 | + it can be used in custom strategies. |
| 16 | + |
| 17 | +- dc287f1: Implement custom strategy concept for locale resolution. |
| 18 | + |
| 19 | + This introduces a new way to define custom locale resolution strategies alongside built-in strategies. Custom strategies provide a cleaner, more composable approach compared to overwriting `getLocale()` and `setLocale()` functions directly. |
| 20 | + |
| 21 | + **New APIs:** |
| 22 | + |
| 23 | + - `defineCustomClientStrategy()`: Define custom strategies for client-side locale resolution |
| 24 | + - `defineCustomServerStrategy()`: Define custom strategies for server-side locale resolution |
| 25 | + |
| 26 | + **Key features:** |
| 27 | + |
| 28 | + - Custom strategies must follow the pattern `custom-<name>` where `<name>` contains only alphanumeric characters |
| 29 | + - Can be combined with built-in strategies in the strategy array |
| 30 | + - Respect strategy order for fallback handling |
| 31 | + - Support both client and server environments |
| 32 | + - Provide better error isolation and type safety |
| 33 | + |
| 34 | + **Usage example:** |
| 35 | + |
| 36 | + ```js |
| 37 | + import { defineCustomClientStrategy } from "./paraglide/runtime.js"; |
| 38 | + |
| 39 | + defineCustomClientStrategy("custom-sessionStorage", { |
| 40 | + getLocale: () => sessionStorage.getItem("user-locale") ?? undefined, |
| 41 | + setLocale: (locale) => sessionStorage.setItem("user-locale", locale), |
| 42 | + }); |
| 43 | + ``` |
| 44 | +
|
| 45 | + Then include in your strategy configuration: |
| 46 | +
|
| 47 | + ```js |
| 48 | + compile({ |
| 49 | + strategy: ["custom-sessionStorage", "cookie", "baseLocale"], |
| 50 | + }); |
| 51 | + ``` |
| 52 | +
|
| 53 | +### Patch Changes |
| 54 | +
|
| 55 | +- 4c0b997: perf(paraglide): improve bundle size by removing message id fallback for fully translated messages |
| 56 | +- 9621803: Add Vary: Accept-Language header when preferredLanguage strategy is used |
| 57 | +
|
| 58 | + Paraglide middleware now automatically sets the `Vary: Accept-Language` header when performing redirects based on the `preferredLanguage` strategy. This indicates to clients (CDN cache, crawlers, etc.) that the response will be different depending on the `Accept-Language` header, ensuring proper caching behavior and SEO compliance. |
| 59 | +
|
| 60 | + Closes https://github.com/opral/inlang-paraglide-js/issues/522 |
| 61 | +
|
| 62 | +- Updated dependencies [22089a2] |
| 63 | + |
| 64 | +
|
3 | 65 | ## 2.0.13 |
4 | 66 |
|
5 | 67 | ### Patch Changes |
|
0 commit comments