Self hosted FLOSS fitness/workout, nutrition and weight tracker
Update the way to extract translatable strings from the DB
Roland Geider10974f4e2c96
diff --git a/.gitignore b/.gitignoreindex 9c8a9dd45..a15f12fa3 100644--- a/.gitignore+++ b/.gitignore@@ -63,4 +63,8 @@ target/wger/core/static/yarnnode_modules+# Virtual envsvenv++# Dummy file for translations+/wger/i18n.tpldiff --git a/docs/i18n.rst b/docs/i18n.rstindex 9ab348609..469e97813 100644--- a/docs/i18n.rst+++ b/docs/i18n.rst@@ -8,18 +8,18 @@ Updating the translation files------------------------------wger uses django's translation infrastructure, but there are a couple of things-that need to be considered. First, update your po files with the usual django-command (run this in the wger subfolder, not the root one)::+that need to be considered. First you need to extract some translatable strings+from the database such as exercise categories and muscle names::- django-admin makemessages --locale en --extension py,html,tpl+ python ../manage.py extract-i18n-Extract some translatable strings from the database such as exercise categories-and muscle names::+Then, update your po files with the usual django command (run this in the wger+subfolder, not the root one)::++ django-admin makemessages --locale en --extension py,html,tpl- python ../manage.py extract-i18n-and add them to the end of ``locale/en/LC_MESSAGES/django.po``. Once you have-translated the file, compile it with::+and finally you can compile them with::django-admin compilemessages --alldiff --git a/wger/core/management/commands/extract-i18n.py b/wger/core/management/commands/extract-i18n.pyindex d3383db5c..581c6dc1f 100644--- a/wger/core/management/commands/extract-i18n.py+++ b/wger/core/management/commands/extract-i18n.py@@ -36,13 +36,16 @@ class Command(BaseCommand):def handle(self, **options):# Collect all translatable items- out = []- out += [i for i in ExerciseCategory.objects.all()]- out += [i for i in Equipment.objects.all()]- out += [i for i in Muscle.objects.all()]- out += [i for i in RepetitionUnit.objects.all()]-- # Print the result- for i in out:- self.stdout.write(f'msgid "{i}"\n'- 'msgstr ""\n\n')+ data = [i for i in ExerciseCategory.objects.all()] \+ + [i for i in Equipment.objects.all()] \+ + [i for i in Muscle.objects.all()] \+ + [i for i in RepetitionUnit.objects.all()]++ # Write the result to a file that can be read by gettext. Yes, this is+ # a bit ugly, but the categories or muscles have basically never changed.+ out = '{% load i18n %}\n'+ for i in data:+ out += f'{{% translate "{i}" %}}\n'++ with open('wger/i18n.tpl', 'w') as f:+ f.write(out)