locale of the bundled file. * * @var array */ private static $bundled = array( 'de' => 'de_DE', 'es' => 'es_ES', 'fr' => 'fr_FR', 'it' => 'it_IT', ); /** * Register the loader. * * @return void */ public static function init() { add_action( 'init', array( __CLASS__, 'load' ), 0 ); } /** * Load the bundled file for the current locale, if any. * * @return void */ public static function load() { $file = self::bundled_file( determine_locale() ); if ( '' !== $file ) { load_textdomain( '3task-doorman', $file ); } } /** * The bundled file for a locale, or an empty string when a language pack from * translate.wordpress.org is installed or no bundled file fits. * * de_AT and de_CH use de_DE, formal German uses de_DE_formal, es_MX uses es_ES and so on. * * @param string $locale Locale. * @return string */ public static function bundled_file( $locale ) { $locale = (string) $locale; if ( file_exists( WP_LANG_DIR . '/plugins/3task-doorman-' . $locale . '.mo' ) ) { return ''; } $dir = THREEDOOR_DIR . 'languages/3task-doorman-'; $exact = $dir . $locale . '.mo'; if ( file_exists( $exact ) ) { return $exact; } $language = strtolower( substr( $locale, 0, 2 ) ); if ( ! isset( self::$bundled[ $language ] ) ) { return ''; } $fallback = self::$bundled[ $language ]; if ( 'de' === $language && false !== strpos( $locale, '_formal' ) ) { $fallback = 'de_DE_formal'; } $file = $dir . $fallback . '.mo'; return file_exists( $file ) ? $file : ''; } }