Translate class for handling text translation and transformation.

Constructors

  • Constructs a new instance of the Translator class.

    Parameters

    • Optionallocale: Locale

      An object representing the initial locale configuration.

    • Optionaltransform: (str: string) => string

      A function for transforming strings.

    • Optionalconfig: Partial<ITranslateConfig>

      An object representing additional configuration options.

    Returns Translate

Properties

clear: () => void

Clear the _skip and _transformed variables.

config: Partial<ITranslateConfig>
createElement: (
    type: string,
    props: null | IAttributeCollection,
    ...children: any[],
) => any

Creates and returns an element based on the provided type, props, and children.

Type declaration

    • (type: string, props: null | IAttributeCollection, ...children: any[]): any
    • Parameters

      • type: string

        The type of the element to create.

      • props: null | IAttributeCollection

        The properties or attributes to assign to the element.

      • ...children: any[]

        The child elements or content to append to the element.

      Returns any

      • The created element.
install: (
    ...params: [
        locale?: Locale,
        transform?: (str: string) => string,
        config?: Partial<ITranslateConfig>,
    ],
) => Translate

Installs the Translate object and configures React.

Type declaration

    • (
          ...params: [
              locale?: Locale,
              transform?: (str: string) => string,
              config?: Partial<ITranslateConfig>,
          ],
      ): Translate
    • Parameters

      • ...params: [
            locale?: Locale,
            transform?: (str: string) => string,
            config?: Partial<ITranslateConfig>,
        ]

        The parameters needed to create a new Translate instance.

      Returns Translate

      The installed Translate object.

jss: (type: string, props: null | IAttributeCollection) => ReactElement<{}, any>

Create an element using the given type and props

Type declaration

    • (type: string, props: null | IAttributeCollection): ReactElement<{}, any>
    • Parameters

      • type: string

        The type of the element

      • props: null | IAttributeCollection

        The props for the element

      Returns ReactElement<{}, any>

      • The created element
translateText: (text: string) => string

Translates the given text to another language.

Type declaration

    • (text: string): string
    • Parameters

      • text: string

        The text to be translated.

      Returns string

      The translated text.

use: (middleware: Middleware) => void

Adds a middleware to the list of used middlewares.

Type declaration

    • (middleware: Middleware): void
    • Parameters

      • middleware: Middleware

        The middleware to be added.

      Returns void

Accessors