Modules

Docs / API / Modules / translations

Translations

Admin & chat

@s2script/sdk/translations

SourceMod-style i18n (per-client language, phrase files, {1} formatting).

2 exports

Import

import { Phrases } from "@s2script/sdk/translations";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

type
Phrases

A phrase set: key → template string, where {1}/{2}/… are positional substitution slots.

const
Translations

SourceMod-style translation registry: seed a default phrase set, override it per language from translations/<code>/<name>.phrases.json, then translate a key for a given client's language.

import { Translations } from "@s2script/sdk/translations";
Translations.load("trdemo", { Greeting: "Hello {1}", Bye: "Goodbye {1}" });
console.log(Translations.translate(-1, "Greeting", "world")); // "Hello world"
load(name: string, seed: Phrases): void
Register a phrase set: seed is the built-in English default; translations/<code>/<name>.phrases.json overrides per language.
translate(slot: number, key: string, ...args: (string | number)[]): string
Translate key for slot's language (slot < 0 = the server default), substituting positional {1}/{2} args.
setDefaultLanguage(code: string): void
Set the server/console default language code (default "" = root/English).
Back to modules All packages

s2script — Source 2 plugin framework

GitHub