render

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package render fournit le moteur de templates HTML pour JellyGate.

Charge tous les templates depuis web/templates/ au démarrage, charge les traductions depuis web/i18n/{lang}.json, et fournit une interface simple pour le rendu avec i18n contextuel.

La fonction T() utilise la langue du contexte de requête et effectue un fallback automatique sur le français si une clé est absente.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine is the HTML template engine with i18n support.

func NewEngine

func NewEngine(templatesDir, i18nDir string) (*Engine, error)

NewEngine creates a new template engine. Loads layouts, pages, and translations.

Parameters:

  • templatesDir: templates directory (web/templates)
  • i18nDir: translations directory (web/i18n)

func (*Engine) NewTemplateData

func (e *Engine) NewTemplateData(lang string) *TemplateData

NewTemplateData creates a TemplateData tied to a language. The T() function automatically resolves keys in the correct language with fallback to English/French.

func (*Engine) Render

func (e *Engine) Render(w io.Writer, name string, data *TemplateData) error

Render exécute un template avec les données fournies.

func (*Engine) Translate

func (e *Engine) Translate(lang, key string) string

Translate returns the translation of a key in the requested language. If the key does not exist in the requested language, it falls back to English, then to French. If not found anywhere, it returns "[key]".

type TemplateData

type TemplateData struct {
	Lang        string
	AppVersion  string
	ScriptNonce string

	Section string                 // Section actuelle (ex: "login", "users")
	Data    map[string]interface{} // Données arbitraires
	Error   string
	Session interface{}

	// Raccourcis pour les templates (évite .Data.XXX dans les templates)
	Invitation          interface{}
	AdminUsername       string
	IsAdmin             bool
	CanInvite           bool
	LDAPEnabled         bool
	ShowNewPasswordForm bool
	ResetCode           string
	SuccessMessage      string
	// contains filtered or unexported fields
}

TemplateData est la structure passée à tous les templates. Le champ T (translate) est une fonction qui retourne la traduction d'une clé dans la langue courante, avec fallback sur le français.

func (*TemplateData) T

func (d *TemplateData) T(key string) string

T retourne la traduction pour la clé donnée, dans la langue de ce contexte.

type Translations

type Translations map[string]string

Translations est un dictionnaire de traductions clé → valeur.

Jump to

Keyboard shortcuts

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