Documentation
¶
Index ¶
- Constants
- Variables
- func ByLanguage(versions []Version) map[string]Version
- func RegisterRoutes(r modulekit.Mux, c *Controller, admin func(http.Handler) http.Handler)
- func RegisterTranslationRoutes(r modulekit.Mux, c *TranslationsController, ...)
- func Wire(d modulekit.Deps) modulekit.Parts
- type Alternate
- type Controller
- func (c *Controller) Add(w http.ResponseWriter, r *http.Request)
- func (c *Controller) List(w http.ResponseWriter, r *http.Request)
- func (c *Controller) MakeDefault(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Remove(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)
- type Link
- type Member
- type Repo
- type Settings
- type Texts
- func (t *Texts) Languages(ctx context.Context, kind, ref string) ([]string, error)
- func (t *Texts) SaveLanguages(ctx context.Context, kind, ref string, langs []string) error
- func (t *Texts) SaveTranslations(ctx context.Context, kind, ref string, values map[string]string) error
- func (t *Texts) Text(ctx context.Context, lang, kind, ref string) (string, bool, error)
- func (t *Texts) Translations(ctx context.Context, kind, ref string) (map[string]string, error)
- func (t *Texts) Visible(ctx context.Context, kind, ref, lang string) (bool, error)
- type TranslationInfo
- type TranslationRepo
- func (r *TranslationRepo) Add(ctx context.Context, source, translation int) error
- func (r *TranslationRepo) SaveSettings(ctx context.Context, st Settings) error
- func (r *TranslationRepo) Saved(ctx context.Context, nid int) error
- func (r *TranslationRepo) Set(ctx context.Context, nid int) ([]Member, error)
- func (r *TranslationRepo) Settings(ctx context.Context) (Settings, error)
- type Translations
- func (t *Translations) SaveSettings(ctx context.Context, st Settings) error
- func (t *Translations) Settings(ctx context.Context) (Settings, error)
- func (t *Translations) Translatable(ctx context.Context, nodeType string) (bool, error)
- func (t *Translations) Translate(ctx context.Context, db *sql.DB, node modulekit.Node, lang string, ...) (int, error)
- func (t *Translations) Versions(ctx context.Context, nid int) ([]Version, error)
- type TranslationsController
- type Version
Constants ¶
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 ¶
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 ¶
ByLanguage - versions by language: the first of each.
func RegisterRoutes ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (*Repo) NodeCounts ¶
NodeCounts - the number of nodes (the trash's too) of each language, by code.
type Settings ¶
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 (*Texts) SaveLanguages ¶
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) Translations ¶
Translations - kind of ref in each language it has, by language.
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.
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 ¶
Translatable - the items of nodeType are translated.
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 ¶
func (c *TranslationsController) Page(w http.ResponseWriter, r *http.Request)
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 ¶
func (c *TranslationsController) Translate(w http.ResponseWriter, r *http.Request)
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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |