Skip to content

Commit 323a9ea

Browse files
Merge pull request #3783 from opral/release-paraglide
paraglide js version 2.6.0
2 parents 823c6b8 + 683e5c7 commit 323a9ea

File tree

6 files changed

+39
-40
lines changed

6 files changed

+39
-40
lines changed

.changeset/incremental-lix-sync.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
"@inlang/sdk": major
3-
"@inlang/paraglide-js": minor
43
"@inlang/cli": minor
54
---
65

.changeset/localized-string-branded-type.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

.changeset/optional-chain-translations.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

inlang/packages/paraglide/paraglide-js/CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# @inlang/paraglide-js
22

3+
## 2.6.0
4+
5+
### Minor Changes
6+
7+
- 3d6259c: Add `LocalizedString` branded type for compile-time i18n safety.
8+
9+
Message functions now return `LocalizedString` instead of `string`, enabling TypeScript users to distinguish between translated and untranslated strings at compile time. This is fully backward compatible since branded types are assignable to their base type.
10+
11+
```typescript
12+
import { m } from "./paraglide/messages.js";
13+
import type { LocalizedString } from "@inlang/paraglide-js";
14+
15+
const greeting: LocalizedString = m.hello(); // ✓ Type-safe
16+
const raw: LocalizedString = "Hello"; // ✗ Type error
17+
```
18+
19+
- 4bde3eb: Add optional chaining to compiled message inputs so missing inputs no longer throw at runtime; include tests covering single- and multi-variant messages.
20+
21+
Closes https://github.com/opral/inlang-paraglide-js/issues/568
22+
23+
Example:
24+
25+
```js
26+
// compiled translation
27+
export const greeting = (i) => `Hello ${i?.name}`;
28+
29+
// TypeScript still enforces the input shape; this is purely runtime safety (handy in dev).
30+
greeting(); // no throw, returns "Hello undefined"
31+
greeting({ name: "Ada" }); // "Hello Ada"
32+
33+
// previously (boom 💥)
34+
export const greetingOld = (i) => `Hello ${i.name}`;
35+
greetingOld(); // TypeError: Cannot read properties of undefined (reading 'name')
36+
```
37+
338
## 2.5.0
439
540
- 72d1c53: Ensure the CLI honours allowJs flags defined in extended or referenced tsconfig files instead of prompting unnecessarily.

inlang/packages/paraglide/paraglide-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@inlang/paraglide-js",
33
"type": "module",
4-
"version": "2.5.0",
4+
"version": "2.6.0",
55
"license": "MIT",
66
"publishConfig": {
77
"access": "public",

inlang/packages/paraglide/paraglide-js/src/compiler/compile-bundle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ ${isSafeBundleId ? "export " : ""}const ${safeBundleId} = (inputs${hasInputs ? "
107107
(locale, index) =>
108108
`${index > 0 ? " " : ""}${!isFullyTranslated || index < args.availableLocales.length - 1 ? `if (locale === "${locale}") ` : ""}return ${args.messageReferenceExpression(locale, args.bundle.id)}(inputs)`
109109
)
110-
.join("\n")}${!isFullyTranslated ? `\n return /** @type {LocalizedString} */ ("${args.bundle.id}")` : ""}
110+
.join(
111+
"\n"
112+
)}${!isFullyTranslated ? `\n return /** @type {LocalizedString} */ ("${args.bundle.id}")` : ""}
111113
};`;
112114

113115
if (isSafeBundleId === false) {

0 commit comments

Comments
 (0)