Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Also extract strings for translation in react

Roland Geider5303c9d6ea75
diff --git a/wger/core/management/commands/extract-i18n.py b/wger/core/management/commands/extract-i18n.py
index 9186070c8..3253fb0bb 100644
--- a/wger/core/management/commands/extract-i18n.py
+++ b/wger/core/management/commands/extract-i18n.py
@@ -28,10 +28,13 @@ from wger.exercises.models import (
class Command(BaseCommand):
"""
- Helper command to read out the strings to manually include in the .po files
+ Helper command to extract translatable content from the database such as
+ categories, muscles or equipment names and write it to files, so they can
+ be extracted and translated on weblate. This is a bit hacky and ugly, but
+ these strings *very* rarely change.
"""
- help = 'Read out all strings that have to be included manually in the .po file'
+ help = 'Write the translatable strings from the database to a file'
def handle(self, **options):
@@ -41,11 +44,29 @@ class Command(BaseCommand):
+ [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'
-
+ # Django - write to .tpl file
with open('wger/i18n.tpl', 'w') as f:
+ out = '{% load i18n %}\n'
+ for i in data:
+ out += f'{{% translate "{i}" %}}\n'
+ f.write(out)
+ self.stdout.write(self.style.SUCCESS(f'Wrote content to i18n.tpl!'))
+
+ # React - write to .tsx file (copy the file into the react repo)
+ with open('wger/i18n.tsx', 'w') as f:
+ out = '''
+ import { useTranslation } from "react-i18next";
+
+ export const DummyComponent = () => {
+ const [t, i18n] = useTranslation();'''
+ for i in data:
+ out += f't("{i}");\n'
+
+ out += '''
+ return (<p></p>);
+ };'''
f.write(out)
+ self.stdout.write(self.style.SUCCESS(f'Wrote content to i18n.tsx!'))
+
+ # Flutter - write to .dart file (copy the file into the flutter repo)
+ # TO BE IMPLEMENTED...