Skip to content

I18n Helper Constants

This file defines regular expression constants used for parsing and matching translation tags in the @sodacore/core i18n (internationalization) system. These regex patterns are used to identify and extract translation keys from strings in templates, queries, or code.


Constants

  • REGEX_TRANSLATION_TAG Matches all occurrences of the translation tag pattern _t(...) in a string.

    • Pattern: /\_t\((.*?)\)/gi
    • Usage: Used to find and extract all translation tags within a text.
  • REGEX_TRANSLATION_TAG_QUERY Matches a string that consists entirely of a translation tag pattern _t(...).

    • Pattern: /^\_t\((.*)\)$/
    • Usage: Used to check if a string is exactly a translation tag and to extract its content.

Usage

typescript
import { REGEX_TRANSLATION_TAG, REGEX_TRANSLATION_TAG_QUERY } from './helper/constants';

const text = "Welcome, _t(user.name)!";

// Find all translation tags in a string
const matches = text.match(REGEX_TRANSLATION_TAG);

// Check if a string is a translation tag query
const isQuery = REGEX_TRANSLATION_TAG_QUERY.test('_t(greeting.hello)');

Notes

  • These constants are intended for internal use within the i18n system to support dynamic translation key extraction and replacement.
  • The patterns assume translation tags are written as _t(key) in templates or code.

Released under the Apache-2.0 License.