Fix translation of units

This commit is contained in:
Laurent Destailleur 2020-12-15 11:39:18 +01:00
parent 2ae1aac5a4
commit a2bd920371
4 changed files with 41 additions and 30 deletions

View File

@ -546,16 +546,17 @@ function show_stats_for_company($product, $socid)
* Return translation label of a unit key.
* Function kept for backward compatibility.
*
* @param string $scale Scale of unit: '0', '-3', '6', ...
* @param string $measuring_style Style of unit: weight, volume,...
* @param int $unit ID of unit (rowid in llx_c_units table)
* @param int $use_short_label 1=Use short label ('g' instead of 'gram'). Short labels are not translated.
* @return string Unit string
* @param string $scale Scale of unit: '0', '-3', '6', ...
* @param string $measuring_style Style of unit: weight, volume,...
* @param int $unit ID of unit (rowid in llx_c_units table)
* @param int $use_short_label 1=Use short label ('g' instead of 'gram'). Short labels are not translated.
* @param Translate $outputlangs Language object
* @return string Unit string
* @see measuringUnitString() formproduct->selectMeasuringUnits()
*/
function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $use_short_label = 0)
function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $use_short_label = 0, $outputlangs = null)
{
return measuringUnitString($unit, $measuring_style, $scale, $use_short_label);
return measuringUnitString($unit, $measuring_style, $scale, $use_short_label, $outputlangs);
}
/**
@ -565,14 +566,19 @@ function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $
* @param string $measuring_style Style of unit: 'weight', 'volume', ..., '' = 'net_measure' for option PRODUCT_ADD_NET_MEASURE
* @param string $scale Scale of unit: '0', '-3', '6', ...
* @param int $use_short_label 1=Use short label ('g' instead of 'gram'). Short labels are not translated.
* @param Translate $outputlangs Language object
* @return string Unit string
* @see formproduct->selectMeasuringUnits()
*/
function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0)
function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0, $outputlangs = null)
{
global $langs, $db;
global $measuring_unit_cache;
if (empty($outputlangs)) {
$outputlangs = $langs;
}
if (empty($measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label]))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
@ -605,7 +611,7 @@ function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_sho
} else {
if (is_array($measuringUnits->records) && count($measuringUnits->records) > 0) {
if ($use_short_label) $labeltoreturn = $measuringUnits->records[key($measuringUnits->records)]->short_label;
else $labeltoreturn = $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
else $labeltoreturn = $outputlangs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
} else {
$labeltoreturn = '';
}

View File

@ -265,7 +265,7 @@ class pdf_standard extends ModelePDFProduct
$tab_height = 130;
$tab_height_newpage = 150;
//
// Label of product
$pdf->SetFont('', 'B', $default_font_size);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
$nexY = $pdf->GetY();
@ -276,29 +276,34 @@ class pdf_standard extends ModelePDFProduct
$nexY += 5;
$outputlangs->load("other");
if ($object->weight)
{
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight), 0, 1);
$texttoshow = $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight);
if (isset($object->weight_units)) $texttoshow .= ' '.measuring_units_string($object->weight_units, 'weight', 0, 0, $outputlangs);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
$nexY = $pdf->GetY();
}
if ($object->weight)
{
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != '' ? $object->length : '?').' x '.($object->width != '' ? $object->width : '?').' x '.($object->height != '' ? $object->height : '?'), 0, 1);
$texttoshow = $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != '' ? $object->length : '?').' x '.($object->width != '' ? $object->width : '?').' x '.($object->height != '' ? $object->height : '?');
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
$nexY = $pdf->GetY();
}
if ($object->surface)
{
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Area").': '.dol_htmlentitiesbr($object->surface), 0, 1);
$texttoshow = $langs->trans("Area").': '.dol_htmlentitiesbr($object->surface);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
$nexY = $pdf->GetY();
}
if ($object->volume)
{
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Volume").': '.dol_htmlentitiesbr($object->volume), 0, 1);
$texttoshow = $langs->trans("Volume").': '.dol_htmlentitiesbr($object->volume);
$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
$nexY = $pdf->GetY();
}
// Affiche notes
// Show notes
// TODO There is no public note on product yet
$notetoshow = empty($object->note_public) ? '' : $object->note_public;
if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))

View File

@ -138,7 +138,7 @@ Right=Right
CalculatedWeight=Calculated weight
CalculatedVolume=Calculated volume
Weight=Weight
WeightUnitton=tonne
WeightUnitton=ton
WeightUnitkg=kg
WeightUnitg=g
WeightUnitmg=mg

View File

@ -280,20 +280,20 @@ class Product extends CommonObject
//! Metric of products
public $weight;
public $weight_units;
public $weight_units; // scale -3, 0, 3, 6
public $length;
public $length_units;
public $length_units; // scale -3, 0, 3, 6
public $width;
public $width_units;
public $width_units; // scale -3, 0, 3, 6
public $height;
public $height_units;
public $height_units; // scale -3, 0, 3, 6
public $surface;
public $surface_units;
public $surface_units; // scale -3, 0, 3, 6
public $volume;
public $volume_units;
public $volume_units; // scale -3, 0, 3, 6
public $net_measure;
public $net_measure_units;
public $net_measure_units; // scale -3, 0, 3, 6
public $accountancy_code_sell;
public $accountancy_code_sell_intra;
@ -5387,19 +5387,19 @@ class Product extends CommonObject
$this->date_modification = $now;
$this->weight = 4;
$this->weight_unit = 1;
$this->weight_units = 3;
$this->length = 5;
$this->length_unit = 1;
$this->length_units = 1;
$this->width = 6;
$this->width_unit = 0;
$this->width_units = 0;
$this->height = null;
$this->height_unit = null;
$this->height_units = null;
$this->surface = 30;
$this->surface_unit = 0;
$this->surface_units = 0;
$this->volume = 300;
$this->volume_unit = 0;
$this->volume_units = 0;
$this->barcode = -1; // Create barcode automatically
}