trans

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SHORT_TIME_FORMAT = "SHORT_TIME_FORMAT"
	LONG_TIME_FORMAT  = "LONG_TIME_FORMAT"
)
View Source
const (
	DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
)
View Source
const PACKAGE_PATH = "github.com/Nigel2392/go-django/src/core/trans"

Variables

View Source
var (
	Monday    = S("Monday")
	Tuesday   = S("Tuesday")
	Wednesday = S("Wednesday")
	Thursday  = S("Thursday")
	Friday    = S("Friday")
	Saturday  = S("Saturday")
	Sunday    = S("Sunday")

	ShortMonday    = S("Mon")
	ShortTuesday   = S("Tue")
	ShortWednesday = S("Wed")
	ShortThursday  = S("Thu")
	ShortFriday    = S("Fri")
	ShortSaturday  = S("Sat")
	ShortSunday    = S("Sun")

	January   = S("January")
	February  = S("February")
	March     = S("March")
	April     = S("April")
	May       = S("May")
	June      = S("June")
	July      = S("July")
	August    = S("August")
	September = S("September")
	October   = S("October")
	November  = S("November")
	December  = S("December")

	ShortJanuary   = S("Jan")
	ShortFebruary  = S("Feb")
	ShortMarch     = S("Mar")
	ShortApril     = S("Apr")
	ShortMay       = S("May")
	ShortJune      = S("Jun")
	ShortJuly      = S("Jul")
	ShortAugust    = S("Aug")
	ShortSeptember = S("Sep")
	ShortOctober   = S("Oct")
	ShortNovember  = S("Nov")
	ShortDecember  = S("Dec")

	AM   = S("AM")
	PM   = S("PM")
	AMPM = S("AM/PM")
)
View Source
var TRANSLATIONS_DEFAULT_LOCALE = language.English

Functions

func ContextWithLocale added in v1.7.2

func ContextWithLocale(ctx context.Context, locale language.Tag) context.Context

ContextWithLocale returns a new context with the given locale set.

func DefaultLocale added in v1.7.2

func DefaultLocale() language.Tag

func GetText added in v1.7.2

func GetText(ctx context.Context, v any) (string, bool)

func GetTextFunc added in v1.7.2

func GetTextFunc(v any) (fn func(ctx context.Context) Translation)

func LocaleFromContext added in v1.7.2

func LocaleFromContext(ctx context.Context) language.Tag

LocaleFromContext retrieves the locale from the current context. If the default backend is not set, it returns an empty string.

func S

func S(v Untranslated, args ...any) func(ctx context.Context) Translation

S is a shortcut for translating a string with the default backend.

It returns a function that can be used in templates to translate the string. The function takes a context and returns a Translation (alias for string).

func SP added in v1.7.2

func SP(singular, plural Untranslated, n any, args ...any) func(ctx context.Context) Translation

SP is a shortcut for pluralizing a string with the default backend.

It returns a function that can be used in templates to pluralize the string. The function takes a context, singular and plural forms, and a count. It returns a Translation (alias for string) that can be used in templates.

Types

type Locale added in v1.7.2

type Locale = string

type LocaleMap added in v1.7.2

type LocaleMap = map[Locale]TranslationTextMap

type SprintBackend added in v1.7.0

type SprintBackend struct{}

func (*SprintBackend) Pluralize added in v1.7.2

func (b *SprintBackend) Pluralize(ctx context.Context, singular, plural string, n int) string

func (*SprintBackend) Pluralizef added in v1.7.2

func (b *SprintBackend) Pluralizef(ctx context.Context, singular, plural string, n int, args ...any) string

func (*SprintBackend) TimeFormat added in v1.7.2

func (b *SprintBackend) TimeFormat(ctx context.Context, short bool) string

func (*SprintBackend) Translate added in v1.7.0

func (b *SprintBackend) Translate(ctx context.Context, v string) string

func (*SprintBackend) Translatef added in v1.7.0

func (b *SprintBackend) Translatef(ctx context.Context, v string, args ...any) string

type Translation added in v1.7.2

type Translation = string

func P added in v1.7.2

func P(ctx context.Context, singular, plural Untranslated, n any, args ...any) Translation

P is a shortcut for pluralizing a string with the default backend. It returns a function that can be used in templates to pluralize the string. The function takes a context, singular and plural forms, and a count. It returns a Translation (alias for string) that can be used in templates.

func T

func T(ctx context.Context, v Untranslated, args ...any) Translation

T translates a string with the default backend.

It returns a Translation (alias for string) that can be used in templates.

func Time added in v1.7.2

func Time(ctx context.Context, t time.Time, format string) Translation

Time formats a time.Time value into a Translation (alias for string) using the specified format.

It parses the format string and replaces format specifiers with their corresponding values.

Values such as weekday names and month names are localized based on the current context's locale.

The format codes are as follows:

- %a short weekday na (e.g., "Mon") - %A full weekday nam (e.g., "Monday") - %w weekday number (1-7, Monday is 1, Sunday is 7) - %b short month name (e.g., "Jan") - %B full month name (e.g., "January") - %m month number (01-12) - %-m month number (1-12) - %d day of the month (01-31) - %-d day of the month (1-31) - %y year (4 digits, e.g., 2023) - %-y year (2 digits, e.g., 23) - %Y year (4 digits, e.g., 2023) - %-Y year (2 digits, e.g., 23) - %H hour (00-23) - %-H hour (0-23) - %I hour (01-12) - %-I hour (1-12) - %M minute (00-59) - %-M minute (0-59) - %S second (00-59) - %-S second (0-59) - %f milliseconds (000-999) - %-f milliseconds (0-999) - %F microseconds (000000-999999) - %-F microseconds (0-999999) - %z timezone offset (e.g., "+02:00") - %Z timezone name (e.g., "UTC") - %j day of the year (001-366) - %U week number (00-53, Sunday as first day of week) - %W week number (00-53, Monday as first day of week) - %p AM/PM - %% an escaped percent sign

type TranslationBackend added in v1.6.8

type TranslationBackend interface {
	Translate(ctx context.Context, v Untranslated) Translation
	Translatef(ctx context.Context, v Untranslated, args ...any) Translation
	Pluralize(ctx context.Context, singular, plural Untranslated, n int) Translation
	Pluralizef(ctx context.Context, singular, plural Untranslated, n int, args ...any) Translation
	TimeFormat(ctx context.Context, short bool) Translation
}
var DefaultBackend TranslationBackend = &SprintBackend{}

type TranslationTextMap added in v1.7.2

type TranslationTextMap = map[Untranslated]Translation

type Untranslated added in v1.7.2

type Untranslated = string

Jump to

Keyboard shortcuts

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