Add a language-switch system with per-language files
Introduce a hand-rolled i18n layer across all three UIs, each reading its
text from per-language JSON files (English base + Polish + Danish). Nothing
in the converted screens hardcodes English any more.
- Web App (Vue): src/i18n/{en,pl,da}.json + index.js exposing t()/tSplit(),
reactive to the signed-in profile locale. Every view, component, form and
the status labels in lib/format.js go through t().
- API Server panel (Vue): src/i18n/ with its own localStorage-persisted
language (the panel has no user profile) and a header language picker.
Chrome, cards, login and API section titles translated; endpoint reference
descriptions intentionally kept in English. Rebuilt embedded dist.
- Phone App (Flutter): assets/i18n/ + lib/i18n.dart loaded at startup,
driven by AppSettings.locale. Nav, login, lock, dashboard, the full
Settings panel (incl. language picker) and format.dart status labels
translated; remaining detail screens fall back to English.
Language = the language half of the existing BCP-47 locale; the region half
still drives date/number/currency formatting. Missing keys fall back to
English, and plurals use Intl.PluralRules / Intl.plural so Polish gets the
correct one/few/many forms. Settings flags languages without a translation.
Tests updated to assert the localized (Polish) status wording; all pass.
See TRANSLATIONS.md for the format and how to add a language.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee28b522c7
commit
b6bb6b1df0
54 files changed
+4191
-979
No files matched your search
@@ -9,12 +9,20 @@
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
import "package:intl/date_symbol_data_local.dart";
|
||||
import "package:carcontrol_phone/format.dart";
|
||||
import "package:carcontrol_phone/i18n.dart";
|
||||
import "package:carcontrol_phone/main.dart";
|
||||
import "package:carcontrol_phone/models.dart";
|
||||
|
||||
void main() {
|
||||
// rootBundle (used by loadTranslations) needs the binding initialised.
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUpAll(() async {
|
||||
await initializeDateFormatting();
|
||||
await loadTranslations();
|
||||
// Polish exercises both the region-aware number grouping and the localized
|
||||
// status wording (one/few/many plurals), so the badge labels below are the
|
||||
// Polish strings — the same text the web app renders under pl.
|
||||
appSettings.locale = "pl-PL";
|
||||
appSettings.currency = "PLN";
|
||||
appSettings.dateFormat = "DMY";
|
||||
@@ -67,11 +75,11 @@ void main() {
|
||||
"expiry": {"state": state, "daysUntilExpiry": days},
|
||||
"hasFile": false,
|
||||
});
|
||||
expect(expiryStatus(doc("expired", -5).expiry).label, "Expired 5d ago");
|
||||
expect(expiryStatus(doc("expiring_soon", 0).expiry).label, "Expires today");
|
||||
expect(expiryStatus(doc("expiring_soon", 12).expiry).label, "Renew in 12d");
|
||||
expect(expiryStatus(doc("valid", 200).expiry).label, "Valid · 200d");
|
||||
expect(expiryStatus(doc("no_expiry", null).expiry).label, "No expiry");
|
||||
expect(expiryStatus(doc("expired", -5).expiry).label, "Wygasło 5 dni temu");
|
||||
expect(expiryStatus(doc("expiring_soon", 0).expiry).label, "Wygasa dzisiaj");
|
||||
expect(expiryStatus(doc("expiring_soon", 12).expiry).label, "Odnowienie za 12 dni");
|
||||
expect(expiryStatus(doc("valid", 200).expiry).label, "Ważne · 200 dni");
|
||||
expect(expiryStatus(doc("no_expiry", null).expiry).label, "Bezterminowe");
|
||||
expect(expiryStatus(doc("expired", -5).expiry).key, StatusKey.overdue);
|
||||
});
|
||||
|
||||
@@ -79,16 +87,19 @@ void main() {
|
||||
Reminder rem(Map<String, dynamic> extra) =>
|
||||
Reminder.fromJson({"id": "r", "car": "c", "title": "t", "type": "service", ...extra});
|
||||
|
||||
expect(reminderStatus(rem({"status": "done", "done": true})).label, "Done");
|
||||
expect(reminderStatus(rem({"status": "no_trigger"})).label, "No trigger");
|
||||
expect(reminderStatus(rem({"status": "done", "done": true})).label, "Gotowe");
|
||||
expect(reminderStatus(rem({"status": "no_trigger"})).label, "Brak wyzwalacza");
|
||||
expect(
|
||||
reminderStatus(rem({"status": "overdue", "daysLeft": -3, "kmLeft": -200})).label,
|
||||
"Overdue 3d · 200 km");
|
||||
expect(reminderStatus(rem({"status": "due_soon", "daysLeft": 0})).label, "Due in today");
|
||||
// The km count is grouped per the chosen locale (pl-PL uses a space), which
|
||||
// is the whole point of routing every number through the one helper.
|
||||
expect(reminderStatus(rem({"status": "upcoming", "daysLeft": 40, "kmLeft": 5000})).label,
|
||||
"Due in 40d · 5 000 km");
|
||||
"Zaległe 3 dni · 200 km");
|
||||
expect(reminderStatus(rem({"status": "due_soon", "daysLeft": 0})).label, "Termin za dzisiaj");
|
||||
// The km count is grouped per the chosen locale (pl-PL groups thousands with
|
||||
// a space), which is the whole point of routing every number through the one
|
||||
// helper. Asserted as start + end so the exact space glyph (ICU uses a
|
||||
// non-breaking space) does not make the test brittle.
|
||||
final due = reminderStatus(rem({"status": "upcoming", "daysLeft": 40, "kmLeft": 5000})).label;
|
||||
expect(due, startsWith("Termin za 40 dni · 5"));
|
||||
expect(due, endsWith("000 km"));
|
||||
});
|
||||
|
||||
test("TechnicalCheck: a failed check derives no next date", () {
|
||||
@@ -121,7 +132,7 @@ void main() {
|
||||
"hasFile": false,
|
||||
});
|
||||
expect(m.totalCost, 150.0);
|
||||
expect(warrantyStatus(m)!.label, "Warranty ends in 10d");
|
||||
expect(warrantyStatus(m)!.label, "Gwarancja kończy się za 10 dni");
|
||||
expect(warrantyStatus(m)!.key, StatusKey.soon);
|
||||
|
||||
final noWarranty = MaintenanceEntry.fromJson(
|
||||
|
||||
Reference in new issue
Block a user