class-foo-friendly-dates.php
4 weeks ago
class-foo-plugin-base.php
4 weeks ago
class-foo-plugin-file-locator.php
4 weeks ago
class-foo-plugin-metabox-sanity.php
4 weeks ago
class-foo-plugin-options.php
4 weeks ago
class-foo-plugin-settings.php
4 weeks ago
class-foo-plugin-textdomain.php
4 weeks ago
index.php
4 weeks ago
class-foo-plugin-textdomain.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /* |
| 8 | * Foo Plugin TextDomain Class |
| 9 | * |
| 10 | * A helpful class to handle loading plugin language files |
| 11 | * |
| 12 | * Version: 1.0 |
| 13 | * Author: Brad Vincent |
| 14 | * Author URI: http://fooplugins.com |
| 15 | * License: GPL2 |
| 16 | */ |
| 17 | |
| 18 | if ( !class_exists( 'Foo_Plugin_TextDomain_v1_0' ) ) { |
| 19 | |
| 20 | class Foo_Plugin_TextDomain_v1_0 { |
| 21 | |
| 22 | /** |
| 23 | * Loads the plugin language files |
| 24 | * |
| 25 | * @access public |
| 26 | * @since 1.0 |
| 27 | * |
| 28 | * @param string $plugin_file The main plugin file |
| 29 | * @param string $plugin_slug The plugin slug/folder name |
| 30 | * @param string $language_directory The plugin language directory relative to the main plugin file. Default directory is /languages/ |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public static function load_textdomain($plugin_file, $plugin_slug, $language_directory = '/languages/') { |
| 35 | |
| 36 | // Set filter for plugin's languages directory |
| 37 | $lang_dir = dirname( plugin_basename( $plugin_file ) ) . $language_directory; |
| 38 | $lang_dir = apply_filters( $plugin_slug . '_languages_directory', $lang_dir ); |
| 39 | |
| 40 | // Traditional WordPress plugin locale filter |
| 41 | $locale = apply_filters( 'plugin_locale', get_locale(), $plugin_slug ); |
| 42 | $mo_file = sprintf( '%1$s-%2$s.mo', $plugin_slug, $locale ); |
| 43 | |
| 44 | // Setup paths to current locale file |
| 45 | $mo_file_local = $lang_dir . $mo_file; |
| 46 | $mo_file_global = WP_LANG_DIR . "/{$plugin_slug}/" . $mo_file; |
| 47 | |
| 48 | if ( file_exists( $mo_file_global ) ) { |
| 49 | // Look in global /wp-content/languages/plugin-slug/ folder |
| 50 | load_textdomain( $plugin_slug, $mo_file_global ); |
| 51 | } elseif ( file_exists( $mo_file_local ) ) { |
| 52 | // Look in local /wp-content/plugins/plugin-slug/languages/ folder |
| 53 | load_textdomain( $plugin_slug, $mo_file_local ); |
| 54 | } else { |
| 55 | // Load the default language files |
| 56 | load_plugin_textdomain( $plugin_slug, false, $lang_dir ); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |