---
title: "CallableStrategy"
description: "Wrap a closure as a translation backend – the simplest extension point and the migration path off the old translateFn option."
canonical_url: "https://kirby.tools/docs/content-translator/php-classes/strategies/callable-strategy"
---

# CallableStrategy

> Wrap a closure as a translation backend – the simplest extension point and the migration path off the old translateFn option.

Wrap a closure as a `Strategy`. The closure runs once per text – no batching. Reach for a custom `Strategy` implementation when batching matters.

<note>

This is what wraps the deprecated `translateFn` option behind the scenes. New code should set `strategy => $closure` directly, or implement `Strategy` for batching support.

</note>

## Construction

```php
public function __construct(Closure $translate)
```

<field-group>
<field name="translate" type="Closure(string $text, string $target, ?string $source): string">

Translation function. Returns the translated text. The same signature as the legacy `translateFn`.

</field>
</field-group>

## Usage

<tabs :default-value="config">
<tabs-item label="Via config" value="config">

```php [config.php]
return [
    'johannschopplich.content-translator' => [
        'strategy' => function (string $text, string $target, ?string $source): string {
            return myTranslateFunction($text, $target, $source);
        },
    ],
];
```

The closure is auto-wrapped in `CallableStrategy`.

</tabs-item>

<tabs-item label="Explicit" value="explicit">

```php
use JohannSchopplich\ContentTranslator\Translation\Strategies\CallableStrategy;

return [
    'johannschopplich.content-translator' => [
        'strategy' => new CallableStrategy(
            fn (string $text, string $target, ?string $source) => myTranslateFunction($text, $target, $source),
        ),
    ],
];
```

</tabs-item>
</tabs>

## When to Use Something Else

`CallableStrategy` is fine for low-volume sites and `translateFn` migration. For batching, per-field dispatch, or structured exceptions, see [Implementing a Custom Strategy](/docs/content-translator/php-classes/strategies#implementing-a-custom-strategy).

---

Every page of this site as Markdown: <https://kirby.tools/sitemap.md>
