Preserve numeric counts in plural fallback messages

Use the numeric argument in grammatical one branches because target-locale rules can select them for 21 and larger counts. Keep exact-number wording and add relative-date and distribution widget regressions.
This commit is contained in:
Luke Gabriel R. Arrieta
2026-11-03 08:32:20 +08:00
parent a88ba0e130
commit 60ed8a0509
4 changed files with 60 additions and 12 deletions

View File

@@ -6,6 +6,13 @@ These files are usually edited on weblate, and not directly in the repo:
## Maintenance
Use the numeric placeholder in grammatical plural branches, including `one`:
`{count, plural, one{{count} week} other{{count} weeks}}`. In some languages,
`one` also applies to numbers such as 21; it is not an exact match for 1.
Use exact selectors such as `=1` for wording that really is specific to that
number, for example `yesterday`. Keep existing exact selectors when editing
plural messages, and have translators review the changed source strings in Weblate.
Find keys that are not used in the code anymore:
```bash
@@ -28,4 +35,4 @@ When a new `app_<locale>.arb` file is added (usually by a Weblate PR), register
per-app language settings (uses `pt-BR`, not `pt_BR`)
- `ios/Runner/Info.plist` under `CFBundleLocalizations`, so iOS offers the language for the app
- `lib/l10n/language_native_names.dart`, so the language picker in the settings shows its native
name
name

View File

@@ -603,7 +603,7 @@
"@chartRangeAll": {
"description": "Label for the chart time-range selector option showing all data"
},
"chartRangeWeeks": "{count, plural, one{1 week} other{{count} weeks}}",
"chartRangeWeeks": "{count, plural, one{{count} week} other{{count} weeks}}",
"@chartRangeWeeks": {
"description": "Chart time-range selector option covering a number of weeks",
"placeholders": {
@@ -612,7 +612,7 @@
}
}
},
"chartRangeMonths": "{count, plural, one{1 month} other{{count} months}}",
"chartRangeMonths": "{count, plural, one{{count} month} other{{count} months}}",
"@chartRangeMonths": {
"description": "Chart time-range selector option covering a number of months",
"placeholders": {
@@ -621,7 +621,7 @@
}
}
},
"chartRangeYears": "{count, plural, one{1 year} other{{count} years}}",
"chartRangeYears": "{count, plural, one{{count} year} other{{count} years}}",
"@chartRangeYears": {
"description": "Chart time-range selector option covering a number of years",
"placeholders": {
@@ -684,7 +684,7 @@
"@chartAverageWindow": {
"description": "Label of the setting for how many days the moving average covers"
},
"chartAverageWindowDays": "{days, plural, one{1 day} other{{days} days}}",
"chartAverageWindowDays": "{days, plural, one{{days} day} other{{days} days}}",
"@chartAverageWindowDays": {
"description": "One option of the average window setting, e.g. '7 days'",
"placeholders": {
@@ -715,7 +715,7 @@
"@distributionLatest": {
"description": "Label of the marker for the most recent value in the distribution histogram"
},
"distributionEntryCount": "{count, plural, one{1 entry} other{{count} entries}}",
"distributionEntryCount": "{count, plural, one{{count} entry} other{{count} entries}}",
"@distributionEntryCount": {
"description": "How many measurements fall into the tapped histogram bin",
"placeholders": {
@@ -724,7 +724,7 @@
}
}
},
"distributionDayCount": "{count, plural, one{1 day} other{{count} days}}",
"distributionDayCount": "{count, plural, one{{count} day} other{{count} days}}",
"@distributionDayCount": {
"description": "How many days fall into the tapped histogram bin, for metrics summed per day",
"placeholders": {
@@ -742,7 +742,7 @@
}
}
},
"relativeWeeksAgo": "{count, plural, one{1 week ago} other{{count} weeks ago}}",
"relativeWeeksAgo": "{count, plural, one{{count} week ago} other{{count} weeks ago}}",
"@relativeWeeksAgo": {
"description": "How long ago something was measured, for distances below a month",
"placeholders": {
@@ -751,7 +751,7 @@
}
}
},
"relativeMonthsAgo": "{count, plural, one{1 month ago} other{{count} months ago}}",
"relativeMonthsAgo": "{count, plural, one{{count} month ago} other{{count} months ago}}",
"@relativeMonthsAgo": {
"description": "How long ago something was measured, for distances below a year",
"placeholders": {
@@ -760,7 +760,7 @@
}
}
},
"relativeYearsAgo": "{count, plural, one{1 year ago} other{{count} years ago}}",
"relativeYearsAgo": "{count, plural, one{{count} year ago} other{{count} years ago}}",
"@relativeYearsAgo": {
"description": "How long ago something was measured, for distances of a year and more",
"placeholders": {
@@ -1873,7 +1873,7 @@
}
}
},
"healthSyncStatus": "{count, plural, =0{Last sync: {time}, no new entries} one{Last sync: {time}, 1 new entry} other{Last sync: {time}, {count} new entries}}",
"healthSyncStatus": "{count, plural, =0{Last sync: {time}, no new entries} one{Last sync: {time}, {count} new entry} other{Last sync: {time}, {count} new entries}}",
"@healthSyncStatus": {
"description": "Status line under the health sync toggle showing when the last sync ran and how many entries it imported",
"placeholders": {

View File

@@ -23,6 +23,27 @@ import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/l10n/localizations_delegates.dart';
void main() {
testWidgets('plural fallback preserves the count in relative dates', (tester) async {
final now = DateTime.utc(2026, 1, 1);
for (final years in [21, 31, 101]) {
await tester.pumpWidget(
MaterialApp(
locale: const Locale('ru'),
localizationsDelegates: appLocalizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (context) => Text(
relativeDate(context, now.subtract(Duration(days: 365 * years)), now: now),
),
),
),
);
await tester.pumpAndSettle();
expect(find.textContaining(RegExp('^$years\\b')), findsOneWidget);
}
});
group('hoursAndMinutes', () {
test('splits the minutes into hours and minutes', () {
expect(hoursAndMinutes(452, 'en'), '7:32');

View File

@@ -23,7 +23,8 @@ import 'package:wger/features/measurements/widgets/charts/distribution_chart.dar
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/l10n/localizations_delegates.dart';
Widget _wrap(Widget child) => MaterialApp(
Widget _wrap(Widget child, {Locale? locale}) => MaterialApp(
locale: locale,
localizationsDelegates: appLocalizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
@@ -70,6 +71,25 @@ void main() {
return Offset(box.left + countLabelWidth + step / 2, box.top + readoutHeight + 100);
}
testWidgets('plural fallback preserves the selected distribution count', (tester) async {
await tester.pumpWidget(
_wrap(
const MeasurementDistributionWidgetFl(
[(value: 60, count: 21)],
latest: 60,
unit: 'kg',
binWidth: 2,
),
locale: const Locale('ru'),
),
);
await tester.pumpAndSettle();
await tester.tapAt(firstBinCenter(tester, bins: 1));
await tester.pumpAndSettle();
expect(find.textContaining(RegExp(r': 21\b')), findsOneWidget);
});
testWidgets('a tapped bin reads out as its range and count', (tester) async {
await tester.pumpWidget(
_wrap(const MeasurementDistributionWidgetFl(counted, latest: 65, unit: 'kg', binWidth: 2)),