Documentation ¶
Index ¶
- Variables
- type ContentTagProcessor
- type ControlProcessor
- type MatchProcessor
- type Processor
- func NewContentTagProcessor(tagProcessor ContentTagProcessor) Processor
- func NewControlPlaceholderProcessor(controlProcessor ControlProcessor) Processor
- func NewRegexpProcessor(regexp *regexp.Regexp, matchProcessor MatchProcessor) Processor
- func NewStandaloneTagProcessor(tagProcessor StandaloneTagProcessor) Processor
- type StandaloneTagProcessor
- type Translator
Constants ¶
This section is empty.
Variables ¶
var ( // EntityPlaceholder replaces entity references like __ENTITY__coal with their translation. EntityPlaceholder = NewRegexpProcessor(regexpEntityPlaceholder, processEntityPlaceholder) // ItemPlaceholder replaces item references like __ITEM__electronic-circuit__ with their translation. ItemPlaceholder = NewRegexpProcessor(regexpItemPlaceholder, processItemPlaceholder) // PositionPlaceholder replaces positional placeholders like __1__ with the translated parameter. PositionPlaceholder = NewRegexpProcessor(regexpPositionPlaceholder, processPositionPlaceholder) )
var ( // PluralPlaceholder replaces the plural placeholders like __plural_for_parameter_1_{...}__. PluralPlaceholder = NewRegexpProcessor(regexpPluralPlaceholder, processPluralPlaceholder) )
Functions ¶
This section is empty.
Types ¶
type ContentTagProcessor ¶
type ContentTagProcessor = func(translator Translator, locale, name, value, content string) (string, bool)
type ControlProcessor ¶
type MatchProcessor ¶
type Processor ¶
type Processor = func(translator Translator, locale string, value string, parameters []any) string
Processor is the type of functions able to process already translated strings, e.g. by replacing placeholders in them. The function returns the transformed value.
func NewContentTagProcessor ¶
func NewContentTagProcessor(tagProcessor ContentTagProcessor) Processor
NewContentTagProcessor creates a new processor for replacing pairs of tags with actual content between them, like [color=red]foo[/color]. The only possible tags are [color] and [font], all other tags will be ignored. Both ending tags [/color] and [.color] will be detected. Closing tags must match the opening counterparts, mismatched tags will remain untouched. Each tag will be passed to the tagProcessor, including the already-processed content between it. The tagProcessor must return the replacement for the tag, and whether processing it was actually successful.
func NewControlPlaceholderProcessor ¶
func NewControlPlaceholderProcessor(controlProcessor ControlProcessor) Processor
NewControlPlaceholderProcessor creates a new processor which replaces references to controls like __CONTROL__build__ as well as to alternative controls like __ALT_CONTROL__2__build__. Whenever a control placeholder is detected, the provided controlProcessor will be called. In case of normal controls the version will always be 0, in case of alternative controls the number from the placeholder will be passed in as version. The controlProcessor must return the replacement value, and whether the processing was actually successful.
func NewRegexpProcessor ¶
func NewRegexpProcessor(regexp *regexp.Regexp, matchProcessor MatchProcessor) Processor
NewRegexpProcessor creates a new processor based on a regular expression. The regular expression is run on the input, and each match to the expression is passed to the matchProcessor. Each matched groups of the expression get passed in as values to the matchProcessor. The matchProcessor must return the replacement, and whether the processing was actually successful.
func NewStandaloneTagProcessor ¶
func NewStandaloneTagProcessor(tagProcessor StandaloneTagProcessor) Processor
NewStandaloneTagProcessor creates a new processor for replacing standalone tags like [item=electronic-circuit]. Each found tag will be passed to the tagProcessor, which must provide the replacement for the tag, and whether the processing was actually successful.
type StandaloneTagProcessor ¶
type StandaloneTagProcessor = func(translator Translator, locale, name, value string) (string, bool)