### Start Svelte Development Server Source: https://github.com/antepodeum/linguini/blob/main/site/README.md Starts the development server for your Svelte project. Dependencies should be installed first. ```sh npm run dev ``` -------------------------------- ### Start Svelte Development Server and Open in Browser Source: https://github.com/antepodeum/linguini/blob/main/site/README.md Starts the development server and automatically opens the application in a new browser tab. ```sh npm run dev -- --open ``` -------------------------------- ### Install Linguini CLI Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Install the Linguini command-line interface using Cargo. Ensure you have Rust and Cargo installed. ```bash cargo install linguini-cli --version 0.1.0-alpha.3 ``` -------------------------------- ### Set up and Check Website Dependencies Source: https://github.com/antepodeum/linguini/blob/main/CONTRIBUTING.md Navigate to the site directory, install dependencies using pnpm, and run checks to ensure the website is configured correctly. ```sh cd site pnpm install pnpm check ``` -------------------------------- ### Install Linguini VS Code Extension Locally Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Set up the Linguini VS Code extension for local development. This involves navigating to the extension directory, installing dependencies, compiling, and running the development version. ```bash cd editors/vscode npm install npm run compile npm run open:dev ``` -------------------------------- ### Install Linguini Vite Plugin Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Install the Linguini Vite plugin using npm. This plugin is necessary for generating web and SvelteKit runtime helpers. ```sh npm install @antepod/linguini-vite ``` -------------------------------- ### Recreate Project with Specific Template and Configuration Source: https://github.com/antepodeum/linguini/blob/main/site/README.md Recreate an existing project with a specific template, TypeScript types, and without automatic installation. Useful for ensuring consistent project setup. ```sh npx sv@0.15.3 create --template minimal --types ts --no-install site ``` -------------------------------- ### Initialize Linguini Web Runtime for Non-SvelteKit Frameworks Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Create a web internationalization instance using the generated web runtime. This setup configures the localization strategy for use in various web frameworks. ```typescript import { createWebI18n } from "./generated/linguini/web"; import * as runtime from "./generated/linguini"; const i18n = createWebI18n(runtime, { strategy: ["url", "cookie", "header", "baseLocale"], }); ``` -------------------------------- ### Implement Locale for English Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Provide translations for your schema messages in a `.lgl` locale file. This example shows the English implementation for the defined schema. ```lgl // linguini/locale/main/en.lgl hello = Hello, {name}! checkout_total = Total {amount} on {created} field_required = {field} is required. ``` -------------------------------- ### Implement Locale for Russian Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Provide translations for your schema messages in a `.lgl` locale file. This example shows the Russian implementation for the defined schema. ```lgl // linguini/locale/main/ru.lgl hello = Привет, {name}! checkout_total = Итого {amount} на {created} field_required = Поле «{field}» обязательно для заполнения. ``` -------------------------------- ### Layout Component Setup with Locale Context Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md Sets up the root layout component to create and provide the Linguini instance using Svelte's context API. It derives the active locale from route data. ```svelte {@render children()} ``` -------------------------------- ### Configure Vite with Linguini Plugin Source: https://github.com/antepodeum/linguini/blob/main/plugins/vite/README.md Integrate the Linguini Vite plugin into your Vite configuration file. This snippet shows the basic setup required to enable Linguini's build and HMR capabilities within your Vite project. ```js import { defineConfig } from "vite"; import linguini from "@antepod/linguini-vite"; export default defineConfig({ plugins: [linguini()] }); ``` -------------------------------- ### Define Schema in Linguini Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Write your application's translatable messages and their types in a `.lgs` schema file. This example defines types for Money and ShortDate, and messages for greeting, checkout total, and field requirement. ```lgs // linguini/schema/main.lgs type Money = Decimal @currency(code = "USD") type ShortDate = Date @date(style = "short") /// Greeting shown on the home page. hello(name: String) /// Checkout total with schema-owned formatting. checkout_total(amount: Money, created: ShortDate) /// Error shown when a field is empty. field_required(field: String) ``` -------------------------------- ### ICU MessageFormat Example for Russian Source: https://github.com/antepodeum/linguini/blob/main/docs/why.md Demonstrates the complexity of ICU MessageFormat for handling grammatical agreement in Russian, requiring extensive manual combination of gender, plural, and size. ```icu {size, select, small {{count, plural, one {{gender, select, male {маленький} female {маленькая} neuter {маленькое} other {маленький}}} few {{gender, select, male {маленьких} female {маленьких} neuter {маленьких} other {маленьких}}} many {{gender, select, male {маленьких} female {маленьких} neuter {маленьких} other {маленьких}}} other {{gender, select, male {маленьких} female {маленьких} neuter {маленьких} other {маленьких}}} }} big {{ ... }} } ``` -------------------------------- ### Override Locale Formatting Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Customize how parameters are formatted within a locale file. This example overrides the default formatting for `amount` to `number` and `created` to `long` date style. ```lgl checkout_total = Total {amount @number} on {created @date(style = "long")} ``` -------------------------------- ### Scaffold a New Linguini Project Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Initialize a new Linguini project with the default directory structure and configuration files. ```bash linguini init ``` -------------------------------- ### Create a New Svelte Project Source: https://github.com/antepodeum/linguini/blob/main/site/README.md Use this command to initialize a new Svelte project with default settings. ```sh npx sv create my-app ``` -------------------------------- ### Integrate Server Hooks in SvelteKit Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Import and use the generated server hooks from `$lib/generated/linguini/sveltekit` in your `src/hooks.server.ts` file. ```ts // src/hooks.server.ts export { handle } from "$lib/generated/linguini/sveltekit"; ``` -------------------------------- ### Linguini CLI Commands Overview Source: https://github.com/antepodeum/linguini/blob/main/README.md A list of common Linguini CLI commands for project initialization, diagnostics, code generation, formatting, and language server operations. ```bash linguini init Create a project skeleton linguini check Report diagnostics across schema and locale files linguini fix Apply quick fixes — missing files, message stubs linguini build Build and write codegen outputs linguini generate Render sample output for all locales and enum variants linguini format Format .lgs and .lgl files linguini lsp Start the language server over stdio ``` -------------------------------- ### Integrate Layout Load Function in SvelteKit Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Import and use the generated layout load function from `$lib/generated/linguini/sveltekit` in your `src/routes/+layout.server.ts` file. ```ts // src/routes/+layout.server.ts export { load } from "$lib/generated/linguini/sveltekit"; ``` -------------------------------- ### Build Linguini Project Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Generate code for your application based on the schema and locale configurations. The output paths are specified in `linguini.toml`. ```bash linguini build ``` -------------------------------- ### Web Configuration for Locale Routing and Persistence Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Configure web-specific settings in `linguini.toml` for locale routing and persistence strategies. This section is added only when non-default behavior is needed. ```toml [web] # Locale sources are checked left-to-right. The first supported locale wins. strategy = ["url", "cookie", "localStorage", "header", "baseLocale"] # URL routing and localized URL generation. base_path = "" prefix_default_locale = false trailing_slash = "ignore" # "ignore", "always", "never", or "directory" redirect = true origin = "https://example.com" exclude = ["/api/**", "/_app/**", "/favicon.ico"] # SvelteKit auto-localizes internal links by default. # Use data-linguini-ignore on a single link or localize_links = false globally # to keep hrefs unchanged. localize_links = true # Cookie persistence. cookie_name = "LINGUINI_LOCALE" cookie_path = "/" cookie_max_age = 31536000 cookie_same_site = "lax" # "lax", "strict", or "none" cookie_secure = false cookie_http_only = false # cookie_domain = "example.com" # Browser storage persistence. local_storage_key = "LINGUINI_LOCALE" # Existing-app escape hatch for strategy = ["globalVariable", ...]. # global_variable_name = "__LINGUINI_LOCALE__" ``` -------------------------------- ### Integrate Reroute Hooks in SvelteKit Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Import and use the generated reroute hooks from `$lib/generated/linguini/sveltekit` in your `src/hooks.ts` file. ```ts // src/hooks.ts export { reroute } from "$lib/generated/linguini/sveltekit"; ``` -------------------------------- ### Linguini Implementation of a Word with Grammar Source: https://github.com/antepodeum/linguini/blob/main/docs/why.md Shows how Linguini ties a word's grammatical properties and inflected forms together within an 'impl' block, making grammar a typed field and inflection a method call. ```lgl impl Item { pasta { Gender = feminine form acc(Plural) { one => пасту few => пасты _ => паст } } } ``` -------------------------------- ### Implement Locale with Linguini Source: https://github.com/antepodeum/linguini/blob/main/README.md Implement the defined schema contract with real language logic using Linguini's locale implementation files (.lgl). This involves defining enums, forms for pluralization and gender, and the actual string implementations for functions. ```lgl // linguini/locale/checkout/ru.lgl enum Gender { masculine, feminine, neuter, other } impl Item { pasta { Gender = feminine form acc(Plural) { one => пасту few => пасты _ => паст } } sauce { Gender = masculine form acc(Plural) { one => соус few => соуса _ => соусов } } } form Rubles(Plural) { one => рубль few => рубля _ => рублей } form Pronoun(Plural, Gender) { one { masculine => Его feminine => Её _ => Их } _ => Их } you_ordered = {customer}, вы заказали: {amount} {item.acc(amount)} на сумму {total} {Rubles(total)}. {Pronoun(amount, item.Gender)} доставка будет {delivery}. cart_summary = В корзине {amount} {item.acc(amount)} на сумму {total} {Rubles(total)} ``` -------------------------------- ### Project Configuration with TOML Source: https://github.com/antepodeum/linguini/blob/main/README.md Configure your Linguini project using a TOML file. This includes defining project name, default and available locales, and paths for schema and locale files. It also specifies build targets, such as TypeScript output directory, module format, and declaration generation. ```toml [project] name = "shop" default_locale = "en" locales = ["en", "ru"] [paths] schema = "linguini/schema" locale = "linguini/locale" [targets.ts] out = "src/generated/linguini" module = "esm" declaration = true ``` -------------------------------- ### Build Svelte Project for Production Source: https://github.com/antepodeum/linguini/blob/main/site/README.md Generates a production-ready build of your Svelte application. ```sh npm run build ``` -------------------------------- ### Run Workspace Tests Source: https://github.com/antepodeum/linguini/blob/main/README.md Execute all tests within the Linguini project workspace using Cargo. ```bash cargo test --workspace ``` -------------------------------- ### Linguini Project and TS Target Configuration Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Configure Linguini project settings and the TypeScript target in `linguini.toml`. Specify the framework as 'sveltekit' for SvelteKit integration. ```toml [project] name = "app" default_locale = "en" locales = ["en", "ru", "ar"] [paths] schema = "schema" locale = "locales" [targets.ts] out = "src/lib/generated/linguini" module = "esm" declaration = true framework = "sveltekit" ``` -------------------------------- ### Configure Linguini Project Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Edit the `linguini.toml` file to define project name, default locale, supported locales, and file paths for schema and locale files. Configure build targets, such as TypeScript output. ```toml [project] name = "my-app" default_locale = "en" locales = ["en", "ru"] [paths] schema = "linguini/schema" locale = "linguini/locale" [targets.ts] out = "src/generated/linguini" module = "esm" declaration = true ``` -------------------------------- ### Run Code Formatting and Linting Checks Source: https://github.com/antepodeum/linguini/blob/main/CONTRIBUTING.md Execute all formatting and linting checks for the entire workspace. Ensure code adheres to project standards before committing. ```sh cargo fmt --all --check ``` ```sh cargo clippy --workspace --all-targets -- -D warnings ``` -------------------------------- ### API Route Using Resolved Language Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md Demonstrates an API route that uses the resolved language from `locals` to create a Linguini instance and return localized content. ```typescript // src/routes/api/preview/+server.ts import { json } from "@sveltejs/kit"; import { createLinguini } from "$lib/generated/linguini"; import type { RequestHandler } from "./$types"; export const GET: RequestHandler = ({ locals }) => { const lgl = createLinguini(locals.language); return json({ title: lgl.delivery("apple", "small", 1) }); }; ``` -------------------------------- ### Component Accessing Locale Source: https://github.com/antepodeum/linguini/blob/main/docs/examples/sveltekit-locale-provider.md Demonstrates how components can access the Linguini instance from Svelte's context to display localized content. This follows the short call shape for easy integration. ```svelte

{lgl.delivery(fruit, size, 1)}

``` -------------------------------- ### Apply Quick Fixes in Linguini Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Automatically generate stub implementations for messages that are defined in the schema but missing from locale files. This is useful when adding new messages. ```bash linguini fix ``` -------------------------------- ### Locale Switching and Displaying Localized Text in Svelte Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Demonstrates how to implement a locale switcher using the 'setLocale' function and display localized text. It iterates over available locales and provides buttons to change the current language. ```svelte

{l.home.subtitle()}

``` -------------------------------- ### Use Generated HTML Placeholders in SvelteKit App Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Incorporate the generated HTML placeholders for language and direction in your `src/app.html` file. ```html
%sveltekit.body%
``` -------------------------------- ### Nested `form` with Multiple Parameters Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md Demonstrates deeper nesting and multiple parameters in `form`. Parameters should be ordered from the enum with the fewest variants to the most. ```lgl form SizeAdj(Size, Plural, Gender) { small { one { masculine => маленький feminine => маленькая neuter => маленькое _ => маленький } _ => маленьких } big { one { masculine => большой feminine => большая neuter => большое _ => большой } _ => больших } } ``` -------------------------------- ### Run Workspace Tests Source: https://github.com/antepodeum/linguini/blob/main/CONTRIBUTING.md Execute all tests across the entire workspace to ensure code integrity and functionality. ```sh cargo test --workspace ``` -------------------------------- ### Importing Other Linguini Svelte Client Helpers Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Import various client-side localization helper functions generated by Linguini for use in your Svelte application. ```typescript import { alternateLinks, delocalizeUrl, linguini, localizeHref, localizeHrefAttribute, localizeMarkupLinks, localizeUrl, shouldLocalizeHref, } from "$lib/generated/linguini/svelte"; ``` -------------------------------- ### Configure Vite for Linguini Plugin Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Add the Linguini Vite plugin to your `vite.config.ts` file. This ensures generated files update during development. ```ts // vite.config.ts import { sveltekit } from "@sveltejs/kit/vite"; import { defineConfig } from "vite"; import linguini from "@antepod/linguini-vite"; export default defineConfig({ plugins: [sveltekit(), linguini()], }); ``` -------------------------------- ### Check for Linguini Errors Source: https://github.com/antepodeum/linguini/blob/main/docs/getting-started.md Run the Linguini analyzer to detect issues like missing implementations, unresolved references, or type errors in your schema and locale files. This command is suitable for CI. ```bash linguini check ``` -------------------------------- ### Forms with String Interpolation using `fn` Source: https://github.com/antepodeum/linguini/blob/main/docs/reference.md Use `fn` when output needs to embed dynamic string values. It accepts named `String` parameters and interpolates them into the output. ```lgl fn delivery_note(item: String, Plural, Gender) { one { feminine => Доставлена {item} _ => Доставлен {item} } _ => Доставлены {item} } ``` -------------------------------- ### Generate and Use Native API with TypeScript Source: https://github.com/antepodeum/linguini/blob/main/README.md Utilize the generated native API from Linguini in your application code. This API provides type-safe access to your localized strings, handling complex grammar rules like pluralization and gender agreement automatically. ```ts import { configureLinguini } from "./generated/linguini"; const l = configureLinguini({ language: () => getRequestLocale() }); l.checkout.you_ordered("Artemy", "pasta", 3, 1290, "2026-05-17"); // → "Artemy, вы заказали: 3 пасты на сумму 1290 рублей. Их доставка будет 17.05.2026." l.checkout.cart_summary(3, "pasta", 1290); // → "В корзине 3 пасты на сумму 1290 рублей" ``` -------------------------------- ### Import and Use Linguini in Svelte Components Source: https://github.com/antepodeum/linguini/blob/main/docs/web-sveltekit.md Import the 'l' helper from the generated Svelte module to access localized strings within your Svelte components. This is the standard way to display translated text. ```svelte

{l.home.title()}

``` -------------------------------- ### 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.