languages

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UntranslatedOriginal - their original (the default).
	UntranslatedOriginal = "original"
	// UntranslatedHide - nothing: the language's items only.
	UntranslatedHide = "hide"
	// UntranslatedAll - every item: lists aren't narrowed by language.
	UntranslatedAll = "all"
)

What a list in a language shows of the items without a version in it.

Variables

View Source
var Assets embed.FS

Assets - the module's templates/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

Functions

func ByLanguage

func ByLanguage(versions []Version) map[string]Version

ByLanguage - versions by language: the first of each.

func RegisterRoutes

func RegisterRoutes(r modulekit.Mux, c *Controller, admin func(http.Handler) http.Handler)

RegisterRoutes registers the Languages page and its actions (behind admin).

func RegisterTranslationRoutes

func RegisterTranslationRoutes(r modulekit.Mux, c *TranslationsController, auth func(http.Handler) http.Handler)

RegisterTranslationRoutes registers a content item's Translations tab and making a translation (behind auth, the sign-in).

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the site's languages in use while the module is on (their prefixes, SetLanguagesSwitch); on every page the switcher's links, the alternates, a content item's translations; the Translations tab of a translated type's items (AddNodePage), their marks kept as their forms save them (OnNodeFormSaved); the content lists in the page's language (SetContentListFilter); the Language section of their forms; the site's texts in its languages (wireTexts); the Languages page. Its uninstall step forgets the languages.

Types

type Alternate

type Alternate struct {
	Lang string
	Href string
}

Alternate - the page's address in a language, for search engines (<link rel="alternate" hreflang>): Lang - the language's code, or "x-default" for the default language's address.

type Controller

type Controller struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

Controller - the Languages page: the site's languages, adding one, removing one, making one the default.

func NewController

func NewController(base *modulekit.BaseController, db *sql.DB, repo *Repo, site siteInformation, changed func(), translations *Translations, types modulekit.ContentTypeService) *Controller

NewController creates a Controller; changed is called after the site's languages change (the cached blocks hold the old addresses).

func (*Controller) Add

func (c *Controller) Add(w http.ResponseWriter, r *http.Request)

Add handles POST /admin/config/languages: a known language the site hasn't, at a prefix (its code when none is given) no other language, address or content takes.

func (*Controller) List

func (c *Controller) List(w http.ResponseWriter, r *http.Request)

List renders GET /admin/config/languages: the default language first, then the others in the order added; the form adding one of the known languages the site hasn't.

func (*Controller) MakeDefault

func (c *Controller) MakeDefault(w http.ResponseWriter, r *http.Request)

MakeDefault handles POST /admin/config/languages/{code}/default: one of the others, with the interface in it, becomes the default language - its addresses lose the prefix, the old default's get its code (modulekit.MoveDefaultLanguage); the site's interface follows.

func (*Controller) Remove

func (c *Controller) Remove(w http.ResponseWriter, r *http.Request)

Remove handles POST /admin/config/languages/{code}/remove: the language leaves the site; its content stays, at addresses without the prefix.

func (*Controller) Settings

func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)

Settings handles POST /admin/config/languages/settings: the content types whose items are translated (of the site's) and what a list in a language shows of the items without a version in it.

type Link struct {
	Code string
	// Name - the language's own name ("Deutsch"); Label - its short
	// one ("DE").
	Name  string
	Label string
	Href  string
	// Current - the page's language.
	Current bool
	// Home - the page has no version in it: Href is its front page.
	Home bool
}

Link - a language of the switcher: its address for the page shown.

type Member

type Member struct {
	Nid      int
	Original bool
	Outdated bool
}

Member - a content item of a set of translations: Original - the set's original; Outdated - the original changed after it was last saved.

type Repo

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

Repo - what the Languages page reads of the site's content (the core's nodes, counted). A built-in module, tested with the engine, may read the core's tables in its SQL; a module of its own repository goes through the SDK's services instead (docs/modules/sdk.md): the core's columns aren't its API.

func NewRepo

func NewRepo(db *sql.DB) *Repo

NewRepo creates a Repo on the site's database.

func (*Repo) NodeCounts

func (r *Repo) NodeCounts(ctx context.Context) (map[string]int, error)

NodeCounts - the number of nodes (the trash's too) of each language, by code.

func (*Repo) SlugsUnder

func (r *Repo) SlugsUnder(ctx context.Context, prefix string) (bool, error)

SlugsUnder - whether a node's address starts with prefix/ (a prefix would hide it).

type Settings

type Settings struct {
	TranslatableTypes []string
	Untranslated      string
}

Settings - the module's settings: the content types whose items are translated; what a list in a language shows of the items without a version in it (Untranslated*).

type Texts

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

Texts - the site's own texts in its other languages and the things shown only in some languages: read once into memory (every page asks), kept until changed here.

func NewTexts

func NewTexts(db *sql.DB) *Texts

NewTexts creates Texts on the site's database.

func (*Texts) Languages

func (t *Texts) Languages(ctx context.Context, kind, ref string) ([]string, error)

Languages - the languages chosen for the thing (none - every one).

func (*Texts) SaveLanguages

func (t *Texts) SaveLanguages(ctx context.Context, kind, ref string, langs []string) error

SaveLanguages sets the languages whose pages show the thing (none - every one's).

func (*Texts) SaveTranslations

func (t *Texts) SaveTranslations(ctx context.Context, kind, ref string, values map[string]string) error

SaveTranslations sets kind of ref in the languages of values ("" - none in it: the text as entered).

func (*Texts) Text

func (t *Texts) Text(ctx context.Context, lang, kind, ref string) (string, bool, error)

Text - kind of ref in lang (false - none).

func (*Texts) Translations

func (t *Texts) Translations(ctx context.Context, kind, ref string) (map[string]string, error)

Translations - kind of ref in each language it has, by language.

func (*Texts) Visible

func (t *Texts) Visible(ctx context.Context, kind, ref, lang string) (bool, error)

Visible - the thing (kind, ref) shows on a page in lang: no languages chosen for it, or lang among them.

type TranslationInfo

type TranslationInfo struct {
	Language     string
	Original     *Version
	Outdated     bool
	Translations []string
}

TranslationInfo - a content item's place in its set of translations, for its form: Language - its language's name; Original - the original it translates (nil - it is the original); Outdated - the original changed since it was saved; Translations - the original's translations' languages.

type TranslationRepo

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

TranslationRepo - the module's tables: the sets of translations and the settings.

func NewTranslationRepo

func NewTranslationRepo(db *sql.DB) *TranslationRepo

NewTranslationRepo creates a TranslationRepo on the site's database.

func (*TranslationRepo) Add

func (r *TranslationRepo) Add(ctx context.Context, source, translation int) error

Add puts translation in the set of source (source's set - a new one with source as its original when source has none).

func (*TranslationRepo) SaveSettings

func (r *TranslationRepo) SaveSettings(ctx context.Context, st Settings) error

SaveSettings saves the module's settings.

func (*TranslationRepo) Saved

func (r *TranslationRepo) Saved(ctx context.Context, nid int) error

Saved records that nid's own form saved it: an original's translations become outdated, a translation is up to date again.

func (*TranslationRepo) Set

func (r *TranslationRepo) Set(ctx context.Context, nid int) ([]Member, error)

Set - the set of translations nid is in: its members, the original first; none - nid has no translations.

func (*TranslationRepo) Settings

func (r *TranslationRepo) Settings(ctx context.Context) (Settings, error)

Settings - the module's settings (the defaults while none are saved).

type Translations

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

Translations - the sets of translations and which content types have them.

func NewTranslations

func NewTranslations(repo *TranslationRepo, nodes nodeRows) *Translations

NewTranslations creates Translations.

func (*Translations) SaveSettings

func (t *Translations) SaveSettings(ctx context.Context, st Settings) error

SaveSettings saves the module's settings.

func (*Translations) Settings

func (t *Translations) Settings(ctx context.Context) (Settings, error)

Settings - the module's settings (read once, kept until saved).

func (*Translations) Translatable

func (t *Translations) Translatable(ctx context.Context, nodeType string) (bool, error)

Translatable - the items of nodeType are translated.

func (*Translations) Translate

func (t *Translations) Translate(ctx context.Context, db *sql.DB, node modulekit.Node, lang string, user *modulekit.User) (int, error)

Translate creates node's translation into lang by user - a copy of it in lang, its title kept, unpublished - in node's set: its id.

func (*Translations) Versions

func (t *Translations) Versions(ctx context.Context, nid int) ([]Version, error)

Versions - the items of nid's set of translations ctx's visitor may see (the trash's left out), the original first; none - nid has no translations.

type TranslationsController

type TranslationsController struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

TranslationsController - a content item's Translations tab and making a translation.

func NewTranslationsController

func NewTranslationsController(base *modulekit.BaseController, db *sql.DB, nodes modulekit.NodesRepository, types modulekit.ContentTypeService, translations *Translations) *TranslationsController

NewTranslationsController creates a TranslationsController.

func (*TranslationsController) Page

Page renders GET /node/{id}/translations: each site language - the default first - with its version of the item: the original, the translations (outdated marked), Translate where there's none.

func (*TranslationsController) Translate

Translate handles POST /node/{id}/translations/{lang}: the item's translation into lang - a copy of it in lang, unpublished, in its set - when its set has none yet; its form opens.

type Version

type Version struct {
	Member
	Node modulekit.Node
}

Version - a content item of a set of translations as shown: the item (its own columns: type, title, address, status, language) and its place in the set.

func (Version) Public

func (v Version) Public() bool

Public - anyone may see it: published and not on moderation.

Directories

Path Synopsis
ent
Package ent - the languages module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the languages module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the languages module's own ent schema: which content items translate which, and the module's settings.
Package schema - the languages module's own ent schema: which content items translate which, and the module's settings.
Package manifest declares the languages module (its registry entry): the site's languages besides its default one, each at its own address prefix (/en/…), the language switcher and the pages' addresses in the other languages for search engines.
Package manifest declares the languages module (its registry entry): the site's languages besides its default one, each at its own address prefix (/en/…), the language switcher and the pages' addresses in the other languages for search engines.

Jump to

Keyboard shortcuts

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