dyntpl_i18n

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: MIT Imports: 5 Imported by: 0

README

Dyntpl i18n bindings

Provide i18n support to use in dyntpl templates.

Internationalization support provides by i18n package.

I18n enables by setup context with variables like this:

var db *i18n.DB
ctx := dyntpl.AcquireCtx()
defer dyntpl.ReleaseCtx(ctx)
ctx.SetStatic(dyntpl_i18n.DatabaseKey, db).
	SetString(dyntpl_i18n.LocaleKey, "en")
...

or by using shorthand

var db *i18n.DB
ctx := dyntpl_i18n.AcquireCtx("en", "ltr", db)
defer dyntpl_i18n.Release(ctx)
...

For simple translate use function i18n::template or shorthand i18n::t:

{%= i18n::t("key", "default value", {"!placeholder0": "replacement", "!placeholder1": object.Label, ...}) %}

You may omit default value and replacements, only first argument is required.

For plural translation use function i18n::translatePlural or shorthand i18n::tp:

{%= i18n::tp("key", "default value", 15, {...}) %}

Third argument is a count for a plural formula. It's required as a key argument.

Documentation

Index

Constants

View Source
const (
	DatabaseKey            = "i18n__database"
	PlaceholderReplacerKey = "i18n__placeholder"
	LocaleKey              = "i18n__locale"
	DirectionKey           = "i18n__direction"
)

Variables

This section is empty.

Functions

func AcquireCtx

func AcquireCtx(locale, direction string, db *i18n.DB) *dyntpl.Ctx

AcquireCtx takes ctx from default pool and wraps it with locale/direction vars.

func ReleaseCtx

func ReleaseCtx(ctx *dyntpl.Ctx)

Types

This section is empty.

Jump to

Keyboard shortcuts

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