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;

This implementation is independent of third party libraries that you may be using. Thus, you may prefer to implement ITextLocalizerService yourself.

There are two text values associated with localization:

  • A lookup key. A short code that maps to the actual string for each culture.
  • Fallback text. The text supplied when the lookup key does not have anything to offer for the given culture.

Hierarchy (view full)

Implements

Constructors

Accessors

Methods

  • Returns the localized version of the text for the given culture. Will try the language from the culture ('en' from 'en-US') and a code called '' to be used as a general fallback. You will have to register the '' code along with your language code translations if you want support of ''. service.Register('TRUE', { '': 'true', 'en': 'true', 'es': 'verdadero' }); If nothing is matched, it returns the fallback text.

    Parameters

    • cultureIdToMatch: string

      It will only use the language code part, like 'en' in 'en-US'. It will always attempt to match to '*' if the language code doesn't match.

    • l10nKey: null | string

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

    • fallback: null | string

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

    Returns null | string

    The localized text or the fallback text.

  • 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.

  • Constructs the l10nText for the Error Message.

    Parameters

    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

    Returns string

  • 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.

  • Constructs the l10nText for the Summary error message.

    Parameters

    • errorCode: string

      same as ConditionType unless you set the ValidatorConfig.errorCode property

    • dataTypeLookupKey: null | string

    Returns string

  • 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

Generated using TypeDoc v0.25.12