i18n(alarm): localize all native notification, channel and chooser texts
Centralize every native-side user-facing string in a single
AlarmNotificationStrings store written by Flutter via a new
setNotificationStrings MethodChannel whenever the app locale changes,
and read at notification/channel build time (with English fallbacks)
even when the engine is dead. This replaces the hardcoded Spanish text
in the ringing notification ("Alarma PluriWave", "Posponer", "Detener"),
the pre-notice notification ("Posponer", "Omitir esta vez"), both
notification channels (names + descriptions) and the file-action
choosers ("Abrir carpeta", "Abrir grabación").
The per-alarm preNoticeTemplate/snoozeCountdown template+label args are
dropped from scheduleAlarm and the persisted spec and folded into the
shared store, so a locale change now also relocalizes already-scheduled
alarms. Channels are re-created on each use so their name/description
refresh after a language switch.
Adds alarmRingingNotificationTitle, alarmFire/PreNoticeChannelName,
alarmFire/PreNoticeChannelDescription and openFolder/openRecording
chooser keys across all 13 locales (reusing snoozeAction, stopAlarmAction,
skipNextAction, snoozeAgainAction). Rewrites the template test around
setNotificationStrings. Kotlin is static-reviewed only; no Android build
environment available here.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import 'dart:ui' show Locale;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/l10n/gen/app_localizations.dart';
|
||||
import 'package:pluriwave/modelos/alarma_musical.dart';
|
||||
import 'package:pluriwave/servicios/servicio_alarmas_android.dart';
|
||||
|
||||
@@ -25,55 +28,75 @@ void main() {
|
||||
});
|
||||
|
||||
test(
|
||||
'programar includes preNoticeTemplate with {minutes} placeholder in MethodChannel call',
|
||||
'configurarLocalizaciones pushes localized notification strings with {minutes} templates',
|
||||
() async {
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
final alarma = AlarmaMusical(
|
||||
id: 'test-alarm',
|
||||
nombre: 'Morning alarm',
|
||||
hora: 7,
|
||||
minuto: 0,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2099, 1, 1, 7, 0),
|
||||
final l10n = lookupAppLocalizations(const Locale('es'));
|
||||
|
||||
servicio.configurarLocalizaciones(l10n);
|
||||
// configurarLocalizaciones fires setNotificationStrings as unawaited; let
|
||||
// the microtask/event queue drain so the MethodChannel call is recorded.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
final llamada = llamadas.singleWhere(
|
||||
(c) => c.method == 'setNotificationStrings',
|
||||
);
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
|
||||
expect(
|
||||
args['preNoticeTemplate'],
|
||||
contains('{minutes}'),
|
||||
reason: 'pre-notice template must keep the {minutes} placeholder',
|
||||
);
|
||||
expect(
|
||||
args['snoozeCountdownTemplate'],
|
||||
contains('{minutes}'),
|
||||
reason: 'snooze countdown template must keep the {minutes} placeholder',
|
||||
);
|
||||
|
||||
await servicio.programar(alarma);
|
||||
|
||||
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
expect(args.containsKey('preNoticeTemplate'), isTrue,
|
||||
reason: 'preNoticeTemplate must be present in scheduleAlarm args');
|
||||
final template = args['preNoticeTemplate'] as String?;
|
||||
expect(template, isNotNull,
|
||||
reason: 'preNoticeTemplate must not be null');
|
||||
expect(template, contains('{minutes}'),
|
||||
reason: 'preNoticeTemplate must contain the {minutes} placeholder');
|
||||
// Every notification/channel/chooser string must be present and non-empty
|
||||
// so the native side never falls back to English for a configured locale.
|
||||
const claves = [
|
||||
'ringTitle',
|
||||
'snoozeLabel',
|
||||
'stopLabel',
|
||||
'skipLabel',
|
||||
'snoozeAgainLabel',
|
||||
'fireChannelName',
|
||||
'fireChannelDescription',
|
||||
'preNoticeChannelName',
|
||||
'preNoticeChannelDescription',
|
||||
'openFolderTitle',
|
||||
'openRecordingTitle',
|
||||
];
|
||||
for (final clave in claves) {
|
||||
expect(args[clave], isA<String>(), reason: '$clave missing');
|
||||
expect(
|
||||
(args[clave] as String).isNotEmpty,
|
||||
isTrue,
|
||||
reason: '$clave is empty',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'programar preNoticeTemplate uses default locale fallback when no l10n configured',
|
||||
() async {
|
||||
// ServicioAlarmasAndroid falls back to es locale when no l10n is configured
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
final alarma = AlarmaMusical(
|
||||
id: 'test-alarm-2',
|
||||
nombre: 'Alarm',
|
||||
hora: 8,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2099, 1, 2, 8, 30),
|
||||
);
|
||||
test('scheduleAlarm no longer carries notification string templates', () async {
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
final alarma = AlarmaMusical(
|
||||
id: 'no-template',
|
||||
nombre: 'Alarm',
|
||||
hora: 8,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2099, 1, 2, 8, 30),
|
||||
);
|
||||
|
||||
await servicio.programar(alarma);
|
||||
await servicio.programar(alarma);
|
||||
|
||||
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
final template = args['preNoticeTemplate'] as String?;
|
||||
// The template must contain the literal placeholder string
|
||||
expect(template, contains('{minutes}'));
|
||||
},
|
||||
);
|
||||
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
expect(args.containsKey('preNoticeTemplate'), isFalse);
|
||||
expect(args.containsKey('snoozeCountdownTemplate'), isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user