Skip to main content

Localization Context

LocalizationContext lets custom app code read and temporarily override the active culture and language. It is available in all Custom Code blocks via the AppNow.Framework.Web.Business.Exposed namespace.

Key Concepts

ConceptTypePurpose
CultureCultureInfoControls number/date formatting (cs-CZ, de-DE, …)
LanguageFrameworkLanguageControls which translation strings are resolved

The two are related but independent. The language drives translation lookups — both built-in system translations and your app's Custom translations (accessed as App.Translations.MyString). The culture drives .NET formatting (number separators, date order, etc.).

Supported languages:

FrameworkLanguageDefault culture
enen-US
cscs-CZ
sksk-SK
dede-DE

Reading the Active Locale

// Current culture — use for formatting
var price = amount.ToString("N2", LocalizationContext.CurrentCulture);

// Current language — use for conditional logic
if (LocalizationContext.CurrentLanguage == FrameworkLanguage.cs)
label = "Uložit";

Both properties return the app's configured default when no override is active (for example, outside of a request or before any Acquire call).

Overriding the Locale

Use Acquire(...) to change the locale for the duration of a using block. The previous locale is automatically restored when the block exits, even if an exception is thrown.

By language (culture is derived automatically)

using (LocalizationContext.Acquire(FrameworkLanguage.de))
{
// CurrentLanguage == de, CurrentCulture == de-DE
var label = App.Translations.SaveButton; // resolves the German translation
}
// previous locale restored here

By culture (language is inferred from culture prefix)

using (LocalizationContext.Acquire(new CultureInfo("cs-CZ")))
{
// CurrentCulture == cs-CZ, CurrentLanguage == cs (inferred from "cs" prefix)
var formatted = total.ToString("N2", LocalizationContext.CurrentCulture);
}

If the culture prefix does not map to a known FrameworkLanguage (e.g. fr-FR), the language falls back to the application's configured default.

By culture and language independently

Use this overload when you need the culture and language to differ — for example, formatting numbers with a specific regional culture while keeping translations in a different language.

using (LocalizationContext.Acquire(new CultureInfo("en-US"), FrameworkLanguage.cs))
{
// CurrentCulture == en-US → decimal point is "."
// CurrentLanguage == cs → translations are Czech
var message = App.Translations.ConfirmDelete;
var price = amount.ToString("N2", LocalizationContext.CurrentCulture);
}

Common Pattern: Generating a Document in a Specific Language

A typical use case is generating a PDF or export file in the language of the end recipient rather than the language of the logged-in user.

var recipientLanguage = FrameworkLanguage.sk;

using (LocalizationContext.Acquire(recipientLanguage))
{
var content = RenderInvoice(order);
SavePdf(content);
}