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