Fallback Values

The .Fallback() method provides a default value when a translation key is missing or invalid.

Syntax

string result = key.Tr(table).Fallback(defaultValue);

Basic Usage

// If "missing.key" doesn't exist, returns "Default Text"
string text = "missing.key".Tr("UI").Fallback("Default Text");

// If key exists, returns the translated value
string text = "menu.title".Tr("UI").Fallback("Untitled");

When Fallback Is Used

Fallback is returned when:

  1. The key doesn't exist in the table

  2. The column for current locale is missing

  3. The cell value is null or empty

Use Cases

Missing Keys

Provide graceful degradation:

Development Placeholders

Use fallbacks during development:

User-Generated Content

Handle dynamic content safely:

Chaining

Fallback can be combined with other methods:

Dynamic Fallbacks

Generate fallback values dynamically:

Empty String vs Fallback

Best Practices

Meaningful Fallbacks

Provide fallbacks that make sense in context:

Debug Mode

Use fallbacks to identify missing translations during development:

UI Default Text

Set fallback to match your UI's default state:

Performance

Fallback values are only evaluated when needed (lazy evaluation):

Last updated