A service to offer text alternatives to the default text based on cultureId.

It supports having fallbacks, so the app can have a standard implementation and another that introduces special cases.

To set that up:

let vs = createValidationServices(); // provides the standard case in vs.textLocalizerService
let special = new TextLocalizerService();
special.fallbackService = vs.textLocalizerService;
vs.textLocalizerService = special;
interface ITextLocalizerService {
    serviceName: string;
    fallbackService: null | ITextLocalizerService;
    dispose(): void;
    localize(cultureIdToMatch, l10nKey, fallback): null | string;
    localizeWithDetails(cultureIdToMatch, l10nKey, fallback): LocalizedDetailsResult;
    getErrorMessage(cultureIdToMatch, errorCode, dataTypeLookupKey): null | string;
    getSummaryMessage(cultureIdToMatch, errorCode, dataTypeLookupKey): null | string;
    getDataTypeLabel(cultureIdToMatch, dataTypeLookupKey): null | string;
    register(l10nKey, cultureToText): void;
    registerErrorMessage(errorCode, dataTypeLookupKey, cultureToText): void;
    registerSummaryMessage(errorCode, dataTypeLookupKey, cultureToText): void;
    registerDataTypeLabel(dataTypeLookupKey, cultureToText): void;
}

Hierarchy (view full)

Implemented by

Properties

serviceName: string
fallbackService: null | ITextLocalizerService

Reference to a fallback of the same service or null if no fallback.

Methods

  • If the user needs to abandon this instance, they should use this to clean up active resources (like timers) and to release memory that would stall the garbage collector from disposing this object. It should assign any object reference to undefined as a strong indicator that the object has been disposed.

    Returns void

  • Returns the localized version of the text for the given culture. If nothing is matched, it returns the fallback text.

    Parameters

    • cultureIdToMatch: string

      The cultureID.

    • l10nKey: null | string

      Localization key, which is the text that identifies which word, phrase, or other block of text is requested. If null or '', no localization is requested.

    • fallback: null | string

      Used when there was no match for the culture. Only supply '' if you are sure that registered data will always supply a value.

    Returns null | string

    The localized text or the fallback text.

  • Localizes the given text with additional details. See localize() for more information.

    Parameters

    • cultureIdToMatch: string

      The culture ID to match for localization.

    • l10nKey: null | string

      The localization key.

    • fallback: null | string

      The fallback text to use if localization fails.

    Returns LocalizedDetailsResult

    An object containing the localized text, localization result, requested culture ID, and actual culture ID.

  • Attempts to get the localized error message for the ErrorCode and optional DataTypeLookupKey If dataTypeLookupKey is supplied and no match is found, it tries with just the ErrorCode.

    Parameters

    • cultureIdToMatch: string
    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

    Returns null | string

    The error message or null if not available.

  • Attempts to get the localized Summary error message for the ErrorCode and optional DataTypeLookupKey If dataTypeLookupKey is supplied and no match is found, it tries with just the ErrorCode.

    Parameters

    • cultureIdToMatch: string
    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

    Returns null | string

    The Summary error message or null if not available.

  • Attempts to get the localized label for a data type lookup key to be used in {DataType} token of error messages.

    Parameters

    • cultureIdToMatch: string
    • dataTypeLookupKey: string

    Returns null | string

    The name or null if not available.

  • Registers a lookup key with the culture specific text. Replaces an already registered entry with the same l10nKey.

    Parameters

    • l10nKey: string

      Localization key, which is the text that identifies which word, phrase, or other block of text is requested.

    • cultureToText: CultureToText

      keys are language codes from cultureId, like 'en'. values are the actual text to output.

    Returns void

  • Utility to add an error message for a validator. The localization key (l10ntext) will use this pattern: 'EM-' + ErrorCode + '-' + DataTypeLookupKey 'EM-' + ErrorCode // this is a fallback

    Parameters

    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

      optional.

    • cultureToText: CultureToText

    Returns void

  • Utility to add a summary error message for a validator The localization key (l10ntext) will use this pattern: 'SEM-' + ErrorCode + '-' + DataTypeLookupKey 'SEM-' + ErrorCode // this is a fallback

    Parameters

    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

      optional.

    • cultureToText: CultureToText

    Returns void

  • Utility to add text representation of a data type associating it with its dataTypeLookupKey. The text is used with the {DataType} token in error messages. The localization key (l10ntext) will use this pattern: 'DTLK-' + DataTypeLookupKey

    Parameters

    Returns void

Generated using TypeDoc v0.25.12