Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit d959282

Browse files
committed
implements #337 by enabling privacy strings translation
implements #337 by adding woocommerce privacy strings to the Polylang strings translation table
1 parent b32ee97 commit d959282

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/Hyyan/WPI/Plugin.php

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected function registerCore()
189189
new Taxonomies\Taxonomies();
190190
new Media();
191191
new Permalinks();
192+
new Privacy();
192193
new Language();
193194
new Coupon();
194195
new Reports();

src/Hyyan/WPI/Privacy.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* This file is part of the hyyan/woo-poly-integration plugin.
4+
* (c) Hyyan Abo Fakher <[email protected]>.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
namespace Hyyan\WPI;
10+
11+
/**
12+
* Privacy.
13+
*
14+
*/
15+
class Privacy
16+
{
17+
18+
/**
19+
* Construct initiated on init by Plugin.php
20+
*/
21+
public function __construct()
22+
{
23+
$this->registerPrivacyStrings();
24+
add_filter('woocommerce_get_privacy_policy_text', array($this, 'translatePrivacyPolicyText'), 10, 2);
25+
}
26+
27+
/**
28+
* Register woocommerce privacy policy messages in polylang strings
29+
* translations table.
30+
*/
31+
public function registerPrivacyStrings()
32+
{
33+
$this->registerString('woocommerce_checkout_privacy_policy_text', get_option('woocommerce_checkout_privacy_policy_text', sprintf(__('Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our %s.', 'woocommerce'), '[privacy_policy]')));
34+
$this->registerString('woocommerce_registration_privacy_policy_text', get_option('woocommerce_registration_privacy_policy_text', sprintf(__('Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our %s.', 'woocommerce'), '[privacy_policy]')));
35+
}
36+
37+
38+
/**
39+
* Register setting and value in polylang strings translations table.
40+
*
41+
* @param string $setting Name of setting/string to translate
42+
* @param string $value Value in base language
43+
*/
44+
private function registerString($setting, $value)
45+
{
46+
if (function_exists('pll_register_string')) {
47+
pll_register_string($setting, $value, __('WooCommerce Privacy', 'woo-poly-integration'), true);
48+
}
49+
}
50+
51+
/**
52+
* Register setting and value in polylang strings translations table.
53+
*
54+
* @param string $text Text to be translated
55+
* @param string $type Name of privacy policy type 'checkout' or ‘registration’
56+
*/
57+
public function translatePrivacyPolicyText($text, $type)
58+
{
59+
if (function_exists('pll_register_string')) {
60+
$trans = pll__($text);
61+
return ($trans) ? $trans : $text;
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)