Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Sort strings alphabetically

Roland Geiderf4cf4c9904b5
diff --git a/wger/core/management/commands/extract-i18n.py b/wger/core/management/commands/extract-i18n.py
index f52e0e908..d6a7f7c69 100644
--- a/wger/core/management/commands/extract-i18n.py
+++ b/wger/core/management/commands/extract-i18n.py
@@ -40,21 +40,21 @@ class Command(BaseCommand):
# Replace whitespace and other problematic characters with underscores
def cleanup_name(text: str) -> str:
- return text.lower().\
- replace(' ', '_').\
- replace('-', '_').\
- replace('/', '_').\
- replace('(', '_').\
+ return text.lower(). \
+ replace(' ', '_'). \
+ replace('-', '_'). \
+ replace('/', '_'). \
+ replace('(', '_'). \
replace(')', '_')
# Collect all translatable items
data = [i for i in ExerciseCategory.objects.all()] \
- + [i for i in Equipment.objects.all()] \
- + [i.name_en for i in Muscle.objects.all() if i.name_en] \
- + [i for i in RepetitionUnit.objects.all()]
+ + [i for i in Equipment.objects.all()] \
+ + [i.name_en for i in Muscle.objects.all() if i.name_en] \
+ + [i for i in RepetitionUnit.objects.all()]
- # Make entries unique
- data = set([i.__str__() for i in data])
+ # Make entries unique and sort alphabetically
+ data = sorted(set([i.__str__() for i in data]))
#
# Django - write to .tpl file
@@ -63,12 +63,19 @@ class Command(BaseCommand):
for i in data:
out += f'{{% translate "{i}" %}}\n'
f.write(out)
- self.stdout.write(self.style.SUCCESS(f'Wrote content to i18n.tpl!'))
+ 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
with open('wger/i18n.tsx', 'w') as f:
out = '''
+ // This code is autogenerated in the backend repo in extract-i18n.py do not edit!
+
+ // Translate dynamic strings that are returned from the server
+ // These strings such as categories or equipment are returned by the server
+ // in English and need to be translated here in the application (there are
+ // probably better ways to do this, but that's the way it is right now).
+
import { useTranslation } from "react-i18next";
const DummyComponent = () => {
@@ -80,7 +87,7 @@ class Command(BaseCommand):
return (<p></p>);
};'''
f.write(out)
- self.stdout.write(self.style.SUCCESS(f'Wrote content to i18n.tsx!'))
+ self.stdout.write(self.style.SUCCESS(f'Wrote content to wger/i18n.tsx'))
#
# Flutter - copy content to the end of lib/l10n/app_en.arb in the flutter repo
@@ -89,13 +96,11 @@ class Command(BaseCommand):
for i in data:
out += f'"{cleanup_name(i.__str__())}": "{i}",\n'
f.write(out)
- self.stdout.write(self.style.SUCCESS(f'Wrote content to app_en.arb!'))
+ self.stdout.write(self.style.SUCCESS(f'Wrote content to app_en.arb'))
# Copy to lib/helpers/i18n.dart in the flutter repo
with open('wger/i18n.dart', 'w') as f:
out = '''
- import 'package:flutter/widgets.dart';
- import 'package:flutter_gen/gen_l10n/app_localizations.dart';
/// This code is autogenerated in the backend repo in extract-i18n.py do not edit!
/// Translate dynamic strings that are returned from the server
@@ -103,6 +108,9 @@ class Command(BaseCommand):
/// in English and need to be translated here in the application (there are
/// probably better ways to do this, but that's the way it is right now).
+ import 'package:flutter/widgets.dart';
+ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+
String getTranslation(String value, BuildContext context) {
switch (value) {'''
for i in data:
@@ -111,10 +119,10 @@ class Command(BaseCommand):
return AppLocalizations.of(context).{cleanup_name(i.__str__())};
'''
- out += '''default:
- return 'NOT TRANSLATED';
- }}
- }}'''
+ out += '''
+ default:
+ throw FormatException('Could not translate the server string $value');
+ }}'''
f.write(out)
- self.stdout.write(self.style.SUCCESS('Wrote content to i18n.dart!'))
+ self.stdout.write(self.style.SUCCESS('Wrote content to wger/i18n.dart'))
diff --git a/wger/i18n.tpl b/wger/i18n.tpl
index 4e2ee8011..d5605c287 100644
--- a/wger/i18n.tpl
+++ b/wger/i18n.tpl
@@ -1,32 +1,32 @@
{% load i18n %}
-{% translate "Until Failure" %}
+{% translate "Abs" %}
+{% translate "Arms" %}
+{% translate "Back" %}
+{% translate "Barbell" %}
+{% translate "Bench" %}
+{% translate "Biceps" %}
{% translate "Calves" %}
+{% translate "Cardio" %}
+{% translate "Chest" %}
{% translate "Dumbbell" %}
-{% translate "Barbell" %}
-{% translate "Swiss Ball" %}
+{% translate "Glutes" %}
{% translate "Gym mat" %}
-{% translate "Miles" %}
-{% translate "Minutes" %}
-{% translate "Chest" %}
+{% translate "Hamstrings" %}
+{% translate "Incline bench" %}
+{% translate "Kettlebell" %}
{% translate "Kilometers" %}
-{% translate "Shoulders" %}
-{% translate "Cardio" %}
-{% translate "Biceps" %}
-{% translate "Arms" %}
-{% translate "Triceps" %}
-{% translate "Glutes" %}
+{% translate "Lats" %}
{% translate "Legs" %}
-{% translate "Repetitions" %}
-{% translate "Seconds" %}
+{% translate "Lower back" %}
+{% translate "Miles" %}
+{% translate "Minutes" %}
+{% translate "Pull-up bar" %}
{% translate "Quads" %}
+{% translate "Repetitions" %}
{% translate "SZ-Bar" %}
-{% translate "Back" %}
-{% translate "Bench" %}
-{% translate "Lats" %}
-{% translate "Incline bench" %}
-{% translate "Pull-up bar" %}
-{% translate "Abs" %}
-{% translate "Hamstrings" %}
+{% translate "Seconds" %}
+{% translate "Shoulders" %}
+{% translate "Swiss Ball" %}
+{% translate "Triceps" %}
+{% translate "Until Failure" %}
{% translate "none (bodyweight exercise)" %}
-{% translate "Lower back" %}
-{% translate "Kettlebell" %}