Finished migration to use gettext (this now closes #161)

This commit is contained in:
Bernd Bestel
2019-05-02 20:20:18 +02:00
parent 5d3f248d94
commit 4912dd56d1
75 changed files with 2275 additions and 1581 deletions

View File

@@ -26,7 +26,7 @@ class CalendarService extends BaseService
public function GetEvents()
{
$products = $this->Database->products();
$titlePrefix = $this->LocalizationService-Translator->__t('Product expires') . ': ';
$titlePrefix = $this->LocalizationService->__t('Product expires') . ': ';
$stockEvents = array();
foreach($this->StockService->GetCurrentStock() as $currentStockEntry)
{
@@ -40,7 +40,7 @@ class CalendarService extends BaseService
}
}
$titlePrefix = $this->LocalizationService-Translator->__t('Task due') . ': ';
$titlePrefix = $this->LocalizationService->__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-Translator->__t('Chore due') . ': ';
$titlePrefix = $this->LocalizationService->__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-Translator->__t('Battery charge cycle due') . ': ';
$titlePrefix = $this->LocalizationService->__t('Battery charge cycle due') . ': ';
$batteryEvents = array();
foreach($this->BatteriesService->GetCurrent() as $currentBatteryEntry)
{

View File

@@ -6,10 +6,16 @@ use \Grocy\Services\LocalizationService;
class DemoDataGeneratorService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->LocalizationService = new LocalizationService(GROCY_CULTURE);
}
protected $LocalizationService;
public function PopulateDemoData()
{
$localizationService = new LocalizationService(GROCY_CULTURE);
$rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = -1')->fetchColumn();
if (intval($rowCount) === 0)
{
@@ -17,74 +23,74 @@ class DemoDataGeneratorService extends BaseService
$loremIpsumWithHtmlFormattings = "<h1>Lorem ipsum</h1><p>Lorem ipsum <b>dolor sit</b> amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur <span style=\"background-color: rgb(255, 255, 0);\">sadipscing elitr</span>, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p><ul><li>At vero eos et accusam et justo duo dolores et ea rebum.</li><li>Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li></ul><h1>Lorem ipsum</h1><p>Lorem ipsum <b>dolor sit</b> amet, consetetur \r\nsadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et \r\ndolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et\r\n justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea \r\ntakimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit \r\namet, consetetur <span style=\"background-color: rgb(255, 255, 0);\">sadipscing elitr</span>,\r\n sed diam nonumy eirmod tempor invidunt ut labore et dolore magna \r\naliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo \r\ndolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus \r\nest Lorem ipsum dolor sit amet.</p>";
$sql = "
UPDATE users SET username = '{$localizationService->LocalizeForSqlString('Demo User')}' WHERE id = 1;
INSERT INTO users (username, password) VALUES ('{$localizationService->LocalizeForSqlString('Demo User')} 2', 'x');
INSERT INTO users (username, password) VALUES ('{$localizationService->LocalizeForSqlString('Demo User')} 3', 'x');
INSERT INTO users (username, password) VALUES ('{$localizationService->LocalizeForSqlString('Demo User')} 4', 'x');
UPDATE users SET username = '{$this->__t_sql('Demo User')}' WHERE id = 1;
INSERT INTO users (username, password) VALUES ('{$this->__t_sql('Demo User')} 2', 'x');
INSERT INTO users (username, password) VALUES ('{$this->__t_sql('Demo User')} 3', 'x');
INSERT INTO users (username, password) VALUES ('{$this->__t_sql('Demo User')} 4', 'x');
INSERT INTO locations (name) VALUES ('{$localizationService->LocalizeForSqlString('Pantry')}'); --3
INSERT INTO locations (name) VALUES ('{$localizationService->LocalizeForSqlString('Candy cupboard')}'); --4
INSERT INTO locations (name) VALUES ('{$localizationService->LocalizeForSqlString('Tinned food cupboard')}'); --5
INSERT INTO locations (name) VALUES ('{$this->__t_sql('Pantry')}'); --3
INSERT INTO locations (name) VALUES ('{$this->__t_sql('Candy cupboard')}'); --4
INSERT INTO locations (name) VALUES ('{$this->__t_sql('Tinned food cupboard')}'); --5
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Glass')}', '{$localizationService->LocalizeForSqlString('Glasses')}'); --4
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Tin')}', '{$localizationService->LocalizeForSqlString('Tins')}'); --5
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Can')}', '{$localizationService->LocalizeForSqlString('Cans')}'); --6
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Bunch')}', '{$localizationService->LocalizeForSqlString('Bunches')}'); --7
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Gram')}', '{$localizationService->LocalizeForSqlString('Grams')}'); --8
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Liter')}', '{$localizationService->LocalizeForSqlString('Liters')}'); --9
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Bottle')}', '{$localizationService->LocalizeForSqlString('Bottles')}'); --10
INSERT INTO quantity_units (name, name_plural) VALUES ('{$localizationService->LocalizeForSqlString('Milliliter')}', '{$localizationService->LocalizeForSqlString('Milliliters')}'); --11
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Glass', 'Glasses')}', '{$this->__n_sql(2, 'Glass', 'Glasses')}'); --4
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Tin', 'Tins')}', '{$this->__n_sql(2, 'Tin', 'Tins')}'); --5
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Can', 'Cans')}', '{$this->__n_sql(2, 'Can', 'Cans')}'); --6
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Bunch', 'Bunches')}', '{$this->__n_sql(2, 'Bunch', 'Bunches')}'); --7
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Gram', 'Grams')}', '{$this->__n_sql(2, 'Gram', 'Grams')}'); --8
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Liter', 'Liters')}', '{$this->__n_sql(2, 'Liter', 'Liters')}'); --9
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Bottle', 'Bottles')}', '{$this->__n_sql(2, 'Bottle', 'Bottles')}'); --10
INSERT INTO quantity_units (name, name_plural) VALUES ('{$this->__n_sql(1, 'Milliliter', 'Milliliters')}', '{$this->__n_sql(2, 'Milliliter', 'Milliliters')}'); --11
INSERT INTO product_groups(name) VALUES ('01 {$localizationService->LocalizeForSqlString('Sweets')}'); --1
INSERT INTO product_groups(name) VALUES ('02 {$localizationService->LocalizeForSqlString('Bakery products')}'); --2
INSERT INTO product_groups(name) VALUES ('03 {$localizationService->LocalizeForSqlString('Tinned food')}'); --3
INSERT INTO product_groups(name) VALUES ('04 {$localizationService->LocalizeForSqlString('Butchery products')}'); --4
INSERT INTO product_groups(name) VALUES ('05 {$localizationService->LocalizeForSqlString('Vegetables/Fruits')}'); --5
INSERT INTO product_groups(name) VALUES ('06 {$localizationService->LocalizeForSqlString('Refrigerated products')}'); --6
INSERT INTO product_groups(name) VALUES ('01 {$this->__t_sql('Sweets')}'); --1
INSERT INTO product_groups(name) VALUES ('02 {$this->__t_sql('Bakery products')}'); --2
INSERT INTO product_groups(name) VALUES ('03 {$this->__t_sql('Tinned food')}'); --3
INSERT INTO product_groups(name) VALUES ('04 {$this->__t_sql('Butchery products')}'); --4
INSERT INTO product_groups(name) VALUES ('05 {$this->__t_sql('Vegetables/Fruits')}'); --5
INSERT INTO product_groups(name) VALUES ('06 {$this->__t_sql('Refrigerated products')}'); --6
DELETE FROM sqlite_sequence WHERE name = 'products'; --Just to keep IDs in order as mentioned here...
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Cookies')}', 4, 3, 3, 1, 8, 1, 'cookies.jpg'); --1
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Chocolate')}', 4, 3, 3, 1, 8, 1); --2
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Gummy bears')}', 4, 3, 3, 1, 8, 1, 'gummybears.jpg'); --3
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Crisps')}', 4, 3, 3, 1, 10, 1); --4
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Eggs')}', 2, 3, 2, 10, 5); --5
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Noodles')}', 3, 3, 3, 1, 6); --6
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Pickles')}', 5, 4, 4, 1, 3); --7
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Gulash soup')}', 5, 5, 5, 1, 3); --8
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Yogurt')}', 2, 6, 6, 1, 6); --9
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Cheese')}', 2, 3, 3, 1, 6); --10
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, description) VALUES ('{$localizationService->LocalizeForSqlString('Cold cuts')}', 2, 3, 3, 1, 6, '{$loremIpsum}'); --11
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->LocalizeForSqlString('Paprika')}', 2, 2, 2, 1, 5, 'paprika.jpg', 7); --12
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->LocalizeForSqlString('Cucumber')}', 2, 2, 2, 1, 5, 'cucumber.jpg', 7); --13
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, default_best_before_days) VALUES ('{$localizationService->LocalizeForSqlString('Radish')}', 2, 7, 7, 1, 5, 7); --14
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->LocalizeForSqlString('Tomato')}', 2, 2, 2, 1, 5, 'tomato.jpg', 7); --15
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Pizza dough')}', 2, 3, 3, 1, 6); --16
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Sieved tomatoes')}', 5, 5, 5, 1, 3); --17
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Salami')}', 2, 3, 3, 1, 6); --18
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Toast')}', 3, 5, 5, 1, 2); --19
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Minced meat')}', 2, 3, 3, 1, 4); --20
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, enable_tare_weight_handling, tare_weight) VALUES ('{$localizationService->LocalizeForSqlString('Flour')}', 3, 8, 8, 1, 3, 1, 500); --21
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Sugar')}', 3, 3, 3, 1, 3); --22
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->LocalizeForSqlString('Milk')}', 2, 10, 10, 1, 6); --23
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$this->__t_sql('Cookies')}', 4, 3, 3, 1, 8, 1, 'cookies.jpg'); --1
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$this->__t_sql('Chocolate')}', 4, 3, 3, 1, 8, 1); --2
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$this->__t_sql('Gummy bears')}', 4, 3, 3, 1, 8, 1, 'gummybears.jpg'); --3
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$this->__t_sql('Crisps')}', 4, 3, 3, 1, 10, 1); --4
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Eggs')}', 2, 3, 2, 10, 5); --5
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Noodles')}', 3, 3, 3, 1, 6); --6
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Pickles')}', 5, 4, 4, 1, 3); --7
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Gulash soup')}', 5, 5, 5, 1, 3); --8
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Yogurt')}', 2, 6, 6, 1, 6); --9
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Cheese')}', 2, 3, 3, 1, 6); --10
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, description) VALUES ('{$this->__t_sql('Cold cuts')}', 2, 3, 3, 1, 6, '{$loremIpsum}'); --11
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$this->__t_sql('Paprika')}', 2, 2, 2, 1, 5, 'paprika.jpg', 7); --12
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$this->__t_sql('Cucumber')}', 2, 2, 2, 1, 5, 'cucumber.jpg', 7); --13
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, default_best_before_days) VALUES ('{$this->__t_sql('Radish')}', 2, 7, 7, 1, 5, 7); --14
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$this->__t_sql('Tomato')}', 2, 2, 2, 1, 5, 'tomato.jpg', 7); --15
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Pizza dough')}', 2, 3, 3, 1, 6); --16
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Sieved tomatoes')}', 5, 5, 5, 1, 3); --17
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Salami')}', 2, 3, 3, 1, 6); --18
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Toast')}', 3, 5, 5, 1, 2); --19
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Minced meat')}', 2, 3, 3, 1, 4); --20
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, enable_tare_weight_handling, tare_weight) VALUES ('{$this->__t_sql('Flour')}', 3, 8, 8, 1, 3, 1, 500); --21
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Sugar')}', 3, 3, 3, 1, 3); --22
INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$this->__t_sql('Milk')}', 2, 10, 10, 1, 6); --23
INSERT INTO shopping_list (note, amount) VALUES ('{$localizationService->LocalizeForSqlString('Some good snacks')}', 1);
INSERT INTO shopping_list (note, amount) VALUES ('{$this->__t_sql('Some good snacks')}', 1);
INSERT INTO shopping_list (product_id, amount) VALUES (20, 1);
INSERT INTO shopping_list (product_id, amount) VALUES (17, 1);
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pizza')}', '{$loremIpsumWithHtmlFormattings}', 'pizza.jpg'); --1
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Spaghetti bolognese')}', '{$loremIpsumWithHtmlFormattings}', 'spaghetti.jpg'); --2
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Sandwiches')}', '{$loremIpsumWithHtmlFormattings}', 'sandwiches.jpg'); --3
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes.jpg'); --4
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'chocolate_sauce.jpg'); --5
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')} / {$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes_chocolate_sauce.jpg'); --6
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Pizza')}', '{$loremIpsumWithHtmlFormattings}', 'pizza.jpg'); --1
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Spaghetti bolognese')}', '{$loremIpsumWithHtmlFormattings}', 'spaghetti.jpg'); --2
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Sandwiches')}', '{$loremIpsumWithHtmlFormattings}', 'sandwiches.jpg'); --3
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Pancakes')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes.jpg'); --4
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'chocolate_sauce.jpg'); --5
INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$this->__t_sql('Pancakes')} / {$this->__t_sql('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes_chocolate_sauce.jpg'); --6
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 16, 1, '{$localizationService->LocalizeForSqlString('Bottom')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 17, 1, '{$localizationService->LocalizeForSqlString('Topping')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, note, ingredient_group) VALUES (1, 18, 1, '{$localizationService->LocalizeForSqlString('This is the note content of the recipe ingredient')}', '{$localizationService->LocalizeForSqlString('Topping')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 10, 1, '{$localizationService->LocalizeForSqlString('Bottom')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 16, 1, '{$this->__t_sql('Bottom')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 17, 1, '{$this->__t_sql('Topping')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, note, ingredient_group) VALUES (1, 18, 1, '{$this->__t_sql('This is the note content of the recipe ingredient')}', '{$this->__t_sql('Topping')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 10, 1, '{$this->__t_sql('Bottom')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount) VALUES (2, 6, 1);
INSERT INTO recipes_pos (recipe_id, product_id, amount) VALUES (2, 10, 1);
INSERT INTO recipes_pos (recipe_id, product_id, amount, note) VALUES (2, 17, 1, '{$localizationService->LocalizeForSqlString('This is the note content of the recipe ingredient')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount, note) VALUES (2, 17, 1, '{$this->__t_sql('This is the note content of the recipe ingredient')}');
INSERT INTO recipes_pos (recipe_id, product_id, amount) VALUES (2, 20, 1);
INSERT INTO recipes_pos (recipe_id, product_id, amount) VALUES (3, 10, 1);
INSERT INTO recipes_pos (recipe_id, product_id, amount) VALUES (3, 11, 1);
@@ -97,31 +103,31 @@ class DemoDataGeneratorService extends BaseService
INSERt INTO recipes_nestings(recipe_id, includes_recipe_id) VALUES (6, 4);
INSERt INTO recipes_nestings(recipe_id, includes_recipe_id) VALUES (6, 5);
INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Changed towels in the bathroom')}', 'manually', 5); --1
INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Cleaned the kitchen floor')}', 'dynamic-regular', 7); --2
INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Lawn mowed in the garden')}', 'dynamic-regular', 21); --3
INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens on the 5th of every month')}', 'monthly', 5); --4
INSERT INTO chores (name, period_type) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens daily')}', 'daily'); --5
INSERT INTO chores (name, period_type, period_config) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens on Mondays and Wednesdays')}', 'weekly', 'monday,wednesday'); --6
INSERT INTO chores (name, period_type, period_days) VALUES ('{$this->__t_sql('Changed towels in the bathroom')}', 'manually', 5); --1
INSERT INTO chores (name, period_type, period_days) VALUES ('{$this->__t_sql('Cleaned the kitchen floor')}', 'dynamic-regular', 7); --2
INSERT INTO chores (name, period_type, period_days) VALUES ('{$this->__t_sql('Lawn mowed in the garden')}', 'dynamic-regular', 21); --3
INSERT INTO chores (name, period_type, period_days) VALUES ('{$this->__t_sql('The thing which happens on the 5th of every month')}', 'monthly', 5); --4
INSERT INTO chores (name, period_type) VALUES ('{$this->__t_sql('The thing which happens daily')}', 'daily'); --5
INSERT INTO chores (name, period_type, period_config) VALUES ('{$this->__t_sql('The thing which happens on Mondays and Wednesdays')}', 'weekly', 'monday,wednesday'); --6
INSERT INTO batteries (name, description, used_in) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}1', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2023', '{$localizationService->LocalizeForSqlString('TV remote control')}'); --1
INSERT INTO batteries (name, description, used_in) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}2', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2022', '{$localizationService->LocalizeForSqlString('Alarm clock')}'); --2
INSERT INTO batteries (name, description, used_in, charge_interval_days) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}3', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2022', '{$localizationService->LocalizeForSqlString('Heat remote control')}', 60); --3
INSERT INTO batteries (name, description, used_in, charge_interval_days) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}4', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2028', '{$localizationService->LocalizeForSqlString('Heat remote control')}', 60); --4
INSERT INTO batteries (name, description, used_in) VALUES ('{$this->__t_sql('Battery')}1', '{$this->__t_sql('Warranty ends')} 2023', '{$this->__t_sql('TV remote control')}'); --1
INSERT INTO batteries (name, description, used_in) VALUES ('{$this->__t_sql('Battery')}2', '{$this->__t_sql('Warranty ends')} 2022', '{$this->__t_sql('Alarm clock')}'); --2
INSERT INTO batteries (name, description, used_in, charge_interval_days) VALUES ('{$this->__t_sql('Battery')}3', '{$this->__t_sql('Warranty ends')} 2022', '{$this->__t_sql('Heat remote control')}', 60); --3
INSERT INTO batteries (name, description, used_in, charge_interval_days) VALUES ('{$this->__t_sql('Battery')}4', '{$this->__t_sql('Warranty ends')} 2028', '{$this->__t_sql('Heat remote control')}', 60); --4
INSERT INTO task_categories (name) VALUES ('{$localizationService->LocalizeForSqlString('Home')}'); --1
INSERT INTO task_categories (name) VALUES ('{$localizationService->LocalizeForSqlString('Life')}'); --2
INSERT INTO task_categories (name) VALUES ('{$localizationService->LocalizeForSqlString('Projects')}'); --3
INSERT INTO task_categories (name) VALUES ('{$this->__t_sql('Home')}'); --1
INSERT INTO task_categories (name) VALUES ('{$this->__t_sql('Life')}'); --2
INSERT INTO task_categories (name) VALUES ('{$this->__t_sql('Projects')}'); --3
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Repair the garage door')}', 1, date(datetime('now', 'localtime'), '+14 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Fork and improve grocy')}', 3, date(datetime('now', 'localtime'), '+30 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Task')}1', 2, date(datetime('now', 'localtime'), '-1 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Task')}2', 2, date(datetime('now', 'localtime'), '-1 day'), 1);
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Find a solution for what to do when I forget the door keys')}', date(datetime('now', 'localtime'), '+3 day'), 1);
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->LocalizeForSqlString('Task')}3', date(datetime('now', 'localtime'), '+4 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Repair the garage door')}', 1, date(datetime('now', 'localtime'), '+14 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Fork and improve grocy')}', 3, date(datetime('now', 'localtime'), '+30 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Task')}1', 2, date(datetime('now', 'localtime'), '-1 day'), 1);
INSERT INTO tasks (name, category_id, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Task')}2', 2, date(datetime('now', 'localtime'), '-1 day'), 1);
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Find a solution for what to do when I forget the door keys')}', date(datetime('now', 'localtime'), '+3 day'), 1);
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$this->__t_sql('Task')}3', date(datetime('now', 'localtime'), '+4 day'), 1);
INSERT INTO equipment (name, description, instruction_manual_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Coffee machine')}', '{$loremIpsumWithHtmlFormattings}', 'loremipsum.pdf'); --1
INSERT INTO equipment (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Dishwasher')}', '{$loremIpsumWithHtmlFormattings}'); --2
INSERT INTO equipment (name, description, instruction_manual_file_name) VALUES ('{$this->__t_sql('Coffee machine')}', '{$loremIpsumWithHtmlFormattings}', 'loremipsum.pdf'); --1
INSERT INTO equipment (name, description) VALUES ('{$this->__t_sql('Dishwasher')}', '{$loremIpsumWithHtmlFormattings}'); --2
INSERT INTO migrations (migration) VALUES (-1);
";
@@ -262,4 +268,16 @@ class DemoDataGeneratorService extends BaseService
{
return mt_rand(2 * 100, 25 * 100) / 100;
}
private function __t_sql(string $text)
{
$localizedText = $this->LocalizationService->__t($text, null);
return str_replace("'", "''", $localizedText);
}
private function __n_sql($number, string $singularForm, string $pluralForm)
{
$localizedText = $this->LocalizationService->__n($number, $singularForm, $pluralForm);
return str_replace("'", "''", $localizedText);
}
}

View File

@@ -2,58 +2,137 @@
namespace Grocy\Services;
use Gettext\Translations;
use Gettext\Translator;
use \Grocy\Services\DatabaseService;
use \Gettext\Translation;
use \Gettext\Translations;
use \Gettext\Translator;
class LocalizationService
{
public function __construct(string $culture)
{
$this->Culture = $culture;
$this->DatabaseService = new DatabaseService();
$this->Database = $this->DatabaseService->GetDbConnection();
$this->LoadLocalizations($culture);
}
protected $PotTranslation;
protected $PoTranslation;
public $Translator;
protected $DatabaseService;
protected $Database;
protected $Pot;
protected $PotMain;
protected $Po;
protected $PoUserStrings;
protected $Translator;
private function LoadLocalizations()
{
$culture = $this->Culture;
$this->PotTranslation = Translations::fromPoFile(__DIR__ . '/../localization/chore_types.pot');
$this->PotTranslation = $this->PotTranslation->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/component_translations.pot'));
$this->PotTranslation = $this->PotTranslation->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/demo_data.pot'));
$this->PotTranslation = $this->PotTranslation->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/stock_transaction_types.pot'));
$this->PotTranslation = $this->PotTranslation->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/strings.pot'));
$this->PotTranslation = $this->PotTranslation->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/userfield_types.pot'));
if (GROCY_MODE === 'dev')
{
$this->PotMain = Translations::fromPoFile(__DIR__ . '/../localization/strings.pot');
$this->PoTranslation = Translations::fromPoFile(__DIR__ . "/../localization/$culture/chore_types.po");
$this->PoTranslation = $this->PoTranslation->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/component_translations.po"));
$this->PoTranslation = $this->PoTranslation->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/demo_data.po"));
$this->PoTranslation = $this->PoTranslation->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/stock_transaction_types.po"));
$this->PoTranslation = $this->PoTranslation->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/strings.po"));
$this->PoTranslation = $this->PoTranslation->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/userfield_types.po"));
$this->Pot = Translations::fromPoFile(__DIR__ . '/../localization/chore_types.pot');
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/component_translations.pot'));
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/demo_data.pot'));
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/stock_transaction_types.pot'));
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/strings.pot'));
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/userfield_types.pot'));
}
$this->PoUserStrings = new Translations();
$this->PoUserStrings->setDomain('grocy/userstrings');
$this->Po = Translations::fromPoFile(__DIR__ . "/../localization/$culture/chore_types.po");
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/component_translations.po"));
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/demo_data.po"));
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/stock_transaction_types.po"));
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/strings.po"));
$this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/userfield_types.po"));
$quantityUnits = null;
try
{
$quantityUnits = $this->Database->quantity_units()->fetchAll();
}
catch (\Exception $ex)
{
// Happens when database is not initialised or migrated...
}
if ($quantityUnits !== null)
{
foreach ($quantityUnits as $quantityUnit)
{
$translation = new Translation('', $quantityUnit['name']);
$translation->setTranslation($quantityUnit['name']);
$translation->setPlural($quantityUnit['name_plural']);
$translation->setPluralTranslations(preg_split('/\r\n|\r|\n/', $quantityUnit['plural_forms']));
$this->PoUserStrings[] = $translation;
}
$this->Po = $this->Po->mergeWith($this->PoUserStrings);
}
$this->Translator = new Translator();
$this->Translator->loadTranslations($this->PoTranslation);
$this->Translator->register();
$this->Translator->loadTranslations($this->Po);
}
public function GetTranslationsForJavaScriptTranslator()
public function GetPoAsJsonString()
{
return $this->PoTranslation->toJsonString();
return $this->Po->toJsonString();
}
//TODO: Missing translations should be automatically added to the source POT file
public function GetPluralCount()
{
if ($this->Po->getHeader(Translations::HEADER_PLURAL) !== null)
{
return $this->Po->getPluralForms()[0];
}
else
{
return 2;
}
}
public function GetPluralDefinition()
{
if ($this->Po->getHeader(Translations::HEADER_PLURAL) !== null)
{
return $this->Po->getPluralForms()[1];
}
else
{
return '(n != 1)';
}
}
public function __t(string $text, ...$placeholderValues)
{
return __($text, ...$placeholderValues);
$this->CheckAndAddMissingTranslationToPot($text);
return vsprintf($this->Translator->gettext($text), ...$placeholderValues);
}
public function __n($number, $singularForm, $pluralForm)
public function __n($number, string $singularForm, string $pluralForm)
{
$this->CheckAndAddMissingTranslationToPot($singularForm);
return $this->Translator->ngettext($singularForm, $pluralForm, $number);
}
public function CheckAndAddMissingTranslationToPot(string $text)
{
if (GROCY_MODE === 'dev')
{
if ($this->Pot->find('', $text) === false && $this->PoUserStrings->find('', $text) === false)
{
$translation = new Translation('', $text);
$this->PotMain[] = $translation;
$this->PotMain->toPoFile(__DIR__ . '/../localization/strings.pot');
}
}
}
}

View File

@@ -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-Translator->__t('Added for recipe %s', $recipe->name)
'note' => $this->LocalizationService->__t('Added for recipe %s', $recipe->name)
));
$shoppinglistRow->save();
}