Purpose & Overview
Translates specified model attributes across multiple locales dynamically with fallback support, without altering the underlying table schema.
Installation & Setup
1
Install the package
bash
bun add @veap/translatable2
Apply trait to your domain Model
models/YourModel.ts
typescript
// models/Page.ts
import { TranslatableModel } from "@veap/translatable";
export class Page extends TranslatableModel {
static table = "pages";
static translatable = ["title", "content", "meta_description"];
}
// Storing and retrieving translations:
const page = await Page.find("page-uuid");
page.setTranslation("title", "es", "Página Principal");
page.setTranslation("title", "en", "Home Page");
await page.save();3
Run database migrations
bash
bun run veap migrateKeep in mind
- Translatable attributes are declared as an array on the model: `static translatable = ['title', 'content']`.
- Supports retrieving localized values for a specific locale with automatic fallback to the default locale.
- Stores translation values in a central polymorphic `translations` table via `morphMany`.
Dependencies
Veap Core
@veap/core (^0.1.0)
Authors & Maintainers
Veap Core Team
Maintainer
Specifications
- License
- MIT
- Type
- plugin
- Status
- official
- Repository
- GitHub →
- Issues
- Report issue →