Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .changeset/incremental-lix-sync.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
"@inlang/sdk": major
"@inlang/paraglide-js": minor
"@inlang/cli": minor
---

Expand Down
15 changes: 0 additions & 15 deletions .changeset/localized-string-branded-type.md

This file was deleted.

22 changes: 0 additions & 22 deletions .changeset/optional-chain-translations.md

This file was deleted.

35 changes: 35 additions & 0 deletions inlang/packages/paraglide/paraglide-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# @inlang/paraglide-js

## 2.6.0

### Minor Changes

- 3d6259c: Add `LocalizedString` branded type for compile-time i18n safety.

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.

```typescript
import { m } from "./paraglide/messages.js";
import type { LocalizedString } from "@inlang/paraglide-js";

const greeting: LocalizedString = m.hello(); // ✓ Type-safe
const raw: LocalizedString = "Hello"; // ✗ Type error
```

- 4bde3eb: Add optional chaining to compiled message inputs so missing inputs no longer throw at runtime; include tests covering single- and multi-variant messages.

Closes https://github.com/opral/inlang-paraglide-js/issues/568

Example:

```js
// compiled translation
export const greeting = (i) => `Hello ${i?.name}`;

// TypeScript still enforces the input shape; this is purely runtime safety (handy in dev).
greeting(); // no throw, returns "Hello undefined"
greeting({ name: "Ada" }); // "Hello Ada"

// previously (boom 💥)
export const greetingOld = (i) => `Hello ${i.name}`;
greetingOld(); // TypeError: Cannot read properties of undefined (reading 'name')
```

## 2.5.0

- 72d1c53: Ensure the CLI honours allowJs flags defined in extended or referenced tsconfig files instead of prompting unnecessarily.
Expand Down
2 changes: 1 addition & 1 deletion inlang/packages/paraglide/paraglide-js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@inlang/paraglide-js",
"type": "module",
"version": "2.5.0",
"version": "2.6.0",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ ${isSafeBundleId ? "export " : ""}const ${safeBundleId} = (inputs${hasInputs ? "
(locale, index) =>
`${index > 0 ? " " : ""}${!isFullyTranslated || index < args.availableLocales.length - 1 ? `if (locale === "${locale}") ` : ""}return ${args.messageReferenceExpression(locale, args.bundle.id)}(inputs)`
)
.join("\n")}${!isFullyTranslated ? `\n return /** @type {LocalizedString} */ ("${args.bundle.id}")` : ""}
.join(
"\n"
)}${!isFullyTranslated ? `\n return /** @type {LocalizedString} */ ("${args.bundle.id}")` : ""}
};`;

if (isSafeBundleId === false) {
Expand Down