2017 © Pedro Peláez
 

wordpress-plugin wp-content-translator

Minimalistic content translation in WordPress.

image

helsingborg-stad/wp-content-translator

Minimalistic content translation in WordPress.

  • Wednesday, September 13, 2017
  • by sebastianthulin
  • Repository
  • 5 Watchers
  • 1 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

Wp Content Translator

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

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., (*2)

Translations

The GUI is is available in:, (*3)

  • English
  • Swedish
  • Norwegian

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:, (*4)

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

You can easily use the default language selector (a basic html <select>element) or create a language selector with custom markup., (*5)

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"., (*6)

Available template tags to use in the markup:, (*7)

Wrapper:, (*8)

  • string languages (displays the language rows)

Language row:, (*9)

  • 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 = '<ul>{{ languages }}</ul>',
    $element = '<li><a href="{{ url }}" class="{{ isCurrent }}">{{ name }}</a></li>'
)

Configurations

Each translation component has it's own configuration filter which can be used to change it's configuration., (*10)

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

Available configurations: - bool translate_fallback - Fallback to default language or not - string translate_delimeter - Delimeter to use, (*11)

wp-content-translator/configuration/post

Available configurations: - bool translate - Use the component or not, (*12)

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

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, (*13)

Filters

wp-content-translator/should_download_wp_translation_when_installing

Decide if the plugin should download the WP language pack when installing languages., (*14)

  • @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

Filters the name of the current language in the admin bar., (*15)

  • @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

Where to redirect to after a langauge have been uninstalled., (*16)

  • @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

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., (*17)

  • @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

Is the meta type translate component installed or not?, (*18)

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

  • @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

Whether to remove metadata when uninstalling the translation component., (*20)

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

  • @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

Default return value for shouldTranslate method, (*22)

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

  • @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

wp-content-translator/before_install_language

Runs before a language is installed., (*24)

  • @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

Runs after a language have been installed., (*25)

  • @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

Runs before a language is uninstalled., (*26)

  • @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

Runs after a language is uninstalled., (*27)

  • @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

Runs before language switcher is added to the admin bar., (*28)

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

Runs after language switcher have been added to the admin bar., (*29)

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

Runs right before the "language" options page is added to the admin menu., (*30)

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

Runs right after the "language" options page have been added to the admin menu., (*31)

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

Runs when installing a translation component., (*32)

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

  • @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

Runs when uninstalling a meta type translate component., (*34)

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

  • @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);

The Versions

13/09 2017

dev-master

9999999-dev

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

13/09 2017

1.0.7

1.0.7.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

16/05 2017

1.0.6

1.0.6.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

03/05 2017

1.0.5

1.0.5.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

29/03 2017

1.0.4

1.0.4.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

29/03 2017

1.0.3

1.0.3.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

27/02 2017

1.0.2

1.0.2.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

20/02 2017

1.0.1

1.0.1.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark

26/01 2017

1.0.0

1.0.0.0

Minimalistic content translation in WordPress.

  Sources   Download

MIT

by Kristoffer Svanmark