locale

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 3 Imported by: 0

README

locale

i18n library for PurgeBot. Embeds JSON translation files and exposes typed message keys that services use to look up translated strings.

Usage

import "github.com/PurgeBot-net/locale"

// Look up a message in a given language, falling back to en-GB.
locale.MsgPurgeAlreadyRunning.In(lang)

// With fmt.Sprintf args:
locale.MsgPurgeStatusFetching.In(lang, channelName)

lang is a BCP 47 tag (e.g. "en-GB", "de") — typically taken from the Discord interaction's guild or user locale.

Adding translations

  1. Add or update keys in translations/en-GB.json (the source file).
  2. Crowdin picks up the changes automatically via crowdin.yml and creates translation PRs for other locales.
  3. Add a typed constant in messages.go if introducing a new key.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func T

func T(lang string, key Message, args ...any) string

T returns the translation for the dotted key in the given language, falling back to en-GB. Additional args are passed to fmt.Sprintf.

Types

type Message

type Message string

Message is a typed locale key. Use the vars below instead of raw strings.

var (
	// error.*
	MsgErrorGuildOnly         Message = "error.guild_only"
	MsgErrorUnauthorized      Message = "error.unauthorized"
	MsgErrorInternal          Message = "error.internal"
	MsgErrorInternalStart     Message = "error.internal_start"
	MsgErrorUnknownSubcommand Message = "error.unknown_subcommand"

	// purge.*
	MsgPurgeInvalidTarget       Message = "purge.invalid_target"
	MsgPurgeAlreadyRunning      Message = "purge.already_running"
	MsgPurgeNoPerms             Message = "purge.no_perms"
	MsgPurgeInvalidRegex        Message = "purge.invalid_regex"
	MsgPurgeResolveError        Message = "purge.resolve_error"
	MsgPurgeMissingPerms        Message = "purge.missing_perms"
	MsgPurgeMissingPermsChannel Message = "purge.missing_perms_channel"
	MsgPurgeInProgress          Message = "purge.in_progress"

	// purge.status.*
	MsgPurgeStatusLabel    Message = "purge.status.label"
	MsgPurgeStatusStarting Message = "purge.status.starting"
	MsgPurgeStatusFetching Message = "purge.status.fetching"

	// purge.cancelled.*
	MsgPurgeCancelledHeader Message = "purge.cancelled.header"
	MsgPurgeCancelledCount  Message = "purge.cancelled.count"

	// purge.complete.*
	MsgPurgeCompleteHeader            Message = "purge.complete.header"
	MsgPurgeCompleteTotalDeleted      Message = "purge.complete.total_deleted"
	MsgPurgeCompleteDuration          Message = "purge.complete.duration"
	MsgPurgeCompleteChannelsProcessed Message = "purge.complete.channels_processed"
	MsgPurgeCompleteChannelBreakdown  Message = "purge.complete.channel_breakdown"
	MsgPurgeCompleteSkippedChannels   Message = "purge.complete.skipped_channels"
	MsgPurgeCompleteChannelLine       Message = "purge.complete.channel_line"
	MsgPurgeCompleteSkippedLine       Message = "purge.complete.skipped_line"

	// target.*
	MsgTargetServer Message = "target.server"

	// cancel.*
	MsgCancelButton     Message = "cancel.button"
	MsgCancelNotAllowed Message = "cancel.not_allowed"
	MsgCancelRequested  Message = "cancel.requested"

	// customize.*
	MsgCustomizeNoPerms   Message = "customize.no_perms"
	MsgCustomizeNoPremium Message = "customize.no_premium"
	MsgCustomizeSaved     Message = "customize.saved"
	MsgCustomizeCleared   Message = "customize.cleared"

	// skip_channels.*
	MsgSkipChannelsPrompt   Message = "skip_channels.prompt"
	MsgSkipChannelsContinue Message = "skip_channels.continue"
	MsgSkipChannelsExpired  Message = "skip_channels.expired"

	// welcome.*
	MsgWelcomeDM Message = "welcome.dm"

	// stats.*
	MsgStatsNoPremium Message = "stats.no_premium"
	MsgStatsHeader    Message = "stats.header"
	MsgStatsTotals    Message = "stats.totals"
	MsgStatsLastPurge Message = "stats.last_purge"
	MsgStatsNoPurges  Message = "stats.no_purges"

	// help.*
	MsgHelpHeader Message = "help.header"

	MsgHelpCommandsTitle Message = "help.commands.title"
	MsgHelpCommandsBody  Message = "help.commands.body"

	MsgHelpParametersTitle Message = "help.parameters.title"
	MsgHelpParametersBody  Message = "help.parameters.body"

	MsgHelpFilteringTitle Message = "help.filtering.title"
	MsgHelpFilteringBody  Message = "help.filtering.body"

	MsgHelpPermissionsTitle Message = "help.permissions.title"
	MsgHelpPermissionsBody  Message = "help.permissions.body"

	MsgHelpButtonInvite  Message = "help.buttons.invite"
	MsgHelpButtonSupport Message = "help.buttons.support"
)

func (Message) In

func (m Message) In(lang string, args ...any) string

In returns the translation for this message in the given language. Additional args are passed to fmt.Sprintf.

Jump to

Keyboard shortcuts

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