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

Commit

Permalink
implements #337 by enabling privacy strings translation
Browse files Browse the repository at this point in the history
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 d959282
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Hyyan/WPI/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ protected function registerCore()
new Taxonomies\Taxonomies();
new Media();
new Permalinks();
new Privacy();
new Language();
new Coupon();
new Reports();
Expand Down
64 changes: 64 additions & 0 deletions src/Hyyan/WPI/Privacy.php
Original file line number Diff line number Diff line change
@@ -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.