mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-20 21:40:48 +01:00
Ulteriore standardizzazione della gestione lingue
This commit is contained in:
parent
646fc7390a
commit
8c2a3023a4
4
core.php
4
core.php
@ -305,6 +305,10 @@ foreach ($list as $file) {
|
||||
include_once $file;
|
||||
}
|
||||
|
||||
// Inizializzazione traduzioni
|
||||
if (database()->tableExists('zz_settings')) {
|
||||
$available_langs = database()->table('zz_langs')->select('id')->pluck('id')->toArray();
|
||||
App::setAvailableLangs($available_langs);
|
||||
|
||||
App::setLang(setting('Lingua'));
|
||||
}
|
||||
|
@ -42,6 +42,10 @@ class Articolo extends Model
|
||||
|
||||
protected $table = 'mg_articoli';
|
||||
|
||||
protected static $translated_fields = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public static function build($codice, ?Categoria $categoria = null, ?Categoria $sottocategoria = null)
|
||||
{
|
||||
$model = new static();
|
||||
@ -57,6 +61,7 @@ class Articolo extends Model
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Funzione per registrare un movimento del magazzino in relazione all'articolo corrente, modificando di conseguenza la quantità dell'articolo stesso.
|
||||
*
|
||||
@ -377,4 +382,8 @@ class Articolo extends Model
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTranslatedFields(){
|
||||
return self::$translated_fields;
|
||||
}
|
||||
}
|
||||
|
13
src/App.php
13
src/App.php
@ -30,7 +30,8 @@ class App
|
||||
public static $rootdir;
|
||||
public static $baseurl;
|
||||
|
||||
public static $lang;
|
||||
protected static $available_langs = [];
|
||||
protected static $lang;
|
||||
|
||||
/** @var array Identificativo del modulo corrente */
|
||||
protected static $current_module;
|
||||
@ -100,6 +101,16 @@ class App
|
||||
return self::$config;
|
||||
}
|
||||
|
||||
public static function getAvailableLangs()
|
||||
{
|
||||
return self::$available_langs;
|
||||
}
|
||||
|
||||
public static function setAvailableLangs($values)
|
||||
{
|
||||
self::$available_langs = (array)$values;
|
||||
}
|
||||
|
||||
public static function getLang()
|
||||
{
|
||||
return self::$lang;
|
||||
|
@ -66,4 +66,49 @@ trait RecordTrait
|
||||
|
||||
return collect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Estensione del salvataggio oggetto per popolare le lingue aggiuntive
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->id) {
|
||||
// Lingue aggiuntive disponibili
|
||||
$langs = \App::getAvailableLangs();
|
||||
$other_langs = array_diff($langs, [\App::getLang()]);
|
||||
|
||||
// Popolo inizialmente i campi traducibili o allineo quelli uguali
|
||||
foreach ($this->getTranslatedFields() as $field) {
|
||||
foreach ($other_langs as $id_lang) {
|
||||
$translation = database()->table($this->table.'_lang')
|
||||
->select($field)
|
||||
->where('id_record', '=', $this->id)
|
||||
->where('id_lang', '=', $id_lang);
|
||||
|
||||
// Se la traduzione non è presente la creo...
|
||||
if ($translation->count() == 0) {
|
||||
$translation->insert([
|
||||
'id_record' => $this->id,
|
||||
'id_lang' => $id_lang,
|
||||
$field => $this->{$field},
|
||||
]);
|
||||
}
|
||||
|
||||
// ...altrimenti la aggiorno se è uguale (quindi probabilmente non ancora tradotta)
|
||||
/*
|
||||
else{
|
||||
if ($translation->first()->{$field} == $this->{$field}) {
|
||||
$translation->update([
|
||||
$field => $this->{$field},
|
||||
]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::save();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user