Translations
Parthian opened this issue · 3 comments
Hi @RamezIssac
Enjoying Slick Reporting. Can you help with Translations?
I have English as default and Spanish as option. Some of the labels/buttons translate automatically with the built in django translations.
E.g. Filters becomes Filtros and the Filter button becomes Filtro.
But things like the following don't translate:
Results, Search, Next, Previous, Show XX Entries, Export to CSV, From Date, To Date. There may be others in different types of reports.
My own translated text from models and the normal django translation process work fine.
Hopefully, these just need the _('Results) type approach? Then Django will work its magic.
Also the To Date when in Spanish mode (probably not language specific, just another language) the date format changes.
2024-01-17 16:05:18 'From date' stays like this
17/01/2024 16:05:18 'To date' changes format. Note, this seems a friendlier format. But does open up the possibility of confusion with the crazy USA date formt month/day/year (why did they do that...).
Thanks,
Stuart
Hello @Parthian
As far as i see, all strings in Slick reporting are marked as translatable,
To translate them to your needed language(s), you can add them into your source code - i do that in a dummy function somewhere x = _("export to csv")
, so they appear in my django.po file(s) and so i can continue the translation flow .
For the date thing, can you elaborate a bit ?
Are you refering to DEFAULT_START_DATE_TIME
and DEFAULT_END_DATE_TIME
?
https://django-slick-reporting.readthedocs.io/en/latest/ref/settings.html
Thanks
Hello again Ramez,
Dates in English
Same Report but after setting to Spanish. Note the "From Date" and "To Date" haven't been translated. And the different date format. It looks like Argentina (country the site is for) uses the same date as UK ie DMY. So it is only a consistency thing
My settings.py has
"DEFAULT_START_DATE_TIME": '1999-01-01 00:00:00',
"DEFAULT_END_DATE_TIME": datetime.datetime.today(),
And my reports.py repeat the start just for completeness:
def get_initial(self):
initial = super().get_initial()
initial["start_date"] = '1900-01-01 00:00:00'
return initial
And here shows lots of things that are not translated: Results, Search, Show ... entries, Showing 1 to 4 of 4 entries, and Previous ... Next. I don't think these are under my control. Compare with Filtros etc in the other images. So some 'built in' text is being automatically translated (as Django does) but most aren't. I found the Export to CSV - that was in my code and is now translated via the po/mo.
Yep Hello again :)
So, for this DEFAULT_START_DATE_TIME": '1999-01-01 00:00:00',
maybe you should change it to DEFAULT_START_DATE_TIME": datetime.datetime(1999,1,1,0,0,0)
? and i should change it in code and in the docs
For the translation:
You'd need to add the translation into your po files as you did with the export to CSV.
How ?
Create a "dummy" function somewhere in your code like this
def dummy():
x = _("Results")
x = _("From Date")
x = _("To Date")
# ...
Now those strings wil be added to your po files -> translated -> be visible on your website.
For the "Showing 1 to 4 of 4 entries" part, this is with datatables.net check https://datatables.net/manual/i18n
Let me know how it goes ;)