```
--------------------------------
### Resolve Request and Localize URL with Linguini Web Runtime
Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md
Resolve the current request to determine the locale and generate localized URLs using the initialized web i18n instance. This is useful for setting up HTML attributes and link generation.
```typescript
const context = await i18n.resolveRequest(request);
const htmlAttrs = context.htmlAttrs;
const pricingHref = context.localizeHref("/pricing", "ru");
```
--------------------------------
### Augment SvelteKit App Locals and PageData
Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md
The generated `sveltekit.d.ts` augments SvelteKit's `App.Locals` and `App.PageData`. Ensure your `src/app.d.ts` correctly includes these declarations.
```ts
// src/app.d.ts
declare global {
namespace App {
interface Error {
message: string;
}
}
}
export {};
```
--------------------------------
### Localize Internal Links in SvelteKit
Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md
Use the 'l' helper to automatically generate localized internal links. SvelteKit's routing will handle the locale prefixing during SSR.
```svelte
{l.nav.pricing()}{l.nav.settings()}
```
--------------------------------
### Quick Fix for Unknown Type
Source: https://github.com/antepodeum/linguini/blob/main/tests/fixtures/golden/snapshots/diagnostic-schema-syntax.txt
When encountering an 'unknown type' error, Linguini often suggests a quick fix, such as declaring the type as an enum. Apply these suggestions to resolve the issue.
```linguini
Help: quick fix: declare enum Color
```
--------------------------------
### Group Messages with Namespaces in Linguini Schema
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Namespaces group related messages under a shared prefix, helping to organize larger schemas and prevent naming conflicts. Source-level import/export syntax is not currently supported.
```lgs
auth {
sign_in(email: String)
sign_out
error_invalid_credentials
}
```
--------------------------------
### Simple Messages in Linguini Locale
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Locale files implement messages declared in the schema. Simple messages are defined as key-value pairs, where the value is the translated string.
```lgl
greeting = Hello, {name}!
sign_out = Sign out
```
--------------------------------
### Define Schema with Linguini
Source: https://github.com/antepodeum/linguini/blob/main/README.md
Define the public contract for your application's localization using Linguini's schema definition language (.lgs). This includes enums, functions with typed arguments, and their return types.
```lgs
// linguini/schema/checkout.lgs
enum Item { pasta, sauce }
/// Shown on the delivery confirmation card.
you_ordered(
customer: String,
item: Item,
amount: Number,
total: Number,
delivery: Date,
)
cart_summary(amount: Number, item: Item, total: Number)
```
--------------------------------
### Parameterless Messages in Linguini Schema
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
A bare identifier within a namespace block defines a message with no parameters. This is useful for simple string constants or configuration values.
```lgs
email_input {
label
placeholder
aria
}
```
--------------------------------
### Route Data for Resolved Language
Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md
Loads the resolved language from SvelteKit's locals into the route data. This makes the language available to the page's components.
```typescript
// src/routes/+layout.server.ts
import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = ({ locals }) => {
return { language: locals.language };
};
```
--------------------------------
### Use Linguini in TypeScript App
Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md
Integrate Linguini-generated code into your TypeScript application. Configure Linguini with the current language and use the generated functions to access localized strings.
```typescript
import { configureLinguini } from "./generated/linguini";
const l = configureLinguini({ language: () => getRequestLocale() });
l.main.hello("Artemy"); // → "Hello, Artemy!"
l.main.field_required("Email"); // → "Email is required."
```
--------------------------------
### Define Messages in Linguini Schema
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Messages are named entries that the app can call, with typed parameters. Doc comments attached to a message declaration appear in codegen output and LSP hover.
```lgs
delivery(fruit: Fruit, size: Size, count: Number)
```
```lgs
greeting(name: String)
```
```lgs
/// Shown on the delivery confirmation card.
delivery(fruit: Fruit, size: Size, count: Number)
```
--------------------------------
### Interpolation in Linguini Locale
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Parameters from the schema message can be referenced by name within curly braces `{}` in the locale file for string interpolation.
```lgl
greeting = Hello, {name}!
price = Total: {amount} {currency}
```
--------------------------------
### Accessing Localized Data in SvelteKit Server Load Function
Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md
Access the request-scoped localization context stored in 'event.locals' within a SvelteKit server load function to provide localized data to the page.
```typescript
export function load({ locals }) {
return {
title: locals.l.home.title(),
locale: locals.locale,
canonical: locals.linguini.localizeHref("/pricing"),
};
}
```
--------------------------------
### Define Type Aliases and Formatters in Linguini Schema
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Type aliases attach formatters to primitive types, making formatting part of the schema contract. Locale files can then interpolate values directly, and generated code applies the schema formatter automatically. Built-in primitives include String, Number, Decimal, Date, and Boolean.
```lgs
type Money = Decimal @currency(code = "EUR")
type ShortDate = Date @date(style = "short")
checkout_total(amount: Money, created: ShortDate)
```
```lgl
checkout_total = Total {amount} on {created}
```
```lgl
checkout_total = Total {amount @number} on {created @date(style = "long")}
```
```lgs
summary(count: Number, total: Decimal, created: Date)
```
```lgl
summary = {count} items, {total}, {created}
```
--------------------------------
### Implement Enum Variants with Grammar in Linguini Locale
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
The `impl` block declares the linguistic implementation of an enum variant. It can contain typed fields, `form` declarations for grammatical forms (like pluralization), and static string blocks. Access typed fields and forms using dot notation and form calls.
```lgl
enum Gender { masculine, feminine, neuter, other }
impl Fruit {
apple {
Gender = neuter
emoji = 🍎
form nom(Plural) {
one => яблоко
few => яблока
_ => яблок
}
form gen(Plural) {
one => яблока
_ => яблок
}
display {
short = ябл.
long = спелое яблоко
}
}
pear {
Gender = feminine
form nom(Plural) {
one => груша
few => груши
_ => груш
}
}
}
```
```lgl
Gender = neuter // typed: Gender enum
emoji = 🍎 // plain string field
```
```lgl
fruit.Gender // typed field access
fruit.nom(count) // form call — count auto-converts to Plural
```
--------------------------------
### SSR Hook for Language Resolution
Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md
Implements SvelteKit's `handle` hook to resolve the user's language from cookies or request headers. Defaults to 'en' if no language is detected.
```typescript
// src/hooks.server.ts
import type { Handle } from "@sveltejs/kit";
const supportedLanguages = ["en", "ru"] as const;
type Language = (typeof supportedLanguages)[number];
function isLanguage(value: string | undefined): value is Language {
return supportedLanguages.includes(value as Language);
}
function languageFromAcceptLanguage(
header: string | null,
): Language | undefined {
return header
?.split(",")
.map((part) => part.trim().split(";")[0])
.find(isLanguage);
}
export const handle: Handle = async ({ event, resolve }) => {
const cookieLanguage = event.cookies.get("locale");
const headerLanguage =
event.request.headers.get("x-linguini-locale") ??
event.request.headers.get("x-locale") ??
languageFromAcceptLanguage(event.request.headers.get("accept-language"));
event.locals.language = isLanguage(cookieLanguage)
? cookieLanguage
: (headerLanguage ?? "en");
return resolve(event);
};
```
--------------------------------
### Declare Schema Types Before Use
Source: https://github.com/antepodeum/linguini/blob/main/tests/fixtures/golden/snapshots/diagnostic-schema-syntax.txt
Ensure all schema types, such as enums or structs, are declared before they are referenced in your Linguini code. This prevents 'unknown type' errors.
```linguini
paint(color: Color)
```
--------------------------------
### Wildcard Usage in `form`
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
The wildcard `_` matches all remaining variants of the current parameter and must be the last arm in a match expression.
```lgl
form F(Gender) {
feminine => она
_ => он
}
```
--------------------------------
### Inline `fn` for Interpolation
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
An `fn` can be written inline as an interpolation value within a string.
```lgl
greeting = Привет, {fn(Gender) { masculine => дорогой, feminine => дорогая, _ => дорогой }} {name}!
```
--------------------------------
### Generated Index TS
Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md
Exposes direct locale facades from generated Linguini code. Use this for direct access to locale functions.
```typescript
import {
createLinguini,
createLinguiniProvider,
lgl,
} from "$lib/generated/linguini";
lgl.delivery("apple", "small", 1);
createLinguini("ru").delivery("apple", "small", 1);
createLinguiniProvider({ resolveLanguage: () => "ru" }).delivery(
"apple",
"small",
1,
);
```
--------------------------------
### App Declaration for SSR Hooks
Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md
Defines the App.Locals interface to include the resolved language for SSR hooks. This ensures type safety for language resolution.
```typescript
// src/app.d.ts
declare global {
namespace App {
interface Locals {
language: "en" | "ru";
}
}
}
export {};
```
--------------------------------
### Grammatical Agreement with `form`
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Use `form` to match enum variants and return a grammatically correct string. Parameters are types only. The wildcard `_` matches all remaining variants at the current level.
```lgl
form Delivered(Plural, Gender) {
one {
masculine => Доставлен
feminine => Доставлена
neuter => Доставлено
_ => Доставлено
}
_ => Доставлены
}
```
--------------------------------
### Svelte Context for Locale State
Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md
Manages locale state within Svelte's context API for SSR. This ensures that the locale is accessible throughout the component tree without relying on server module singletons.
```typescript
// src/lib/i18n.ts
import { getContext, setContext } from "svelte";
import type { Linguini } from "$lib/generated/linguini";
const key = Symbol("linguini");
export function setLgl(lgl: Linguini) {
setContext(key, lgl);
}
export function getLgl(): Linguini {
return getContext(key);
}
```
--------------------------------
### Declare Enums in Linguini Schema
Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md
Enums declare a set of named variants. Names are PascalCase and variants are lowercase. Use this to define a fixed set of options for a message parameter.
```lgs
enum Fruit { apple, pear, orange }
enum Size { small, big }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.