Refactor Localizer into a separate class.

This commit is contained in:
marco
2015-08-09 21:44:37 +02:00
parent 62c0f18c03
commit 787ee9f043
2 changed files with 59 additions and 35 deletions

View File

@ -15,17 +15,12 @@ class Initializer {
$activator = new Activator();
$activator->init();
// localization
$this->setup_textdomain();
add_action(
'init',
array($this, 'localize'),
0
);
$renderer = new Renderer();
$this->renderer = $renderer->init();
$localizer = new Localizer($this->renderer);
$localizer->init();
$menu = new Menu(
$this->renderer,
Env::$assets_url
@ -85,31 +80,4 @@ class Initializer {
);
wp_enqueue_script($name);
}
public function localize() {
load_plugin_textdomain(
Env::$plugin_name,
false,
dirname(plugin_basename(Env::$file)) . '/lang/'
);
// set rtl flag
$this->renderer->addGlobal('is_rtl', is_rtl());
}
public function setup_textdomain() {
$locale = apply_filters(
'plugin_locale',
get_locale(),
Env::$plugin_name
);
$language_path = Env::$languages_path.'/'.Env::$plugin_name.'-'.$locale.'.mo';
load_textdomain(Env::$plugin_name, $language_path);
load_plugin_textdomain(
Env::$plugin_name,
false,
dirname(plugin_basename(Env::$file)) . '/lang/'
);
}
}

56
lib/config/localizer.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace MailPoet\Config;
if(!defined('ABSPATH')) exit;
class Localizer {
function __construct($renderer) {
$this->renderer = $renderer;
}
function init() {
add_action(
'init',
array($this, 'setup'),
0
);
}
function setup() {
$this->loadGlobalText();
$this->loadPluginText();
$this->setGlobalRtl();
}
function loadGlobalText() {
$language_path =
Env::$languages_path
. '/'
. Env::$plugin_name
. '-'
. $this->locale()
. '.mo';
load_textdomain(Env::$plugin_name, $language_path);
}
function loadPluginText() {
load_plugin_textdomain(
Env::$plugin_name,
false,
dirname(plugin_basename(Env::$file)) . '/lang/'
);
}
function setGlobalRtl() {
$this->renderer->addGlobal('is_rtl', is_rtl());
}
function locale() {
$locale = apply_filters(
'plugin_locale',
get_locale(),
Env::$plugin_name
);
return $locale;
}
}