mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Split application translation strings and QU strings (fixes #1705)
This commit is contained in:
@@ -17,21 +17,21 @@ class LocalizationService
|
||||
|
||||
protected $Po;
|
||||
|
||||
protected $PoUserStrings;
|
||||
|
||||
protected $Pot;
|
||||
|
||||
protected $PotMain;
|
||||
|
||||
protected $Translator;
|
||||
|
||||
protected $TranslatorQU;
|
||||
|
||||
private static $instanceMap = [];
|
||||
|
||||
public function CheckAndAddMissingTranslationToPot($text)
|
||||
{
|
||||
if (GROCY_MODE === 'dev')
|
||||
{
|
||||
if ($this->Pot->find('', $text) === false && $this->PoUserStrings->find('', $text) === false && empty($text) === false)
|
||||
if ($this->Pot->find('', $text) === false && empty($text) === false)
|
||||
{
|
||||
$translation = new Translation('', $text);
|
||||
$this->PotMain[] = $translation;
|
||||
@@ -69,11 +69,23 @@ class LocalizationService
|
||||
return $this->Po->toJsonString();
|
||||
}
|
||||
|
||||
public function __n($number, $singularForm, $pluralForm)
|
||||
public function GetPoAsJsonStringQu()
|
||||
{
|
||||
return $this->PoQu->toJsonString();
|
||||
}
|
||||
|
||||
public function __n($number, $singularForm, $pluralForm, $isQu = false)
|
||||
{
|
||||
$this->CheckAndAddMissingTranslationToPot($singularForm);
|
||||
|
||||
return sprintf($this->Translator->ngettext($singularForm, $pluralForm, abs(floatval($number))), $number);
|
||||
if ($isQu)
|
||||
{
|
||||
return sprintf($this->TranslatorQU->ngettext($singularForm, $pluralForm, abs(floatval($number))), $number);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf($this->Translator->ngettext($singularForm, $pluralForm, abs(floatval($number))), $number);
|
||||
}
|
||||
}
|
||||
|
||||
public function __t($text, ...$placeholderValues)
|
||||
@@ -140,9 +152,6 @@ class LocalizationService
|
||||
}
|
||||
}
|
||||
|
||||
$this->PoUserStrings = new Translations();
|
||||
$this->PoUserStrings->setDomain('grocy/userstrings');
|
||||
|
||||
$this->Po = Translations::fromPoFile(__DIR__ . "/../localization/$culture/strings.po");
|
||||
|
||||
if (file_exists(__DIR__ . "/../localization/$culture/chore_assignment_types.po"))
|
||||
@@ -185,6 +194,9 @@ class LocalizationService
|
||||
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/demo_data.po"));
|
||||
}
|
||||
|
||||
$this->Translator = new Translator();
|
||||
$this->Translator->loadTranslations($this->Po);
|
||||
|
||||
$quantityUnits = null;
|
||||
try
|
||||
{
|
||||
@@ -197,6 +209,8 @@ class LocalizationService
|
||||
|
||||
if ($quantityUnits !== null)
|
||||
{
|
||||
$this->PoQu = new Translations();
|
||||
|
||||
foreach ($quantityUnits as $quantityUnit)
|
||||
{
|
||||
$translation = new Translation('', $quantityUnit['name']);
|
||||
@@ -204,13 +218,11 @@ class LocalizationService
|
||||
$translation->setPlural($quantityUnit['name_plural']);
|
||||
$translation->setPluralTranslations(preg_split('/\r\n|\r|\n/', $quantityUnit['plural_forms']));
|
||||
|
||||
$this->PoUserStrings[] = $translation;
|
||||
$this->PoQu[] = $translation;
|
||||
}
|
||||
|
||||
$this->Po = $this->Po->mergeWith($this->PoUserStrings);
|
||||
}
|
||||
|
||||
$this->Translator = new Translator();
|
||||
$this->Translator->loadTranslations($this->Po);
|
||||
$this->TranslatorQU = new Translator();
|
||||
$this->TranslatorQU->loadTranslations($this->PoQu);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user