Skip to content
Permalink
Browse files

implements #337 by enabling privacy strings translation

implements #337 by adding woocommerce privacy strings to the Polylang
strings translation table
  • Loading branch information...
Jon007 committed May 19, 2018
1 parent b32ee97 commit d9592822d4041ce299c04576e0a5d2bb1de4d646
Showing with 65 additions and 0 deletions.
  1. +1 −0 src/Hyyan/WPI/Plugin.php
  2. +64 −0 src/Hyyan/WPI/Privacy.php
@@ -189,6 +189,7 @@ protected function registerCore()
new Taxonomies\Taxonomies();
new Media();
new Permalinks();
new Privacy();
new Language();
new Coupon();
new Reports();
@@ -0,0 +1,64 @@
<?php
/**
* This file is part of the hyyan/woo-poly-integration plugin.
* (c) Hyyan Abo Fakher <hyyanaf@gmail.com>.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Hyyan\WPI;
/**
* Privacy.
*
*/
class Privacy
{
/**
* Construct initiated on init by Plugin.php
*/
public function __construct()
{
$this->registerPrivacyStrings();
add_filter('woocommerce_get_privacy_policy_text', array($this, 'translatePrivacyPolicyText'), 10, 2);
}
/**
* Register woocommerce privacy policy messages in polylang strings
* translations table.
*/
public function registerPrivacyStrings()
{
$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]')));
$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]')));
}
/**
* Register setting and value in polylang strings translations table.
*
* @param string $setting Name of setting/string to translate
* @param string $value Value in base language
*/
private function registerString($setting, $value)
{
if (function_exists('pll_register_string')) {
pll_register_string($setting, $value, __('WooCommerce Privacy', 'woo-poly-integration'), true);
}
}
/**
* Register setting and value in polylang strings translations table.
*
* @param string $text Text to be translated
* @param string $type Name of privacy policy type 'checkout' or ‘registration’
*/
public function translatePrivacyPolicyText($text, $type)
{
if (function_exists('pll_register_string')) {
$trans = pll__($text);
return ($trans) ? $trans : $text;
}
}
}

0 comments on commit d959282

Please sign in to comment.
You can’t perform that action at this time.