mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-02 18:19:25 +01:00
Translate week day names in workout screens
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/models/workouts/set.dart';
|
||||
|
||||
@@ -64,6 +65,19 @@ class Day {
|
||||
return daysOfWeek.map((e) => getDayName(e)).join(', ');
|
||||
}
|
||||
|
||||
String getDaysTextTranslated(locale) {
|
||||
return daysOfWeek.map((e) => getDayTranslated(e, locale)).join(', ');
|
||||
}
|
||||
|
||||
/// Returns the translated name of the given day
|
||||
String getDayTranslated(int day, locale) {
|
||||
// Isn't there another way?... 🙄
|
||||
final now = DateTime.now();
|
||||
final firstDayOfWeek = now.subtract(Duration(days: now.weekday));
|
||||
|
||||
return DateFormat(DateFormat.WEEKDAY, locale).format(firstDayOfWeek.add(Duration(days: day)));
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory Day.fromJson(Map<String, dynamic> json) => _$DayFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DayToJson(this);
|
||||
|
||||
@@ -196,7 +196,7 @@ class DayHeaderDismissible extends StatelessWidget {
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(_day.getDaysText),
|
||||
Text(_day.getDaysTextTranslated(Localizations.localeOf(context).languageCode)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -113,7 +113,10 @@ class _DayCheckboxState extends State<DayCheckbox> {
|
||||
Widget build(BuildContext context) {
|
||||
return CheckboxListTile(
|
||||
key: Key('field-checkbox-${widget._dayNr}'),
|
||||
title: Text(widget._day.getDayName(widget._dayNr)),
|
||||
title: Text(widget._day.getDayTranslated(
|
||||
widget._dayNr,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
)),
|
||||
value: _isSelected,
|
||||
onChanged: (bool? newValue) {
|
||||
setState(() {
|
||||
|
||||
@@ -82,4 +82,20 @@ void main() {
|
||||
//await tester.pumpAndSettle();
|
||||
//verify(mockObserver.didPop(any, any));
|
||||
});
|
||||
|
||||
testWidgets('Tests the localization of days - EN', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
|
||||
expect(find.text('Monday'), findsOneWidget);
|
||||
expect(find.text('Tuesday'), findsOneWidget);
|
||||
expect(find.text('Thursday'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Tests the localization of days - DE', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen(locale: 'de'));
|
||||
|
||||
expect(find.text('Montag'), findsOneWidget);
|
||||
expect(find.text('Dienstag'), findsOneWidget);
|
||||
expect(find.text('Donnerstag'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ void main() {
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Monday, Tuesday'), findsOneWidget);
|
||||
expect(find.text('Thursday'), findsOneWidget);
|
||||
expect(find.text('Montag, Dienstag'), findsOneWidget);
|
||||
expect(find.text('Donnerstag'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user