mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Migrated (hopefully) all translations to PO/Gettext (references #161)
This commit is contained in:
@@ -26,7 +26,7 @@ class CalendarService extends BaseService
|
||||
public function GetEvents()
|
||||
{
|
||||
$products = $this->Database->products();
|
||||
$titlePrefix = $this->LocalizationService->Localize('Product expires') . ': ';
|
||||
$titlePrefix = $this->LocalizationService-Translator->__t('Product expires') . ': ';
|
||||
$stockEvents = array();
|
||||
foreach($this->StockService->GetCurrentStock() as $currentStockEntry)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ class CalendarService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
$titlePrefix = $this->LocalizationService->Localize('Task due') . ': ';
|
||||
$titlePrefix = $this->LocalizationService-Translator->__t('Task due') . ': ';
|
||||
$taskEvents = array();
|
||||
foreach($this->TasksService->GetCurrent() as $currentTaskEntry)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ class CalendarService extends BaseService
|
||||
}
|
||||
|
||||
$chores = $this->Database->chores();
|
||||
$titlePrefix = $this->LocalizationService->Localize('Chore due') . ': ';
|
||||
$titlePrefix = $this->LocalizationService-Translator->__t('Chore due') . ': ';
|
||||
$choreEvents = array();
|
||||
foreach($this->ChoresService->GetCurrent() as $currentChoreEntry)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ class CalendarService extends BaseService
|
||||
}
|
||||
|
||||
$batteries = $this->Database->batteries();
|
||||
$titlePrefix = $this->LocalizationService->Localize('Battery charge cycle due') . ': ';
|
||||
$titlePrefix = $this->LocalizationService-Translator->__t('Battery charge cycle due') . ': ';
|
||||
$batteryEvents = array();
|
||||
foreach($this->BatteriesService->GetCurrent() as $currentBatteryEntry)
|
||||
{
|
||||
|
@@ -9,11 +9,6 @@ class LocalizationService
|
||||
{
|
||||
public function __construct(string $culture)
|
||||
{
|
||||
if (GROCY_MODE === 'dev')
|
||||
{
|
||||
$this->MigrateTranslationsToGettext();
|
||||
}
|
||||
|
||||
$this->Culture = $culture;
|
||||
$this->LoadLocalizations($culture);
|
||||
}
|
||||
@@ -50,6 +45,8 @@ class LocalizationService
|
||||
return $this->PoTranslation->toJsonString();
|
||||
}
|
||||
|
||||
//TODO: Missing translations should be automatically added to the source POT file
|
||||
|
||||
public function __t(string $text, ...$placeholderValues)
|
||||
{
|
||||
return __($text, ...$placeholderValues);
|
||||
@@ -59,64 +56,4 @@ class LocalizationService
|
||||
{
|
||||
return $this->Translator->ngettext($singularForm, $pluralForm, $number);
|
||||
}
|
||||
|
||||
private function MigrateTranslationsToGettext()
|
||||
{
|
||||
foreach (glob(__DIR__ . '/../localization/*', GLOB_ONLYDIR) as $langDir)
|
||||
{
|
||||
$lang = basename($langDir);
|
||||
|
||||
foreach (glob(__DIR__ . "/../localization/$lang/*.php") as $phpArrayFile)
|
||||
{
|
||||
$langStrings = require $phpArrayFile;
|
||||
|
||||
$translations = new \Gettext\Translations();
|
||||
$translations->setDomain('grocy/' . pathinfo($phpArrayFile)['filename']);
|
||||
$translations->setHeader('Last-Translator', 'Translation migration from old PHP array files');
|
||||
$translations->setHeader('Language', $lang);
|
||||
$translations->setHeader('Language-Team', "http://www.transifex.com/grocy/grocy/language/$lang");
|
||||
|
||||
$poFileName = basename($phpArrayFile);
|
||||
$poFileName = str_replace('.php', '.po', $poFileName);
|
||||
$poFilePath = __DIR__ . "/../localization/$lang/$poFileName";
|
||||
if (!file_exists($poFilePath))
|
||||
{
|
||||
$translations->toPoFile($poFilePath);
|
||||
}
|
||||
|
||||
$translations = \Gettext\Translations::fromPoFile($poFilePath);
|
||||
foreach ($langStrings as $langString => $langStringTranslated)
|
||||
{
|
||||
$translation = new \Gettext\Translation('', str_replace('#1', '%s', str_replace('#2', '%s', str_replace('#3', '%s', $langString))));
|
||||
$translation->setTranslation(str_replace('#1', '%s', str_replace('#2', '%s', str_replace('#3', '%s', $langStringTranslated))));
|
||||
$translations[] = $translation;
|
||||
}
|
||||
$translations->toPoFile($poFilePath);
|
||||
|
||||
if ($lang == 'en')
|
||||
{
|
||||
$translations = new \Gettext\Translations();
|
||||
$translations->setDomain('grocy/' . pathinfo($phpArrayFile)['filename']);
|
||||
$translations->setHeader('Last-Translator', 'Translation migration from old PHP array files');
|
||||
$translations->setHeader('Language', $lang);
|
||||
$translations->setHeader('Language-Team', "http://www.transifex.com/grocy/grocy/language/$lang");
|
||||
|
||||
$potFileName = basename($phpArrayFile);
|
||||
$potFileName = str_replace('.php', '.pot', $potFileName);
|
||||
$potFileName = __DIR__ . "/../localization/$potFileName";
|
||||
|
||||
foreach ($langStrings as $langString => $langStringTranslated)
|
||||
{
|
||||
$translation = new \Gettext\Translation('', str_replace('#1', '%s', str_replace('#2', '%s', str_replace('#3', '%s', $langString))));
|
||||
$translations[] = $translation;
|
||||
}
|
||||
|
||||
if (!file_exists($potFileName))
|
||||
{
|
||||
$translations->toPoFile($potFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ class RecipesService extends BaseService
|
||||
$shoppinglistRow = $this->Database->shopping_list()->createRow(array(
|
||||
'product_id' => $recipePosition->product_id,
|
||||
'amount' => $toOrderAmount,
|
||||
'note' => $this->LocalizationService->Localize('Added for recipe #1', $recipe->name)
|
||||
'note' => $this->LocalizationService-Translator->__t('Added for recipe %s', $recipe->name)
|
||||
));
|
||||
$shoppinglistRow->save();
|
||||
}
|
||||
|
Reference in New Issue
Block a user