@morkg/lamed
v1.0.1
Published
@morkg/lamed is a lightweight, fluent, and highly scalable i18n (internationalization) library for TypeScript. The package allows you to define flat string paths (e.g., 'ui/button/save') and magically compiles them into a deeply nested, strictly-typed dic
Maintainers
Readme
Lamed
A bidirectional, strictly-typed i18n builder for TypeScript.
@morkg/lamed lets you define flat translation keys and compile them into a nested dictionary with native fallback locale support, preset collections, and function-based translations.
Why use Lamed
- Fluent, chainable API for locale setup and dictionary compilation
- Strict TypeScript types for generated nested translation objects
- Zero runtime overhead from path nesting
- Presets for common UI, auth, validation, http, navigation, date, field, and language strings
- Support for function-based translations and fallback locale resolution
Installation
npm install @morkg/lamedor
yarn add @morkg/lamedQuick Start
import lamed from "@morkg/lamed";
const dict = lamed()
.locate("en-US", "pt-BR")
.define({
"auth/signIn": {
"en-US": "Sign in",
"pt-BR": "Entrar",
},
"auth/greeting": {
"en-US": (name: string) => `Hello, ${name}!`,
"pt-BR": (name: string) => `Olá, ${name}!`,
},
})
.dict();
console.log(dict.auth.signIn);
console.log(dict.auth.greeting("John"));API
lamed()
Creates a new builder instance.
.locate(primary, fallback?)
Sets the active locale and optional fallback locale.
.define(...presetsOrDefinitions)
Registers translation definitions or preset collections.
.dict()
Compiles the nested dictionary for the current locale and fallback chain.
Presets
Lamed includes built-in preset packages that can be merged into your own definitions.
import lamed, { preset } from "@morkg/lamed";
const dict = lamed()
.locate("en-US")
.define(
preset.ui,
preset.auth,
{
"ui/actions/save": {
"en-US": "Save Changes",
},
"app/custom/title": {
"en-US": "My App",
},
}
)
.dict();
console.log(dict.ui.actions.save);
console.log(dict.auth.signIn);Custom Presets
Create your own preset definitions with the same type-safe shape as built-in presets.
import type { Preset } from "@morkg/lamed";
export const myCustomPreset = {
"admin/users/create": {
"en-US": "Create User",
"pt-BR": "Criar Usuário",
},
} satisfies Preset;How it works
Lamed stores translations as flat paths grouped by locale and builds a nested dictionary only when .dict() is called.
locate()chooses the active and fallback localedefine()accepts translation maps and preset objectsdict()resolves missing values from fallback locale and returns a typed nested object
Runtime behavior
- Missing translations fall back to the fallback locale
- Translation leaf values can be strings or typed functions
- The final result mirrors the flat key structure as a nested tree
Exports
@morkg/lamed exports:
lamed— default factory functionpreset— built-in preset namespaceui,auth,validation,http,date,navigation,field,language— individual preset exportsPreset,StandardLocales,Locale— TypeScript helper types
import lamed, { auth, validation } from "@morkg/lamed";
const dict = lamed()
.locate("en-US")
.define(auth, validation)
.dict();Contributing
Contributions are welcome. Please open an issue or pull request at https://github.com/morkg/lamed.
- Open an issue for major changes
- Keep PRs small and descriptive
- Run
npm run buildbefore submitting when relevant
License
MIT
