diff --git a/composer.json b/composer.json
index 7d7acd65..c694b2d6 100644
--- a/composer.json
+++ b/composer.json
@@ -7,16 +7,14 @@
"php-di/php-di": "^6.0",
"rubellum/slim-blade-view": "^0.1.1",
"morris/lessql": "^1.0",
- "gettext/gettext": "^5.5.4",
+ "gettext/gettext": "^4.8",
"eluceo/ical": "^2.2.0",
"erusev/parsedown": "^1.7",
"gumlet/php-image-resize": "^2.0",
"ezyang/htmlpurifier": "^4.13",
"jucksearm/php-barcode": "^1.0",
"guzzlehttp/guzzle": "^7.0",
- "mike42/escpos-php": "^3.0",
- "gettext/translator": "^1.0",
- "gettext/json": "^1.0"
+ "mike42/escpos-php": "^3.0"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index bddde59e..3b3f5444 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d057a6ab1ad847ba7cb44de95f05a97f",
+ "content-hash": "35840e48e78e30b63f589addfdb50f92",
"packages": [
{
"name": "doctrine/inflector",
@@ -328,28 +328,35 @@
},
{
"name": "gettext/gettext",
- "version": "v5.5.4",
+ "version": "v4.8.4",
"source": {
"type": "git",
"url": "https://github.com/php-gettext/Gettext.git",
- "reference": "77baf40326b4eac0230cd11ee75680969dcbe72a"
+ "reference": "58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-gettext/Gettext/zipball/77baf40326b4eac0230cd11ee75680969dcbe72a",
- "reference": "77baf40326b4eac0230cd11ee75680969dcbe72a",
+ "url": "https://api.github.com/repos/php-gettext/Gettext/zipball/58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1",
+ "reference": "58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1",
"shasum": ""
},
"require": {
"gettext/languages": "^2.3",
- "php": "^7.2|^8.0"
+ "php": ">=5.4.0"
},
"require-dev": {
- "brick/varexporter": "^0.2.1",
- "friendsofphp/php-cs-fixer": "^2.15",
- "oscarotero/php-cs-fixer-config": "^1.0",
- "phpunit/phpunit": "^8.0",
- "squizlabs/php_codesniffer": "^3.0"
+ "illuminate/view": "*",
+ "phpunit/phpunit": "^4.8|^5.7|^6.5",
+ "squizlabs/php_codesniffer": "^3.0",
+ "symfony/yaml": "~2",
+ "twig/extensions": "*",
+ "twig/twig": "^1.31|^2.0"
+ },
+ "suggest": {
+ "illuminate/view": "Is necessary if you want to use the Blade extractor",
+ "symfony/yaml": "Is necessary if you want to use the Yaml extractor/generator",
+ "twig/extensions": "Is necessary if you want to use the Twig extractor",
+ "twig/twig": "Is necessary if you want to use the Twig extractor"
},
"type": "library",
"autoload": {
@@ -370,7 +377,7 @@
}
],
"description": "PHP gettext manager",
- "homepage": "https://github.com/php-gettext/Gettext",
+ "homepage": "https://github.com/oscarotero/Gettext",
"keywords": [
"JS",
"gettext",
@@ -381,68 +388,24 @@
],
"support": {
"email": "oom@oscarotero.com",
- "issues": "https://github.com/php-gettext/Gettext/issues",
- "source": "https://github.com/php-gettext/Gettext/tree/v5.5.4"
+ "issues": "https://github.com/oscarotero/Gettext/issues",
+ "source": "https://github.com/php-gettext/Gettext/tree/v4.8.4"
},
- "time": "2020-12-20T13:37:30+00:00"
- },
- {
- "name": "gettext/json",
- "version": "v1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/php-gettext/Json.git",
- "reference": "13f0d7c8cdd1fe80515d5c40722e18f568225891"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-gettext/Json/zipball/13f0d7c8cdd1fe80515d5c40722e18f568225891",
- "reference": "13f0d7c8cdd1fe80515d5c40722e18f568225891",
- "shasum": ""
- },
- "require": {
- "gettext/gettext": "^5.0.0",
- "php": "^7.2|^8.0"
- },
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^2.15",
- "oscarotero/php-cs-fixer-config": "^1.0",
- "phpunit/phpunit": "^8.0",
- "squizlabs/php_codesniffer": "^3.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Gettext\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
+ "funding": [
{
- "name": "Oscar Otero",
- "email": "oom@oscarotero.com",
- "homepage": "http://oscarotero.com",
- "role": "Developer"
+ "url": "https://paypal.me/oscarotero",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/oscarotero",
+ "type": "github"
+ },
+ {
+ "url": "https://www.patreon.com/misteroom",
+ "type": "patreon"
}
],
- "description": "Json format for gettext",
- "homepage": "https://github.com/php-gettext/Json",
- "keywords": [
- "gettext",
- "i18n",
- "json",
- "loader",
- "translation"
- ],
- "support": {
- "email": "oom@oscarotero.com",
- "issues": "https://github.com/php-gettext/Json/issues",
- "source": "https://github.com/php-gettext/Json/tree/v1.0.1"
- },
- "time": "2021-01-22T17:59:51+00:00"
+ "time": "2021-03-10T19:35:49+00:00"
},
{
"name": "gettext/languages",
@@ -509,66 +472,6 @@
},
"time": "2019-11-13T10:30:21+00:00"
},
- {
- "name": "gettext/translator",
- "version": "v1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/php-gettext/Translator.git",
- "reference": "0a80844789e6a4ffad417d2053bbb56c83b02803"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-gettext/Translator/zipball/0a80844789e6a4ffad417d2053bbb56c83b02803",
- "reference": "0a80844789e6a4ffad417d2053bbb56c83b02803",
- "shasum": ""
- },
- "require": {
- "php": "^7.2|^8.0"
- },
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^2.15",
- "gettext/gettext": "^5.0.0",
- "oscarotero/php-cs-fixer-config": "^1.0",
- "phpunit/phpunit": "^8.0",
- "squizlabs/php_codesniffer": "^3.0"
- },
- "suggest": {
- "gettext/gettext": "Is necessary to load and generate array files used by the translator"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Gettext\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Oscar Otero",
- "email": "oom@oscarotero.com",
- "homepage": "http://oscarotero.com",
- "role": "Developer"
- }
- ],
- "description": "Gettext translator functions",
- "homepage": "https://github.com/php-gettext/Translator",
- "keywords": [
- "gettext",
- "i18n",
- "php",
- "translator"
- ],
- "support": {
- "email": "oom@oscarotero.com",
- "issues": "https://github.com/php-gettext/Translator/issues",
- "source": "https://github.com/php-gettext/Translator/tree/v1.0.1"
- },
- "time": "2020-12-01T18:51:46+00:00"
- },
{
"name": "gumlet/php-image-resize",
"version": "2.0.0",
diff --git a/package.json b/package.json
index f73036d4..e4738510 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
"datatables.net-select": "^1.3.1",
"datatables.net-select-bs4": "^1.3.1",
"fullcalendar": "^3.10.1",
- "gettext-translator": "^3.0.1",
+ "gettext-translator": "2.1.0",
"jquery": "3.5.1",
"jquery-lazy": "^1.7.11",
"jquery-serializejson": "^2.9.0",
diff --git a/public/js/grocy.js b/public/js/grocy.js
index 7eb781b7..9c1a4c7c 100644
--- a/public/js/grocy.js
+++ b/public/js/grocy.js
@@ -231,11 +231,11 @@ U = function(relativePath)
return Grocy.BaseUrl.replace(/\/$/, '') + relativePath;
}
-Grocy.Translator = new window.translator.default(); // Dummy, real instance is loaded async below
+Grocy.Translator = new Translator(); // Dummy, real instance is loaded async below
Grocy.Api.Get("system/localization-strings?v=" + Grocy.Version,
function(response)
{
- Grocy.Translator = new window.translator.default(response);
+ Grocy.Translator = new Translator(response);
},
function(xhr)
{
@@ -250,7 +250,7 @@ __t = function(text, ...placeholderValues)
Grocy.Api.Post('system/log-missing-localization', { "text": text2 });
}
- return Grocy.Translator.gettext(text, ...placeholderValues);
+ return Grocy.Translator.__(text, ...placeholderValues)
}
__n = function(number, singularForm, pluralForm)
{
@@ -260,7 +260,7 @@ __n = function(number, singularForm, pluralForm)
Grocy.Api.Post('system/log-missing-localization', { "text": singularForm2 });
}
- return Grocy.Translator.ngettext(singularForm, pluralForm, number, number);
+ return Grocy.Translator.n__(singularForm, pluralForm, number, number)
}
if (!Grocy.ActiveNav.isEmpty())
diff --git a/services/LocalizationService.php b/services/LocalizationService.php
index 43f3b7b9..1bf1d274 100644
--- a/services/LocalizationService.php
+++ b/services/LocalizationService.php
@@ -2,12 +2,9 @@
namespace Grocy\Services;
-use Gettext\Headers;
use Gettext\Translation;
use Gettext\Translations;
use Gettext\Translator;
-use Gettext\Loader\PoLoader;
-use Gettext\Generator\JsonGenerator;
class LocalizationService
{
@@ -38,9 +35,9 @@ class LocalizationService
public function GetPluralCount()
{
- if ($this->Po->getHeaders()->getPluralForm() !== null)
+ if ($this->Po->getHeader(Translations::HEADER_PLURAL) !== null)
{
- return $this->Po->getHeaders()->getPluralForm()[0];
+ return $this->Po->getPluralForms()[0];
}
else
{
@@ -50,9 +47,9 @@ class LocalizationService
public function GetPluralDefinition()
{
- if ($this->Po->getHeaders()->getPluralForm() !== null)
+ if ($this->Po->getHeader(Translations::HEADER_PLURAL) !== null)
{
- return $this->Po->getHeaders()->getPluralForm()[1];
+ return $this->Po->getPluralForms()[1];
}
else
{
@@ -62,7 +59,7 @@ class LocalizationService
public function GetPoAsJsonString()
{
- return (new JsonGenerator())->generateString($this->Po);
+ return $this->Po->toJsonString();
}
public function __construct(string $culture)
@@ -116,69 +113,69 @@ class LocalizationService
private function LoadLocalizations()
{
$culture = $this->Culture;
- $loader = new PoLoader();
if (GROCY_MODE === 'dev')
{
- $this->PotMain = $loader->loadFile(__DIR__ . '/../localization/strings.pot');
+ $this->PotMain = Translations::fromPoFile(__DIR__ . '/../localization/strings.pot');
- $this->Pot = $loader->loadFile(__DIR__ . '/../localization/chore_period_types.pot');
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/chore_assignment_types.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/component_translations.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/stock_transaction_types.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/strings.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/userfield_types.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/permissions.pot'));
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/locales.pot'));
+ $this->Pot = Translations::fromPoFile(__DIR__ . '/../localization/chore_period_types.pot');
+ $this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/chore_assignment_types.pot'));
+ $this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/component_translations.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->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/permissions.pot'));
+ $this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/locales.pot'));
if (GROCY_MODE !== 'production')
{
- $this->Pot = $this->Pot->mergeWith($loader->loadFile(__DIR__ . '/../localization/demo_data.pot'));
+ $this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/demo_data.pot'));
}
}
- $this->PoUserStrings = Translations::create('grocy');
+ $this->PoUserStrings = new Translations();
+ $this->PoUserStrings->setDomain('grocy/userstrings');
- $this->Po = $loader->loadFile(__DIR__ . "/../localization/$culture/strings.po");
+ $this->Po = Translations::fromPoFile(__DIR__ . "/../localization/$culture/strings.po");
if (file_exists(__DIR__ . "/../localization/$culture/chore_assignment_types.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/chore_assignment_types.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/chore_assignment_types.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/component_translations.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/component_translations.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/component_translations.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/stock_transaction_types.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/stock_transaction_types.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/stock_transaction_types.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/chore_period_types.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/chore_period_types.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/chore_period_types.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/userfield_types.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/userfield_types.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/userfield_types.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/permissions.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/permissions.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/permissions.po"));
}
if (file_exists(__DIR__ . "/../localization/$culture/locales.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/locales.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/locales.po"));
}
if (GROCY_MODE !== 'production' && file_exists(__DIR__ . "/../localization/$culture/demo_data.po"))
{
- $this->Po = $this->Po->mergeWith($loader->loadFile(__DIR__ . "/../localization/$culture/demo_data.po"));
+ $this->Po = $this->Po->mergeWith(Translations::fromPoFile(__DIR__ . "/../localization/$culture/demo_data.po"));
}
$quantityUnits = null;
@@ -195,16 +192,18 @@ class LocalizationService
{
foreach ($quantityUnits as $quantityUnit)
{
- $translation = Translation::create($quantityUnit['name'], $quantityUnit['name'], $quantityUnit['name_plural']);
- $translation->translate($quantityUnit['name']);
- $translation->translatePlural($quantityUnit['name_plural'], ...preg_split('/\r\n|\r|\n/', $quantityUnit['plural_forms']));
+ $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->add($translation);
+ $this->PoUserStrings[] = $translation;
}
$this->Po = $this->Po->mergeWith($this->PoUserStrings);
}
- $this->Translator = Translator::createFromTranslations($this->Po);
+ $this->Translator = new Translator();
+ $this->Translator->loadTranslations($this->Po);
}
}
diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php
index e5d9c7ce..0ee3a4c5 100644
--- a/views/layout/default.blade.php
+++ b/views/layout/default.blade.php
@@ -700,7 +700,7 @@
-
+
@if(!empty($__t('summernote_locale') && $__t('summernote_locale') != 'x'))@endif
diff --git a/yarn.lock b/yarn.lock
index 6f700440..40741098 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1716,10 +1716,12 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
-gettext-translator@^3.0.1:
- version "3.0.1"
- resolved "https://registry.yarnpkg.com/gettext-translator/-/gettext-translator-3.0.1.tgz#6e315a24f2baea56f86a215abb5be0ff2e641baa"
- integrity sha512-rqCbHfglrIL/Siinsylwc2eAbgrSPvGL5Dofo3WPoCQkxljoafDzw0n91TuTGmaYPkrp8S1fIDxOmX5fkpsNeQ==
+gettext-translator@2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/gettext-translator/-/gettext-translator-2.1.0.tgz#946047649b7df4ef00522787bb78792667e4de2f"
+ integrity sha512-RD9HifZKtlRtFScA0VWESzLKQxxRmaRU0IFg6cFZgMP0MMgzfHpWO7MipUyRbMxDFm8adbQqCcFLBV47tjT6Ug==
+ dependencies:
+ sprintf-js "^1.0.3"
gl-mat2@^1.0.1:
version "1.0.1"
@@ -3753,7 +3755,7 @@ split-ca@^1.0.1:
resolved "https://registry.yarnpkg.com/split-ca/-/split-ca-1.0.1.tgz#6c83aff3692fa61256e0cd197e05e9de157691a6"
integrity sha1-bIOv82kvphJW4M0ZfgXp3hV2kaY=
-sprintf-js@^1.1.2:
+sprintf-js@^1.0.3, sprintf-js@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673"
integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==