Skip to content

Commit

Permalink
Add helper script to extract exercise translations
Browse files Browse the repository at this point in the history
This generates a dart file that can be used to generate screenshots with translated
exercise names for the Play Store
  • Loading branch information
rolandgeider committed Jan 10, 2024
1 parent 4853505 commit d12f2cb
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
92 changes: 92 additions & 0 deletions wger/core/management/commands/extract-i18n-flutter-exercises.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

# Django
from django.core.management.base import BaseCommand

# wger
from wger.exercises.models import Exercise


class Command(BaseCommand):
help = ("Helper command to extract translations for the exercises used in the flutter repo for "
"the screenshots for the play store")

uuids = {
'squats': '30ac081b-fb79-4253-9457-8efc07568790',
'benchPress': '3717d144-7815-4a97-9a56-956fb889c996',
'deadLift': 'ee8e8db4-2d82-49e1-ab7f-891e9a354934',
'crunches': 'b186f1f8-4957-44dc-bf30-d0b00064ce6f',
'curls': '1ae6a28d-10e7-4ecf-af4f-905f8193e2c6',
'raises': '63375f5b-2d81-471c-bea4-fc3d207e96cb'
}

def handle(self, **options):
out = []
languages = []

for exercise_key in self.uuids.keys():
self.stdout.write(f"Extracting translations for {exercise_key}")

uuid = self.uuids[exercise_key]
translations = Exercise.objects.filter(exercise_base__uuid=uuid)

variables = []

for translation in translations:
variable_name = f"{exercise_key}{translation.language.short_name.upper()}"
variables.append(variable_name)

if translation.language not in languages:
languages.append(translation.language)

self.stdout.write(
f"- translation {translation.language.short_name}: {translation.name}")

out.append(
f"""
final {variable_name} = Translation(
id: {translation.id},
uuid: '{translation.uuid}',
created: DateTime(2021, 1, 15),
name: '{translation.name}',
description: '''{translation.description}''',
baseId: {translation.exercise_base_id},
language: tLanguage{translation.language.id},
);
"""
)
self.stdout.write("")

out.append(f'final {exercise_key}Translations = [{",".join(variables)}];')

for language in languages:
out.insert(
0,
f"""const tLanguage{language.id} = Language(
id: {language.id},
shortName: '{language.short_name}',
fullName: '{language.full_name}',
);"""
)

out.insert(0, "import 'package:wger/models/exercises/language.dart';")
out.insert(0, "import 'package:wger/models/exercises/translation.dart';")
out.insert(0, "// Autogenerated by extract-i18n-flutter-exercises.py do not edit!")

#
# Write to output
with open('screenshots_exercises.dart', 'w') as f:
f.write('\n'.join(out))
self.stdout.write(self.style.SUCCESS(f'Wrote content to screenshots_exercises.dart'))
2 changes: 1 addition & 1 deletion wger/core/management/commands/extract-i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def cleanup_name(text: str) -> str:
self.stdout.write(self.style.SUCCESS(f'Wrote content to wger/i18n.tpl'))

#
# React - copy the file to src/i18n.tsx in the react repo
# React - copy the file to src/i18n.tsx in the React repo
with open('wger/i18n.tsx', 'w') as f:
out = '''
// This code is autogenerated in the backend repo in extract-i18n.py do not edit!
Expand Down

0 comments on commit d12f2cb

Please sign in to comment.