Skip to content

Instantly share code, notes, and snippets.

@grappler
Last active November 26, 2016 14:47
Show Gist options
  • Save grappler/7060277 to your computer and use it in GitHub Desktop.
Save grappler/7060277 to your computer and use it in GitHub Desktop.
Loading theme and plugin translations in WordPress - https://ulrich.pogson.ch/load-theme-plugin-translations
<?php
function theme_name_setup(){
$domain = 'theme-name';
// wp-content/languages/theme-name/de_DE.mo
load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain );
// wp-content/themes/child-theme-name/languages/de_DE.mo
load_theme_textdomain( $domain, get_stylesheet_directory() . '/languages' );
// wp-content/themes/theme-name/languages/de_DE.mo
load_theme_textdomain( $domain, get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'theme_name_setup' );
<?php
function plugin_name_load_plugin_textdomain() {
$domain = 'plugin-name';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
// wp-content/languages/plugin-name/plugin-name-de_DE.mo
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
// wp-content/plugins/plugin-name/languages/plugin-name-de_DE.mo
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'init', 'plugin_name_load_plugin_textdomain' );
@mszzarei
Copy link

mszzarei commented Jul 8, 2015

hi.how can change name language plugin?
ex:change plugin-name-de_DE.mo to de_DE.mo?!

@bogdanfix
Copy link

mszzarei, you can change the line 8 in "plugin-name.php" from:

load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );

to:

load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $locale . '.mo' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment