Skip to content

Controlling Defaults

BoBkiNN edited this page Mar 2, 2026 · 2 revisions

Sometimes you want to change what default values are returned by different parts of system. This pages describes places related to defaults.

Unknown translation key

When translation not found, each resolver defines how to handle this.
But default translation resolvers provides hooks for it.

FallbackTranslationResolver and BasicTranslationResolver

You can override getMissingText method - it is called when all previous lookups returned nothing

No translation resolved

When translation resolver returns null value, Renderer#onNullTranslation method is called inside I18nEngine#parse

No parsed template found in StringRenderer and ComponentRenderer

When template string is failed to be parsed, TemplateCache#getOrCompute returns null.
In this case, these renderers invoke onParsingFailed method which can be overriden.
By default it returns translation key stored in current context.

On maximum inline depth

When maximum inlining depth is reached, both StringTemplateFormatter and ComponentTemplateFormatter call their onFailedInline method. Here you can configure what text to return in this case. Default implemenetation returns <key> text wrapper in output object, where key is replaced by key requested by inline part

Unknown argument

When there are more arguments passed than parsed text can have, for example having template Hello %s! Order status is %s but passing only one value.

Both StringTemplateFormatter and ComponentTemplateFormatter invoke onUnknownArgument method. By default it returns string %n wrapped inside output object. n is an index of argument part from template + 1.

One of override cases is to insert argument source text as it appears in template string using TemplateArgument#getSource() method

Clone this wiki locally