caddy_i18n

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 18 Imported by: 0

README

caddy-i18n

Use standard GNU Gettext PO translation files to translate HTML responses served via a Caddy web server.

Installation

Install xcaddy

xcaddy build --with github.com/ewen-lbh/caddy-i18n@v0.1.2

Usage

See the example Caddyfile for a simple example.

You can see what the final responses look like in ./example/responses. The example .po files used are in ./example/messages.

Documentation

Overview

Package caddy_i18n provides a middleware that translates HTML responses to the user's preferred language, by using standard GNU Gettext .po files. Translatable strings are marked as such in the HTML using attributes and or tags. The middleware strips out those markers and replaces the strings with their translations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I18n

type I18n struct {
	// The directory where the .po files are stored. The files must be named LANGUAGE.po, where LANGUAGE is the language code (see the languages field).
	Translations string `json:"translations,omitempty"`
	// The HTML attribute used to mark inner content of the tag it is placed on as translatable strings. Defaults to i18n.
	HTMLAttribute string `json:"html_attribute,omitempty"`
	// The HTML tag used to mark inner content of the tag it is placed on as translatable strings. Defaults to i18n.
	HTMLTag string `json:"html_tag,omitempty"`
	// The language code of the content the original responses are written in. Defaults to en.
	SourceLanguage string `json:"source_language,omitempty"`
	// The target languages we should attempt to translate to.
	Languages []string `json:"languages,omitempty"`
	// Update the .po files with new translatable strings found in the HTML responses. Disabled by default.
	UpdateTranslations bool `json:"update_translations,omitempty"`
	// Include a <script>window.i18nLanguage = "...";</script> in the response to expose the language code to JavaScript.
	ExposeToJS bool `json:"expose_to_js,omitempty"`

	*zap.Logger
	// contains filtered or unexported fields
}

func (I18n) CaddyModule

func (I18n) CaddyModule() caddy.ModuleInfo

func (*I18n) Provision

func (m *I18n) Provision(ctx caddy.Context) error

func (*I18n) ServeHTTP

func (m *I18n) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

func (*I18n) Validate

func (m *I18n) Validate() error

Jump to

Keyboard shortcuts

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