updated template tranlastions method for translation in other thank context language

This commit is contained in:
Shreesh Arora
2023-01-19 18:49:16 +05:30
parent e904b733b5
commit a25bbb6587
14 changed files with 75 additions and 90 deletions

View File

@@ -126,7 +126,7 @@ class TranslateCore
* @param string $source
* @return string
*/
public static function getModuleTranslation($module, $string, $source, $sprintf = null, $js = false)
public static function getModuleTranslation($module, $string, $source, $sprintf = null, $js = false, $language = null)
{
global $_MODULES, $_MODULE, $_LANGADM;
@@ -135,11 +135,18 @@ class TranslateCore
// $translations_merged is a cache of wether a specific module's translations have already been added to $_MODULES
static $translations_merged = array();
// inialize $force_refresh as false and use only when $lang is provided to load new language translations
$force_refresh = false;
$name = $module instanceof Module ? $module->name : $module;
$language = Context::getContext()->language;
if (!($language !== null && Validate::isLoadedObject($language))) {
$language = Context::getContext()->language;
} else {
$force_refresh = true;
}
if (!isset($translations_merged[$name]) && isset(Context::getContext()->language)) {
if ((!isset($translations_merged[$name]) && isset(Context::getContext()->language)) || $force_refresh) {
$files_by_priority = array(
// Translations in theme
_PS_THEME_DIR_.'modules/'.$name.'/translations/'.$language->iso_code.'.php',
@@ -149,10 +156,14 @@ class TranslateCore
// PrestaShop 1.4 translations
_PS_MODULE_DIR_.$name.'/'.$language->iso_code.'.php'
);
// if force_refresh is set reverse the list because array_merge will overrite the previous file with new file
if ($force_refresh) {
$files_by_priority = array_reverse($files_by_priority);
}
foreach ($files_by_priority as $file) {
if (file_exists($file)) {
include_once($file);
$_MODULES = !empty($_MODULES) ? $_MODULES + $_MODULE : $_MODULE; //we use "+" instead of array_merge() because array merge erase existing values.
$_MODULES = !empty($_MODULES) ? ($force_refresh ? array_merge($_MODULES, $_MODULE) : $_MODULES + $_MODULE) : $_MODULE; //we use "+" instead of array_merge() when force_refresh is false because array merge erase existing values.
$translations_merged[$name] = true;
}
}
@@ -220,11 +231,15 @@ class TranslateCore
* @param string $string
* @return string
*/
public static function getPdfTranslation($string, $sprintf = null)
public static function getPdfTranslation($string, $sprintf = null, $language = null)
{
global $_LANGPDF;
$iso = Context::getContext()->language->iso_code;
if (!($language !== null && Validate::isLoadedObject($language))) {
$iso = Context::getContext()->language->iso_code;
} else {
$iso = $language->iso_code;
}
if (!Validate::isLangIsoCode($iso)) {
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));

View File

@@ -429,7 +429,7 @@ class OrderHistoryCore extends ObjectModel
if (method_exists($module, 'getExtraMailContent')) {
if (is_array($extra_mail_content = $module->getExtraMailContent(
$result['id_order_state'],
$order->id_lang
$order
))) {
$data = array_merge($data, $extra_mail_content);
}

View File

@@ -40,15 +40,26 @@ function smartyTranslate($params, $smarty)
$addslashes = (isset($params['slashes']) || isset($params['js']));
$sprintf = isset($params['sprintf']) ? $params['sprintf'] : null;
if (!isset($params['lang'])) {
$params['lang'] = null;
} else {
if (!is_object($params['lang'])) {
$params['lang'] = new Language((int)$params['lang']);
}
if (!Validate::isLoadedObject($params['lang'])) {
$params['lang'] = null;
}
}
if ($pdf) {
return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $sprintf), $params);
return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $sprintf, $params['lang']), $params);
}
$filename = ((!isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template)) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath());
// If the template is part of a module
if (!empty($params['mod'])) {
return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], basename($filename, '.tpl'), $sprintf, isset($params['js'])), $params);
return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], basename($filename, '.tpl'), $sprintf, isset($params['js']), $params['lang']), $params);
}
// If the tpl is at the root of the template folder

View File

@@ -24,6 +24,8 @@
* International Registered Trademark & Property of PrestaShop SA
*/
use JetBrains\PhpStorm\Language;
global $smarty;
$smarty->setTemplateDir(_PS_THEME_DIR_);
@@ -55,6 +57,17 @@ function smartyTranslate($params, $smarty)
$params['d'] = null;
}
if (!isset($params['lang'])) {
$params['lang'] = null;
} else {
if (!is_object($params['lang'])) {
$params['lang'] = new Language((int)$params['lang']);
}
if (!Validate::isLoadedObject($params['lang'])) {
$params['lang'] = null;
}
}
if (!is_null($params['d'])) {
if (isset($params['tags'])) {
$backTrace = debug_backtrace();
@@ -102,9 +115,9 @@ function smartyTranslate($params, $smarty)
}
if ($params['mod']) {
return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']), $params);
return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js'], $params['lang']), $params);
} elseif ($params['pdf']) {
return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $params['sprintf']), $params);
return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $params['sprintf'], $params['lang']), $params);
}
if ($_LANG != null && isset($_LANG[$key])) {

View File

@@ -77,20 +77,22 @@ class Bankwire extends PaymentModule
$this->payment_type = OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT;
}
public function getExtraMailContent($id_order_state, $id_lang)
public function getExtraMailContent($id_order_state, $order)
{
if (Configuration::get('PS_OS_AWAITING_PAYMENT') == $id_order_state) {
$this->context->smarty->assign(array(
'bankwire_owner' => Configuration::get('BANK_WIRE_OWNER'),
'bankwire_details' => nl2br(Configuration::get('BANK_WIRE_DETAILS')),
'bankwire_address' => nl2br(Configuration::get('BANK_WIRE_ADDRESS'))
'bankwire_address' => nl2br(Configuration::get('BANK_WIRE_ADDRESS')),
'lang' => new Language($order->id_lang)
));
return array(
'{extra_mail_content_html}' => $this->context->smarty->fetch(
$this->local_path.'mails/'.Language::getIsoById($id_lang).'/mail_template_html.tpl'
$this->local_path.'views/templates/mail/mail_template_html.tpl'
),
'{extra_mail_content_txt}' => $this->context->smarty->fetch(
$this->local_path.'mails/'.Language::getIsoById($id_lang).'/mail_template_text.tpl'
$this->local_path.'views/templates/mail/mail_template_text.tpl'
)
);
}

View File

@@ -24,13 +24,13 @@
<td style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<p style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">
{l s='Here are the bank details for your transfer:' mod='bankwire'}
{l s='Here are the bank details for your transfer:' mod='bankwire' lang=$lang}
</p>
<span style="color:#777">
<span style="color:#333"><strong>{l s='Amount:' mod='bankwire'}</strong></span> {literal}{total_paid}{/literal}<br />
<span style="color:#333"><strong>{l s='Account owner:' mod='bankwire'}</strong></span> {$bankwire_owner}<br />
<span style="color:#333"><strong>{l s='Account details:' mod='bankwire'}</strong></span> {$bankwire_details}<br />
<span style="color:#333"><strong>{l s='Bank address:' mod='bankwire'}</strong></span> {$bankwire_address}
<span style="color:#333"><strong>{l s='Amount:' mod='bankwire' lang=$lang}</strong></span> {literal}{total_paid}{/literal}<br />
<span style="color:#333"><strong>{l s='Account owner:' mod='bankwire' lang=$lang}</strong></span> {$bankwire_owner}<br />
<span style="color:#333"><strong>{l s='Account details:' mod='bankwire' lang=$lang}</strong></span> {$bankwire_details}<br />
<span style="color:#333"><strong>{l s='Bank address:' mod='bankwire' lang=$lang}</strong></span> {$bankwire_address}
</span>
</font>
</td>

View File

@@ -72,20 +72,22 @@ class Cheque extends PaymentModule
$this->payment_type = OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT;
}
public function getExtraMailContent($id_order_state, $id_lang)
public function getExtraMailContent($id_order_state, $order)
{
if (Configuration::get('PS_OS_AWAITING_PAYMENT') == $id_order_state) {
$this->context->smarty->assign(array(
'cheque_name' => Configuration::get('CHEQUE_NAME'),
'cheque_address' => Configuration::get('CHEQUE_ADDRESS'),
'cheque_address_html' => str_replace("\n", '<br />', Configuration::get('CHEQUE_ADDRESS'))
'cheque_address_html' => str_replace("\n", '<br />', Configuration::get('CHEQUE_ADDRESS')),
'lang' => new Language($order->id_lang)
));
return array(
'{extra_mail_content_html}' => $this->context->smarty->fetch(
$this->local_path.'mails/'.Language::getIsoById($id_lang).'/mail_template_html.tpl'
$this->local_path.'views/templates/mail/mail_template_html.tpl'
),
'{extra_mail_content_txt}' => $this->context->smarty->fetch(
$this->local_path.'mails/'.Language::getIsoById($id_lang).'/mail_template_text.tpl'
$this->local_path.'views/templates/mail/mail_template_text.tpl'
)
);
}

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2022 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2022 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2022 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2022 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -24,12 +24,12 @@
<td style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<p style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">
{l s='Here are the bank details for your check:' mod='cheque'}
{l s='Here are the bank details for your check:' mod='cheque' lang=$lang}
</p>
<span style="color:#777">
<span style="color:#333"><strong>{l s='Amount:' mod='cheque'}</strong></span> {literal}{total_paid}{/literal}<br />
<span style="color:#333"><strong>{l s='Payable to the order of:' mod='cheque'}</strong></span> {$cheque_name}<br />
<span style="color:#333"><strong>{l s='Please mail your check to:' mod='cheque'}</strong></span> {$cheque_address_html}
<span style="color:#333"><strong>{l s='Amount:' mod='cheque' lang=$lang}</strong></span> {literal}{total_paid}{/literal}<br />
<span style="color:#333"><strong>{l s='Payable to the order of:' mod='cheque' lang=$lang}</strong></span> {$cheque_name}<br />
<span style="color:#333"><strong>{l s='Please mail your check to:' mod='cheque' lang=$lang}</strong></span> {$cheque_address_html}
</span>
</font>
</td>

View File

@@ -16,8 +16,8 @@
* @copyright 2010-2022 Webkul IN
* @license https://store.webkul.com/license.html
*}
{l s='Here are the bank details for your check:' mod='cheque'}
{l s='Here are the bank details for your check:' mod='cheque' lang=$lang}
{l s='Amount:' mod='cheque'} {literal}{total_paid}{/literal}
{l s='Payable to the order of:' mod='cheque'} {$cheque_name}
{l s='Please mail your check to:' mod='cheque'} {$cheque_address}
{l s='Amount:' mod='cheque' lang=$lang} {literal}{total_paid}{/literal}
{l s='Payable to the order of:' mod='cheque' lang=$lang} {$cheque_name}
{l s='Please mail your check to:' mod='cheque' lang=$lang} {$cheque_address}