PHPackages                             helsingborg-stad/wp-content-translator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. helsingborg-stad/wp-content-translator

ActiveWordpress-plugin

helsingborg-stad/wp-content-translator
======================================

Minimalistic content translation in WordPress.

1.0.7(8y ago)1302MITPHP

Since Jan 26Pushed 8y ago9 watchersCompare

[ Source](https://github.com/helsingborg-stad/wp-content-translator)[ Packagist](https://packagist.org/packages/helsingborg-stad/wp-content-translator)[ RSS](/packages/helsingborg-stad-wp-content-translator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (9)Used By (0)

Wp Content Translator
=====================

[](#wp-content-translator)

Minimalistic content translation in WordPress. The plugin handles translations for posts, postmeta, options, siteoptions (multisite) and usermeta.

While the plugin also handles comments and commentmeta they are not translated. Comments are mapped to a specific language (the langauge active when posting the comment) and will be displayed for that specific language. There's also an option to make languages inherit comments from other languages. Forinstance the nordic languages is very similar, so we want to load Danish and Norwegian comments along with the Swedish comments.

Translations
------------

[](#translations)

The GUI is is available in:

- English
- Swedish
- Norwegian

REDIS &amp; Memcached
---------------------

[](#redis--memcached)

If you are using redis or memcached, you want to define a hash-key depending on selected language. The hash key cannot be changed at runtime after it has been set (defined as constant). Add this to your configuration:

```
if (isset($_COOKIE['wp_content_translator_language']) && !empty($_COOKIE['wp_content_translator_language'])) {
    define('WP_CACHE_KEY_SALT', NONCE_KEY.$_COOKIE['wp_content_translator_language']);
} else {
    define('WP_CACHE_KEY_SALT', NONCE_KEY);
}
```

Language selector
-----------------

[](#language-selector)

You can easily use the default language selector (a basic html ``element) or create a language selector with custom markup.

Use the `wp_content_translator_language_selector()` function to display a language selector. If you want to use the default selector just run the function without any paramters. If you want to create a custom selector there's an option to pass markup for the wrapper and the "language rows".

Available template tags to use in the markup:

**Wrapper:**

- *string* languages (displays the language rows)

**Language row:**

- *string* code (sv\_SE)
- *string* name (Swedish)
- *string* nativeName (Svenska)
- *string* url (//domain.tld/?lang=sv\_SE)
- *string* isCurrent ("is-current" if it's the current language, otherwise empty string)

```
wp_content_translator_language_selector(
    $wrapper = '{{ languages }}',
    $element = '{{ name }}'
)
```

Configurations
--------------

[](#configurations)

Each translation component has it's own configuration filter which can be used to change it's configuration.

```
function my_custom_config($config) {
    $config['key'] = 'my value';
    return $config;
}
add_filter('wp-content-translator/configuration/{{component}}', 'my_custom_config');
```

#### wp-content-translator/configuration/general

[](#wp-content-translatorconfigurationgeneral)

Available configurations:

- *bool* translate\_fallback - Fallback to default language or not
- *string* translate\_delimeter - Delimeter to use

#### wp-content-translator/configuration/post

[](#wp-content-translatorconfigurationpost)

Available configurations:

- *bool* translate - Use the component or not

#### wp-content-translator/configuration/{comment/meta/user/option/siteoption}

[](#wp-content-translatorconfigurationcommentmetauseroptionsiteoption)

Available configurations:

- *bool* translate - Use the component or not
- *bool* translate\_hidden - Translate options prefixed with underscore or not
- *bool* translate\_numeric - Translate numeric values or not
- *array* untranslatable - Array with option keys of untranslatable options
- *array* translatable - Array with option keys of translatable options

Filters
-------

[](#filters)

#### wp-content-translator/should\_download\_wp\_translation\_when\_installing

[](#wp-content-translatorshould_download_wp_translation_when_installing)

Decide if the plugin should download the WP language pack when installing languages.

- `@param string $answer` - The default answer
- `@param string $code` - The language code
- `@param \ContentTranslator\Language $language` - The language object

```
function my_download_wp_translation(bool $answer, string $code, \ContentTranslator\Language $language) {
    if ($code === 'sv_SE') {
        return false;
    }

    return $answer;
}
add_filter('wp-content-translator/should_download_wp_translation_when_installing', 'my_download_wp_translation', 10, 3);
```

#### wp-content-translator/admin\_bar/current\_lang

[](#wp-content-translatoradmin_barcurrent_lang)

Filters the name of the current language in the admin bar.

- `@param string $language` - The name of the language
- `@param string $code` - The language code

```
function my_admin_bar_current_lang(string $language, string $code) {
    if ($code === 'sv_SE') {
        return 'Skånska';
    }

    return $language;
}
add_filter('wp-content-translator/admin_bar/current_lang', 'my_admin_bar_current_lang', 10, 2);
```

#### wp-content-translator/redirect\_after\_uninstall\_language

[](#wp-content-translatorredirect_after_uninstall_language)

Where to redirect to after a langauge have been uninstalled.

- `@param string $url` - The default redirect url
- `@param string $code` - The language code
- `@param \ContentTranslator\Language $language` - The language object

```
function my_after_uninstall_redirect(string $url, string $code, \ContentTranslator\Language $language) {
    return 'http://www.helsingborg.se';
}
add_filter('wp-content-translator/redirect_after_uninstall_language', 'my_after_uninstall_redirect', 10, 3);
```

#### wp-content-translator/comment/connections

[](#wp-content-translatorcommentconnections)

Set up inheritance for comments. Load comments from multiple languages for a language. Example: Load Swedish, Norwegian and Danish comments if the current language is Swedish.

- `@param array $connections` - The default connections
- `@param string $code` - The language code

```
function my_comment_connections(array $connections, string $code) {
    return 'http://www.helsingborg.se';
}
add_filter('wp-content-translator/comment/connections', 'my_comment_connections', 10, 2);
```

#### wp-content-translator/{$component}/is\_installed

[](#wp-content-translatorcomponentis_installed)

Is the meta type translate component installed or not?

Available components: post, comment, option, siteoption, meta (postmeta), user (usermeta), comment (commentmeta)

- `@param bool $isInstalled` - The default is installed value
- `@param string $code` - The langauge code

```
function my_is_usermeta_installed(bool $isInstalled, string $code) {
    if ($code === 'sv_SE') {
        return true;
    }

    return $isInstalled;
}
add_filter('wp-content-translator/user/is_installed', 'my_is_usermeta_installed', 10, 2);
```

#### wp-content-translator/{$component}/remove\_when\_uninstalling

[](#wp-content-translatorcomponentremove_when_uninstalling)

Whether to remove metadata when uninstalling the translation component.

Available components: post, comment, option, siteoption, meta (postmeta), user (usermeta), comment (commentmeta)

- `@param bool $shouldRemove` - The default should remove value
- `@param string $code` - The langauge code

```
function my_should_remove_meta(bool $shouldRemove, string $code) {
    if ($code === 'sv_SE') {
        return true;
    }

    return $shouldRemove;
}
add_filter('wp-content-translator/user/remove_meta_when_uninstalling_language', 'my_should_remove_meta', 10, 2);
```

#### wp-content-translator/{$component}/should\_translate\_default

[](#wp-content-translatorcomponentshould_translate_default)

Default return value for `shouldTranslate` method

Available components: post, comment, option, siteoption, meta (postmeta), user (usermeta), comment (commentmeta)

- `@param bool $shouldTranslate` - The default should translate value
- `@param string $code` - The langauge code

```
function my_should_translate_default(bool $shouldTranslate, string $code) {
    if ($code === 'sv_SE') {
        return true;
    }

    return $shouldTranslate;
}
add_filter('wp-content-translator/user/should_translate_default', 'my_should_translate_default', 10, 2);
```

Actions
-------

[](#actions)

#### wp-content-translator/before\_install\_language

[](#wp-content-translatorbefore_install_language)

Runs before a language is installed.

- `@param string $code` - The langauge code
- `@param \ContentTranslator\Language $language` - The langauge object

```
function my_before_install_language($code, $language) {
    // Do my stuff
}
add_action('wp-content-translator/before_install_language', 'my_before_install_language', 10, 2);
```

#### wp-content-translator/after\_install\_language

[](#wp-content-translatorafter_install_language)

Runs after a language have been installed.

- `@param string $code` - The langauge code
- `@param \ContentTranslator\Language $language` - The langauge object

```
function my_after_install_language($code, $language) {
    // Do my stuff
}
add_action('wp-content-translator/after_install_language', 'my_after_install_language', 10, 2);
```

#### wp-content-translator/before\_uninstall\_language

[](#wp-content-translatorbefore_uninstall_language)

Runs before a language is uninstalled.

- `@param string $code` - The langauge code
- `@param \ContentTranslator\Language $language` - The langauge object

```
function my_before_uninstall_language($code, $language) {
    // Do my stuff
}
add_action('wp-content-translator/before_uninstall_language', 'my_before_uninstall_language', 10, 2);
```

#### wp-content-translator/after\_uninstall\_language

[](#wp-content-translatorafter_uninstall_language)

Runs after a language is uninstalled.

- `@param string $code` - The langauge code
- `@param \ContentTranslator\Language $language` - The langauge object

```
function my_after_uninstall_language($code, $language) {
    // Do my stuff
}
add_action('wp-content-translator/after_uninstall_language', 'my_after_uninstall_language', 10, 2);
```

#### wp-content-translator/admin\_bar/before\_add\_switcher

[](#wp-content-translatoradmin_barbefore_add_switcher)

Runs before language switcher is added to the admin bar.

```
function my_admin_bar_before() {
    // Do my stuff
}
add_action('wp-content-translator/admin_bar/before_add_switcher', 'my_admin_bar_before', 10);
```

#### wp-content-translator/admin\_bar/after\_add\_switcher

[](#wp-content-translatoradmin_barafter_add_switcher)

Runs after language switcher have been added to the admin bar.

```
function my_admin_bar_after() {
    // Do my stuff
}
add_action('wp-content-translator/admin_bar/after_add_switcher', 'my_admin_bar_before', 10);
```

#### wp-content-translator/options/before\_add\_options\_page

[](#wp-content-translatoroptionsbefore_add_options_page)

Runs right before the "language" options page is added to the admin menu.

```
function my_options_page_before() {
    // Do my stuff
}
add_action('wp-content-translator/options/before_add_options_page', 'my_options_page_before', 10);
```

#### wp-content-translator/options/aftere\_add\_options\_page

[](#wp-content-translatoroptionsaftere_add_options_page)

Runs right after the "language" options page have been added to the admin menu.

```
function my_options_page_after() {
    // Do my stuff
}
add_action('wp-content-translator/options/after_add_options_page', 'my_options_page_after', 10);
```

#### wp-content-translator/{$component}/install

[](#wp-content-translatorcomponentinstall)

Runs when installing a translation component.

Available components: post, comment, option, siteoption, meta (postmeta), user (usermeta), comment (commentmeta)

- `@param string $code` - The langauge code

```
function my_user_meta_install(string $code) {
    // Do my stuff
}
add_action('wp-content-translator/user/install', 'my_user_meta_install', 10);
```

#### wp-content-translator/{$component}/uninstall

[](#wp-content-translatorcomponentuninstall)

Runs when uninstalling a meta type translate component.

Available components: post, comment, option, siteoption, meta (postmeta), user (usermeta), comment (commentmeta)

- `@param string $code` - The langauge code

```
function my_user_meta_install(string $code) {
    // Do my stuff
}
add_action('wp-content-translator/user/uninstall', 'my_user_meta_uninstall', 10);
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 87.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~42 days

Total

8

Last Release

3160d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f46fe64973c3e89d15c745c0bf601c25983bafea81d30e64d4bf813a6f8c8c7c?d=identicon)[sebastianthulin](/maintainers/sebastianthulin)

---

Top Contributors

[![sebastianthulin](https://avatars.githubusercontent.com/u/797129?v=4)](https://github.com/sebastianthulin "sebastianthulin (123 commits)")[![Svanmark](https://avatars.githubusercontent.com/u/457482?v=4)](https://github.com/Svanmark "Svanmark (16 commits)")[![nRamstedt](https://avatars.githubusercontent.com/u/16800993?v=4)](https://github.com/nRamstedt "nRamstedt (1 commits)")

### Embed Badge

![Health badge](/badges/helsingborg-stad-wp-content-translator/health.svg)

```
[![Health](https://phpackages.com/badges/helsingborg-stad-wp-content-translator/health.svg)](https://phpackages.com/packages/helsingborg-stad-wp-content-translator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
