translation

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 0

README

togo

togo-framework/translation

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/translation

translation — DB-backed dynamic i18n for togo

A togo plugin that makes translations editable at runtime, in the database — no redeploy. It overrides the kernel translator (k.I18n): keys resolve from the DB first and fall back to the static i18n catalog (install togo-framework/i18n for the static fallback).

togo install togo-framework/i18n          # static catalog (fallback)
togo install togo-framework/translation   # DB-backed dynamic overrides

REST API

Method Path Body
GET /api/translations?locale=ar — → {key: value}
GET /api/translations/locales — → ["ar","en"]
PUT /api/translations/{locale}/{key} {"value":"..."}
DELETE /api/translations/{locale}/{key}
POST /api/translations/import {locale:{key:value}}

Go API

t := translation.FromKernel(k)
_ = t.Set(ctx, "ar", "welcome", "مرحبا")
msg := k.I18n.T("ar", "welcome")   // DB value, else the static catalog

Data model

translations(locale text, tkey text, value text, PRIMARY KEY (locale, tkey)), created on boot. An in-memory cache backs T() (refreshed on writes).

MIT


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package translation is a togo plugin: DB-backed dynamic i18n. It overrides the kernel translator (k.I18n) with one that resolves keys from the database first and falls back to the static i18n catalog. Translations are editable at runtime (no redeploy) via the Go API or the REST endpoints under /api/translations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the DB-backed translator + manager (kernel service "translation").

func FromKernel

func FromKernel(k *togo.Kernel) *Store

FromKernel returns the translation store, or nil if not installed.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, locale, key string) error

Delete removes a translation.

func (*Store) List

func (s *Store) List(locale string) map[string]string

List returns all overrides for a locale.

func (*Store) Locales

func (s *Store) Locales() []string

Locales returns the locales that have DB overrides.

func (*Store) Set

func (s *Store) Set(ctx context.Context, locale, key, value string) error

Set upserts a translation and updates the cache.

func (*Store) T

func (s *Store) T(locale, key string) string

T implements togo.Translator: DB value if present, else the static catalog.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL