# Override translations in plugins

**URL:** <https://forum.getkirby.com/t/override-translations-in-plugins/17997>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 24, 2020, 5:30am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997 "2020-04-24T05:30:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastiangreger](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sebastiangreger/32/16176_2.png) [@sebastiangreger](https://forum.getkirby.com/u/sebastiangreger)\
**Post date:** [April 24, 2020, 5:30am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997/1 "2020-04-24T05:30:28Z")

</div>

Hi, I am researching the following use case:

A plugin uses the `t()` helper for some frontend strings; these are translated into (currently) two languages in `languages/*.php` files.

Is there a way to “inject” my own translations for these strings via the `config.php` on my site?

This could be for two motives:

- either because I need to override the default hardcoded into the plugin for my language (in this specific case: the plugin uses the German informal “Du” but my site uses the formal “Sie”), or
- because my site is running in a locale the plugin does not (yet) provide a translation for.

I looked through the docs and the code of I18n, but couldn’t figure it out myself. I’d greatly appreciate for any pointers! The only thing I dug up was this older thread about overriding Kirby’s default translations (not plugins); I could not find anything related in the Ideas repo either.

> [@Overwrite some translations](https://forum.getkirby.com/t/overwrite-some-translations/16316/2):
>
> Hm, as far as I know, overriding the default translations is not possible. But this is actually a good idea and we should then have these as official translations. You can make suggestions on Transifex.

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [April 24, 2020, 5:47am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997/2 "2020-04-24T05:47:23Z")

</div>

Hi Sebastian,

You can use a dedicated plugin to override language strings. Just make sure its folder name starts with an “x” or something so it will be the last plugin that will be loaded (kind hacky, I know, but it works).

Like this:

```php
<?php

Kirby::plugin('bvdputte/translations-override', [
    'translations' => [
        'en' => [
            "someLangString" => "Sie haben die Übersetzung angepasst",
        ]
    ]
]);

```

Maybe, there’s a less hacky way using the [system.loadPlugins:after](https://getkirby.com/docs/reference/plugins/hooks/system-loadplugins-after) hook and use a function that overrides language strings after all plugins are loaded? But I have not looked into that.

---

<div class="post-metadata">

**Author:** ![sebastiangreger](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sebastiangreger/32/16176_2.png) [@sebastiangreger](https://forum.getkirby.com/u/sebastiangreger)\
**Post date:** [April 24, 2020, 7:16am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997/3 "2020-04-24T07:16:48Z")

</div>

Hi Bart,

Thank you for those ideas. That sounds hacky indeed (and there does not seem to be documentation on how to work with system.loadPlugin:after, so I could not figure it out), but it indeed works! So it has to be a plugin, since `config.php` does not offer a `translations` option, and the plugin has to be loaded after the plugin I want to override. Makes sense.

I also tried adding the string from the plugin to my `site/languages/*.php` files, but that does not work either (which surprises me, as I’d consider that a place to set language strings for everywhere over my site, including plugins).

Now, if I am writing a plugin myself where users should be able to override the built-in translations (e.g. because not everybody might like the informal “Du”), I would have to provide some means for that myself? What appears to work is using `option()` helpers within my `languages/*.php` files - that enables developers to adjust the strings as they see fit.

Maybe I should create an Ideas issue for a more generic override feature?

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [April 24, 2020, 8:07am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997/4 "2020-04-24T08:07:58Z")

</div>

> [@sebastiangreger](#):
>
> also tried adding the string from the plugin to my `site/languages/*.php` files, but that does not work either

AFAIK That’s because plugins can override everything. That’s also why this _trick_, with storing the translations in a plugin and make sure it is the last one to load, works.

> Now, if I am writing a plugin myself where users should be able to override the built-in translations

Maybe you could use Hristiyan’s [variables plugin](https://github.com/OblikStudio/kirby-variables-field) for this? It enables editors to edit the _custom language variables_.

---

<div class="post-metadata">

**Author:** ![sebastiangreger](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sebastiangreger/32/16176_2.png) [@sebastiangreger](https://forum.getkirby.com/u/sebastiangreger)\
**Post date:** [April 25, 2020, 11:37am UTC](https://forum.getkirby.com/t/override-translations-in-plugins/17997/5 "2020-04-25T11:37:53Z")

</div>

> [@bvdputte](#):
>
> Maybe you could use Hristiyan’s [variables plugin](https://github.com/OblikStudio/kirby-variables-field) for this? It enables editors to edit the _custom language variables_ .

Thanks for the tip - will keep this in mind for future needs!

Here’s what I went with for my current project (where editing the translation strings in the panel is not required), using the `options()` helper in the `languages/en.php` of the plugin:

```php
<?php
$translations = [
    'headline.title' => 'Title',
    'headline.field' => 'Field',
];
foreach ($translations as $key => $value) {
    $return['myplugin.' . $key] = option('sgkirby.myplugin.t.en.' . $key, $value);
}
return $return;

```

That way, developers can override the strings in their `config.php` using the `'sgkirby.myplugin.t.en.headline.title'` option (and - on multi-language sites - for other languages with the respective language acronmy as well).

Still a bit hacky, but it serves the purpose 🙂
