PopulatorData
2 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
2 weeks ago
Capabilities.php
2 months ago
Changelog.php
2 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
2 months ago
Env.php
6 months ago
Hooks.php
1 month ago
HooksWooCommerce.php
1 month ago
Initializer.php
1 month ago
Installer.php
10 months ago
Localizer.php
3 years ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
2 weeks ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
2 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
1 month ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
2 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
5 days ago
index.php
3 years ago
Localizer.php
84 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class Localizer { |
| 11 | public function init(WPFunctions $wpFunctions) { |
| 12 | $this->loadGlobalText(); |
| 13 | $this->setupTranslationsUpdater($wpFunctions); |
| 14 | } |
| 15 | |
| 16 | private function setupTranslationsUpdater(WPFunctions $wpFunctions) { |
| 17 | $translationUpdater = $this->getUpdater($wpFunctions); |
| 18 | $translationUpdater->init(); |
| 19 | } |
| 20 | |
| 21 | public function loadGlobalText() { |
| 22 | $languagePath = sprintf( |
| 23 | '%s/%s-%s.mo', |
| 24 | Env::$languagesPath, |
| 25 | Env::$pluginName, |
| 26 | $this->locale() |
| 27 | ); |
| 28 | WPFunctions::get()->loadTextdomain(Env::$pluginName, $languagePath); |
| 29 | } |
| 30 | |
| 31 | public function locale() { |
| 32 | $locale = WPFunctions::get()->applyFilters( |
| 33 | 'plugin_locale', |
| 34 | WPFunctions::get()->getUserLocale(), |
| 35 | Env::$pluginName |
| 36 | ); |
| 37 | return $locale; |
| 38 | } |
| 39 | |
| 40 | public function forceInstallLanguagePacks(WPFunctions $wpFunctions) { |
| 41 | $translationUpdater = $this->getUpdater($wpFunctions); |
| 42 | // Add MailPoet translation update to the update_plugins site transient via inner hook |
| 43 | $transient = $translationUpdater->checkForTranslations(new \stdClass()); |
| 44 | $mailpoetTranslations = []; |
| 45 | $translationUpdates = $transient->translations ?? []; |
| 46 | foreach ($translationUpdates as $translationUpdate) { |
| 47 | $mailpoetTranslations[] = (object)$translationUpdate; |
| 48 | } |
| 49 | |
| 50 | if (!empty($mailpoetTranslations)) { |
| 51 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 52 | require_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; |
| 53 | $upgrader = new \Language_Pack_Upgrader(new SilentUpgraderSkin()); |
| 54 | $upgrader->bulk_upgrade($mailpoetTranslations); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function forceLoadWebsiteLocaleText() { |
| 59 | $languagePath = sprintf( |
| 60 | '%s/%s-%s.mo', |
| 61 | Env::$languagesPath, |
| 62 | Env::$pluginName, |
| 63 | WPFunctions::get()->getLocale() |
| 64 | ); |
| 65 | WPFunctions::get()->unloadTextdomain(Env::$pluginName); |
| 66 | WPFunctions::get()->loadTextdomain(Env::$pluginName, $languagePath); |
| 67 | } |
| 68 | |
| 69 | private function getUpdater(WPFunctions $wp): TranslationUpdater { |
| 70 | $premiumSlug = Installer::PREMIUM_PLUGIN_SLUG; |
| 71 | $premiumVersion = defined('MAILPOET_PREMIUM_VERSION') ? MAILPOET_PREMIUM_VERSION : null; |
| 72 | $freeSlug = Env::$pluginName; |
| 73 | $freeVersion = MAILPOET_VERSION; |
| 74 | |
| 75 | return new TranslationUpdater( |
| 76 | $wp, |
| 77 | $freeSlug, |
| 78 | $freeVersion, |
| 79 | $premiumSlug, |
| 80 | $premiumVersion |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 |