### Manage Namespaces and Translations (Typst) Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Namespaces allow multiple libraries to use TiefLang without conflicts. Each namespace maintains its own translation dictionary, language stack, and default language. This example demonstrates configuring and using translations from separate namespaces. ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang // Core library translations #let core-translations = ( en-US: (error: [An error occurred], success: [Operation successful]), de-DE: (error: [Ein Fehler ist aufgetreten], success: [Vorgang erfolgreich]), ) // UI library translations #let ui-translations = ( en-US: (button: [Click me], title: [Dashboard]), de-DE: (button: [Klick mich], title: [Übersicht]), ) // Configure separate namespaces #configure-translations(core-translations, namespace: "core", default: "en-US") #configure-translations(ui-translations, namespace: "ui", default: "de-DE") // Access translations from specific namespaces #push-lang("en-US") #tr("error", namespace: "core") // Output: An error occurred #tr("title", namespace: "ui") // Output: Dashboard #push-lang("de-DE") #tr("success", namespace: "core") // Output: Vorgang erfolgreich #tr("button", namespace: "ui") // Output: Klick mich ``` -------------------------------- ### Manage Language Stack Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Demonstrates the use of `push-lang` and `pop-lang` to manage the language stack. `push-lang` adds a language to the top of the stack, and `pop-lang` removes it, allowing for nested language context management. ```typst #push-lang("de-DE") #tr("key1") #pop-lang() ``` -------------------------------- ### Configure Translations Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Initializes the TiefLang translation system by providing the translation dictionary. This step is crucial before using translation functions like `tr` or `trk`. It's sufficient for simple, mono-templates not relying on other TiefLang libraries. ```typst #let translations = ( de-DE: ( key1: [Bahnhofsstraße 1], key2: ( subkey1: [Wohnung 1], subkey2: [Wohnung 2], ), ), de-CH: ( key1: [Bahnhofsstrasse 1], key2: ( subkey1: [Top 1], subkey2: [Top 2], ), ), en-US: ( key1: [Bahnhof Street 1], key2: ( subkey1: [Flat 1], subkey2: [Flat 2], ), ), ) configure-translations(translations) ``` -------------------------------- ### Manage Namespaces for Translations Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Explains how to use namespaces to isolate translations when multiple libraries utilize TiefLang. Each `configure-translations` call can be assigned a unique namespace, and translation lookups can specify the target namespace. ```typst #configure-translations(core, namespace: "core") #configure-translations(ui, namespace: "ui") #tr("title", namespace: "ui") ``` -------------------------------- ### Access Translations with `tr` and `trk` Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Demonstrates basic translation retrieval using `tr` and `trk` functions. Both `tr().key1` and `tr("key1")` access the translation for 'key1' in the current language, while `trk("key1")` provides a direct key lookup. These functions require a context. ```typst // These produce the same output! #tr().key1 #tr("key1") #trk("key1") ``` -------------------------------- ### configure-translations Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Initializes the translation system with a dictionary of translations organized by language code. Supports optional namespace isolation, strict mode for production builds, and custom default language settings. ```APIDOC ## configure-translations ### Description Initializes the translation system with a dictionary of translations organized by language code. Supports optional namespace isolation, strict mode for production builds, and custom default language settings. ### Method Typst Function ### Endpoint N/A (Typst Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **translations** (dictionary) - Required - A dictionary where keys are language codes (e.g., "en-US") and values are translation dictionaries. - **namespace** (string) - Optional - Isolates translations to a specific namespace. - **strict** (boolean) - Optional - If true, throws errors on missing translation keys. - **default** (string) - Optional - Sets the default language if none is explicitly selected. ### Request Example ```typst #import "@preview/tieflang:0.1.0": configure-translations #let translations = ( en-US: ( greeting: [Hello], address: ( street: [Main Street 1], apartment: [Apartment 5], ), welcome: (name) => [Welcome, #name!], ), de-DE: ( greeting: [Hallo], address: ( street: [Hauptstraße 1], apartment: [Wohnung 5], ), welcome: (name) => [Willkommen, #name!], ), ) // Basic configuration #configure-translations(translations) // Configuration with options #configure-translations( translations, namespace: "my-template", strict: true, default: "de-DE", ) ``` ### Response #### Success Response (N/A) This function configures the translation system and does not return a value. #### Response Example N/A ``` -------------------------------- ### Enable Strict Mode for Missing Keys Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Shows how to enable strict mode during translation configuration. In strict mode, missing translation keys will result in hard errors, which is recommended for production environments to catch potential issues early. ```typst #configure-translations(translations, strict: true) ``` -------------------------------- ### Configure Translations with TiefLang Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Initializes the TiefLang translation system with a dictionary of translations organized by language code. Supports optional namespace isolation, strict mode for production builds, and custom default language settings. ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang // Define translations with nested keys and function values #let translations = ( en-US: ( greeting: [Hello], address: ( street: [Main Street 1], apartment: [Apartment 5], ), welcome: (name) => [Welcome, #name!], ), de-DE: ( greeting: [Hallo], address: ( street: [Hauptstraße 1], apartment: [Wohnung 5], ), welcome: (name) => [Willkommen, #name!], ), ) // Basic configuration with default namespace #configure-translations(translations) // Configuration with options #configure-translations( translations, namespace: "my-template", // Isolate from other libraries strict: true, // Throw errors on missing keys default: "de-DE", // Set default language (otherwise en-US) ) ``` -------------------------------- ### Use Function Values in Translations Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Illustrates how translations can be functions that accept arguments. When a translation value is a function, `tr` or `trk` will call it with any additional arguments provided, enabling dynamic content generation. ```typst #let translations = ( en-US: ( welcome: (name) => [Hello #name], ), ) #configure-translations(translations) #trk("welcome", "Lena") // Outputs Hello Lena #(tr().welcome)("Lena") // Also outputs Hello Lena ``` -------------------------------- ### Import TiefLang Library Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Imports necessary functions from the TiefLang library for Typst templates. Essential functions like `configure-translations` and `tr` are always needed, while others like `pop-lang`, `push-lang`, `trk`, and `select-language` are optional depending on the template's requirements. ```typst #import "@preview/tieflang:0.1.0": ( configure-translations, tr, // These you'll always need pop-lang, push-lang, trk, // These are optional select-language, // You should only import this if you plan to expose select-language. See the common pitfalls section. ) ``` -------------------------------- ### Manage Language Stack with push-lang / select-language in TiefLang Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Pushes a language onto the language stack, making it the active language for all subsequent translation lookups. `select-language` is an alias for `push-lang`. This allows for dynamic language switching. ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang, select-language #let translations = ( en-US: (greeting: [Hello]), de-DE: (greeting: [Hallo]), fr-FR: (greeting: [Bonjour]), ) #configure-translations(translations, default: "en-US") // Set active language #push-lang("de-DE") #tr("greeting") // Output: Hallo // Using the alias #select-language("fr-FR") #tr("greeting") // Output: Bonjour // Languages stack - most recent is active #push-lang("en-US") #tr("greeting") // Output: Hello (en-US is on top) ``` -------------------------------- ### Define Available Languages Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Creates a dictionary mapping human-readable language names to their corresponding codes. This provides a user-friendly interface for selecting languages, especially when custom language codes are used beyond the standard 'xx-XX' format. ```typst #let languages = ( de-DE: "de-DE", de-CH: "de-CH", en-US: "en-US", german: "de-DE", german-germany: "de-DE", german-switzerland: "de-CH", english-united-states: "en-US", ) ``` -------------------------------- ### Access Nested Translations Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Shows how to access nested translation keys using dot notation with both `trk` and `tr`. This allows for hierarchical organization of translations within the dictionary structure. ```typst #trk("key2.subkey1") #tr().key2.subkey1 ``` -------------------------------- ### push-lang / select-language Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Pushes a language onto the language stack, making it the active language for all subsequent translation lookups. `select-language` is an alias for `push-lang`. ```APIDOC ## push-lang / select-language ### Description Pushes a language onto the language stack, making it the active language for all subsequent translation lookups. `select-language` is an alias for `push-lang`. ### Method Typst Function ### Endpoint N/A (Typst Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **language_code** (string) - Required - The language code to push onto the stack (e.g., "en-US", "de-DE"). ### Request Example ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang, select-language #let translations = ( en-US: (greeting: [Hello]), de-DE: (greeting: [Hallo]), fr-FR: (greeting: [Bonjour]), ) #configure-translations(translations, default: "en-US") // Set active language using push-lang #push-lang("de-DE") #tr("greeting") // Output: Hallo // Using the alias select-language #select-language("fr-FR") #tr("greeting") // Output: Bonjour // Languages stack - most recent is active #push-lang("en-US") #tr("greeting") // Output: Hello (en-US is on top) ``` ### Response #### Success Response (N/A) This function modifies the active language stack and does not return a value. #### Response Example N/A ``` -------------------------------- ### Pop Language Stack (Typst) Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Removes the top language from the stack, reverting to the previous language. `restore-language` is an alias for `pop-lang`. Throws an error if called when the stack is empty. ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang, pop-lang, restore-language #let translations = ( en-US: (message: [English message]), de-DE: (message: [Deutsche Nachricht]), ) #configure-translations(translations, default: "en-US") #push-lang("en-US") #tr("message") // Output: English message #push-lang("de-DE") #tr("message") // Output: Deutsche Nachricht #pop-lang() // Remove de-DE from stack #tr("message") // Output: English message (back to en-US) // Using the alias #push-lang("de-DE") #restore-language() // Same as pop-lang() #tr("message") // Output: English message ``` -------------------------------- ### Define Translation Dictionary Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Creates a nested dictionary structure to hold translations for different languages. Each language code (e.g., 'de-DE', 'en-US') maps to its specific translations, which can include nested keys and string values. ```typst #let translations = ( de-DE: ( key1: [Bahnhofsstraße 1], key2: ( subkey1: [Wohnung 1], subkey2: [Wohnung 2], ), ), de-CH: ( key1: [Bahnhofsstrasse 1], key2: ( subkey1: [Top 1], subkey2: [Top 2], ), ), en-US: ( key1: [Bahnhof Street 1], key2: ( subkey1: [Flat 1], subkey2: [Flat 2], ), ), ) ``` -------------------------------- ### Direct Key Lookup with trk() in TiefLang Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Performs a direct key lookup in the translation dictionary. Supports dot notation for nested keys and passes additional arguments to function values. This function is useful for retrieving specific translated strings. ```typst #import "@preview/tieflang:0.1.0": configure-translations, trk, push-lang #let translations = ( en-US: ( static-text: [Static content], nested: ( deep: ( value: [Deeply nested value], ), ), dynamic: (name, count) => [#name has #count items], ), ) #configure-translations(translations) #push-lang("en-US") // Simple key lookup #trk("static-text") // Output: Static content // Nested key with dot notation #trk("nested.deep.value") // Output: Deeply nested value // Function value with arguments #trk("dynamic", "Alice", 5) // Output: Alice has 5 items // With namespace #trk("static-text", namespace: "core") ``` -------------------------------- ### Configure Default Language in TiefLang Source: https://github.com/tiefseetauchner/tieflang/blob/main/README.md Sets a default language for a namespace. This default is used if the language stack is empty. It requires the 'translations' object and the desired default language code. ```typst #configure-translations(translations, default: "de-CH") #tr("key1") // uses de-CH if no language was pushed ``` -------------------------------- ### tr Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Retrieves translations from the configured dictionary. When called without arguments, returns the entire translation dictionary for the current language. When called with a key, performs a direct lookup supporting dot notation for nested keys. ```APIDOC ## tr ### Description Retrieves translations from the configured dictionary. When called without arguments, returns the entire translation dictionary for the current language. When called with a key, performs a direct lookup supporting dot notation for nested keys. ### Method Typst Function ### Endpoint N/A (Typst Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **key** (string) - Optional - The translation key to look up. Supports dot notation for nested keys (e.g., "sections.intro"). If omitted, returns the entire translation dictionary for the current language. - **namespace** (string) - Optional - Specifies the namespace to use for the lookup. ### Request Example ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang #let translations = ( en-US: ( title: [My Document], sections: ( intro: [Introduction], body: [Main Content], ), ), ) #configure-translations(translations) #push-lang("en-US") // Access entire dictionary and use property access #tr().title // Output: My Document #tr().sections.intro // Output: Introduction // Direct key lookup #tr("title") // Output: My Document #tr("sections.intro") // Output: Introduction // With namespace (assuming configure-translations was called with namespace: "my-template") // #tr("title", namespace: "my-template") ``` ### Response #### Success Response (N/A) Returns the translated string or the entire translation dictionary for the current language based on the arguments provided. #### Response Example ```typst // If tr() is called without arguments: // (title: [My Document], sections: (intro: [Introduction], body: [Main Content])) // If tr("title") is called: // [My Document] // If tr("sections.intro") is called: // [Introduction] ``` ``` -------------------------------- ### trk Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Performs a direct key lookup in the translation dictionary. Supports dot notation for nested keys and passes additional arguments to function values. ```APIDOC ## trk ### Description Performs a direct key lookup in the translation dictionary. Supports dot notation for nested keys and passes additional arguments to function values. ### Method Typst Function ### Endpoint N/A (Typst Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **key** (string) - Required - The translation key to look up. Supports dot notation for nested keys (e.g., "nested.deep.value"). - **args**... (any) - Optional - Additional arguments to pass to the translation value if it's a function. - **namespace** (string) - Optional - Specifies the namespace to use for the lookup. ### Request Example ```typst #import "@preview/tieflang:0.1.0": configure-translations, trk, push-lang #let translations = ( en-US: ( static-text: [Static content], nested: ( deep: ( value: [Deeply nested value], ), ), dynamic: (name, count) => [#name has #count items], ), ) #configure-translations(translations) #push-lang("en-US") // Simple key lookup #trk("static-text") // Output: Static content // Nested key with dot notation #trk("nested.deep.value") // Output: Deeply nested value // Function value with arguments #trk("dynamic", "Alice", 5) // Output: Alice has 5 items // With namespace (assuming configure-translations was called with namespace: "core") // #trk("static-text", namespace: "core") ``` ### Response #### Success Response (N/A) Returns the translated string or the result of the function value. #### Response Example ```typst // If trk("static-text") is called: // [Static content] // If trk("nested.deep.value") is called: // [Deeply nested value] // If trk("dynamic", "Alice", 5) is called: // Alice has 5 items ``` ``` -------------------------------- ### Retrieve Translations with tr() in TiefLang Source: https://context7.com/tiefseetauchner/tieflang/llms.txt Retrieves translations from the configured dictionary. When called without arguments, returns the entire translation dictionary for the current language. When called with a key, performs a direct lookup supporting dot notation for nested keys. ```typst #import "@preview/tieflang:0.1.0": configure-translations, tr, push-lang #let translations = ( en-US: ( title: [My Document], sections: ( intro: [Introduction], body: [Main Content], ), ), ) #configure-translations(translations) #push-lang("en-US") // Access entire dictionary and use property access #tr().title // Output: My Document #tr().sections.intro // Output: Introduction // Direct key lookup #tr("title") // Output: My Document #tr("sections.intro") // Output: Introduction // With namespace #tr("title", namespace: "my-template") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.