api
4 years ago
base
3 years ago
comp
3 years ago
import
3 years ago
overrides
3 years ago
presets
3 years ago
rest
3 years ago
scanner
3 years ago
settings
3 years ago
view
3 years ago
Activator.php
3 years ago
AdInitiator.php
4 years ago
Assets.php
3 years ago
Cache.php
5 years ago
Clear.php
4 years ago
Core.php
3 years ago
DemoEnvironment.php
5 years ago
IpHandler.php
4 years ago
Localization.php
3 years ago
MyConsent.php
4 years ago
RpmInitiator.php
5 years ago
Stats.php
5 years ago
UserConsent.php
4 years ago
Utils.php
4 years ago
index.php
5 years ago
Localization.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | namespace DevOwl\RealCookieBanner; |
| 4 | |
| 5 | use DevOwl\RealCookieBanner\Vendor\DevOwl\Multilingual\AbstractSyncPlugin; |
| 6 | use DevOwl\RealCookieBanner\Vendor\DevOwl\Multilingual\Sync; |
| 7 | use DevOwl\RealCookieBanner\Vendor\MatthiasWeb\Utils\Localization as UtilsLocalization; |
| 8 | use DevOwl\RealCookieBanner\base\UtilsProvider; |
| 9 | use DevOwl\RealCookieBanner\lite\settings\TcfVendorConfiguration; |
| 10 | use DevOwl\RealCookieBanner\settings\Blocker; |
| 11 | use DevOwl\RealCookieBanner\settings\Cookie; |
| 12 | use DevOwl\RealCookieBanner\settings\CookieGroup; |
| 13 | use DevOwl\RealCookieBanner\view\customize\banner\Legal; |
| 14 | // @codeCoverageIgnoreStart |
| 15 | \defined('ABSPATH') or die('No script kiddies please!'); |
| 16 | // Avoid direct file request |
| 17 | // @codeCoverageIgnoreEnd |
| 18 | /** |
| 19 | * i18n management for backend and frontend. |
| 20 | */ |
| 21 | class Localization { |
| 22 | use UtilsProvider; |
| 23 | use UtilsLocalization; |
| 24 | /** |
| 25 | * Keys of array which should be not translated with `translateArray`. |
| 26 | */ |
| 27 | const COMMON_SKIP_KEYS = ['slug']; |
| 28 | /** |
| 29 | * Get the directory where the languages folder exists. |
| 30 | * |
| 31 | * @param string $type |
| 32 | * @return string[] |
| 33 | */ |
| 34 | protected function getPackageInfo($type) { |
| 35 | if ($type === \DevOwl\RealCookieBanner\Vendor\MatthiasWeb\Utils\Localization::$PACKAGE_INFO_BACKEND) { |
| 36 | return [path_join(RCB_PATH, 'languages'), RCB_TD]; |
| 37 | } else { |
| 38 | return [path_join(RCB_PATH, \DevOwl\RealCookieBanner\Assets::$PUBLIC_JSON_I18N), RCB_TD]; |
| 39 | } |
| 40 | } |
| 41 | /** |
| 42 | * Make our plugin multilingual with the help of `AbstractSyncPlugin` and `Sync`! |
| 43 | * Also have a look at `BannerCustomize`, there are `LanguageDependingOption`'s. |
| 44 | */ |
| 45 | public static function multilingual() { |
| 46 | $compLanguage = \DevOwl\RealCookieBanner\Core::getInstance()->getCompLanguage(); |
| 47 | $sync = new \DevOwl\RealCookieBanner\Vendor\DevOwl\Multilingual\Sync( |
| 48 | \array_merge( |
| 49 | [ |
| 50 | \DevOwl\RealCookieBanner\settings\Cookie::CPT_NAME => |
| 51 | \DevOwl\RealCookieBanner\settings\Cookie::SYNC_OPTIONS, |
| 52 | \DevOwl\RealCookieBanner\settings\Blocker::CPT_NAME => |
| 53 | \DevOwl\RealCookieBanner\settings\Blocker::SYNC_OPTIONS |
| 54 | ], |
| 55 | \DevOwl\RealCookieBanner\Core::getInstance()->isPro() |
| 56 | ? [ |
| 57 | \DevOwl\RealCookieBanner\lite\settings\TcfVendorConfiguration::CPT_NAME => |
| 58 | \DevOwl\RealCookieBanner\lite\settings\TcfVendorConfiguration::SYNC_OPTIONS |
| 59 | ] |
| 60 | : [] |
| 61 | ), |
| 62 | [ |
| 63 | \DevOwl\RealCookieBanner\settings\CookieGroup::TAXONOMY_NAME => |
| 64 | \DevOwl\RealCookieBanner\settings\CookieGroup::SYNC_OPTIONS |
| 65 | ], |
| 66 | $compLanguage |
| 67 | ); |
| 68 | $compLanguage->setSync($sync); |
| 69 | $idsToCurrent = [ |
| 70 | \DevOwl\RealCookieBanner\view\customize\banner\Legal::SETTING_PRIVACY_POLICY, |
| 71 | \DevOwl\RealCookieBanner\view\customize\banner\Legal::SETTING_IMPRINT |
| 72 | ]; |
| 73 | foreach ($idsToCurrent as $id) { |
| 74 | add_filter('DevOwl/Customize/LocalizedValue/' . $id, function ($value) use ($compLanguage) { |
| 75 | return $compLanguage->getCurrentPostId($value, \DevOwl\RealCookieBanner\settings\Cookie::CPT_NAME); |
| 76 | }); |
| 77 | } |
| 78 | // Translate some meta fields when they get copied to the other language |
| 79 | if ($compLanguage instanceof \DevOwl\RealCookieBanner\Vendor\DevOwl\Multilingual\AbstractSyncPlugin) { |
| 80 | foreach ( |
| 81 | [ |
| 82 | \DevOwl\RealCookieBanner\settings\Cookie::META_NAME_PROVIDER, |
| 83 | \DevOwl\RealCookieBanner\settings\Cookie::META_NAME_PROVIDER_PRIVACY_POLICY_URL |
| 84 | ] |
| 85 | as $translateMetaKey |
| 86 | ) { |
| 87 | add_filter('DevOwl/Multilingual/Copy/Meta/post/' . $translateMetaKey, [ |
| 88 | $compLanguage, |
| 89 | 'translateInputAndReturnValue' |
| 90 | ]); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 |