Partly reverted b856911f0f

Loading localization strings async for the fronted currently doesn't work in all cases...
This commit is contained in:
Bernd Bestel
2021-07-12 21:20:39 +02:00
parent 18e8fc8293
commit 8d2c3ae584
3 changed files with 5 additions and 18 deletions

View File

@@ -129,6 +129,7 @@ class BaseController
$this->View->set('__n', function ($number, $singularForm, $pluralForm) use ($localizationService) { $this->View->set('__n', function ($number, $singularForm, $pluralForm) use ($localizationService) {
return $localizationService->__n($number, $singularForm, $pluralForm); return $localizationService->__n($number, $singularForm, $pluralForm);
}); });
$this->View->set('LocalizationStrings', $localizationService->GetPoAsJsonString());
// TODO: Better handle this generically based on the current language (header in .po file?) // TODO: Better handle this generically based on the current language (header in .po file?)
$dir = 'ltr'; $dir = 'ltr';

View File

@@ -231,28 +231,13 @@ U = function(relativePath)
return Grocy.BaseUrl.replace(/\/$/, '') + relativePath; return Grocy.BaseUrl.replace(/\/$/, '') + relativePath;
} }
Grocy.Translator = new Translator(); // Dummy, real instance is loaded async below Grocy.Translator = new Translator(Grocy.LocalizationStrings);
Grocy.Api.Get("system/localization-strings?v=" + Grocy.Version + "&language=" + Grocy.Culture,
function(response)
{
Grocy.Translator = new Translator(response);
if (Grocy.Mode === "dev")
{
Grocy.LocalizationStrings = response.messages[""];
}
},
function(xhr)
{
console.error(xhr);
}
);
__t = function(text, ...placeholderValues) __t = function(text, ...placeholderValues)
{ {
if (Grocy.Mode === "dev") if (Grocy.Mode === "dev")
{ {
var text2 = text; var text2 = text;
if (Grocy.LocalizationStrings && !Grocy.LocalizationStrings.hasOwnProperty(text2)) if (Grocy.LocalizationStrings && !Grocy.LocalizationStrings.messages[""].hasOwnProperty(text2))
{ {
Grocy.Api.Post('system/log-missing-localization', { "text": text2 }); Grocy.Api.Post('system/log-missing-localization', { "text": text2 });
} }
@@ -265,7 +250,7 @@ __n = function(number, singularForm, pluralForm)
if (Grocy.Mode === "dev") if (Grocy.Mode === "dev")
{ {
var singularForm2 = singularForm; var singularForm2 = singularForm;
if (Grocy.LocalizationStrings && !Grocy.LocalizationStrings.hasOwnProperty(singularForm2)) if (Grocy.LocalizationStrings && !Grocy.LocalizationStrings.messages[""].hasOwnProperty(singularForm2))
{ {
Grocy.Api.Post('system/log-missing-localization', { "text": singularForm2 }); Grocy.Api.Post('system/log-missing-localization', { "text": singularForm2 });
} }

View File

@@ -94,6 +94,7 @@
Grocy.Currency = '{{ GROCY_CURRENCY }}'; Grocy.Currency = '{{ GROCY_CURRENCY }}';
Grocy.CalendarFirstDayOfWeek = '{{ GROCY_CALENDAR_FIRST_DAY_OF_WEEK }}'; Grocy.CalendarFirstDayOfWeek = '{{ GROCY_CALENDAR_FIRST_DAY_OF_WEEK }}';
Grocy.CalendarShowWeekNumbers = {{ BoolToString(GROCY_CALENDAR_SHOW_WEEK_OF_YEAR) }}; Grocy.CalendarShowWeekNumbers = {{ BoolToString(GROCY_CALENDAR_SHOW_WEEK_OF_YEAR) }};
Grocy.LocalizationStrings = {!! $LocalizationStrings !!};
Grocy.FeatureFlags = {!! json_encode($featureFlags) !!}; Grocy.FeatureFlags = {!! json_encode($featureFlags) !!};
Grocy.Webhooks = { Grocy.Webhooks = {
@if(GROCY_FEATURE_FLAG_LABELPRINTER && !GROCY_LABEL_PRINTER_RUN_SERVER) @if(GROCY_FEATURE_FLAG_LABELPRINTER && !GROCY_LABEL_PRINTER_RUN_SERVER)