Skip to content

apply
@localizer/transform 1.1.3

This factory allows to use any custom string function as a transformer for localizable values.

Usage

This utility allows you to define a transformation function that modifies the localized output in any way you need. For example, you can wrap text in markdown-style bold formatting:

typescript
import { 
loc
} from '@localizer/core';
import {
transform
,
apply
} from '@localizer/transform';
const
bold
=
apply
((
text
) => `**${
text
}**`);
const
value
=
loc
`Custom function`;
const
result
=
transform
(
value
, [
bold
]);

NOTE

Such transformations are not tied to any specific locale. For scenarios requiring locale-aware transformations, you can implement a custom transformer by adhering to the Transformer type. This allows you to define transformations that respect locale-specific rules and nuances, ensuring accurate and context-sensitive results.

typescript
import { loc } from '@localizer/core';
import { transform } from '@localizer/transform';

const bold = (localizable) => loc`**${localizable}**`;

const value = loc`Custom function`;
const result = transform(value, [bold]);