choice method

  1. @override
String choice(
  1. String key,
  2. int count, {
  3. Map<String, dynamic>? parameters,
  4. String? locale,
  5. String? namespace,
})
override

Translates with pluralization based on count.

Implementation

@override
String choice(
  String key,
  int count, {
  Map<String, dynamic>? parameters,
  String? locale,
  String? namespace,
}) {
  final loc = locale ?? _currentLocale;
  final ns = namespace ?? '';

  String? msg =
      _getTranslation(key, loc, ns) ?? _getTranslation(key, loc, '');

  if (msg == null && loc != _fallbackLocale) {
    msg = _getTranslation(key, _fallbackLocale, ns) ??
        _getTranslation(key, _fallbackLocale, '');
  }

  msg ??= key;

  // Handle pluralization
  if (msg.contains('|')) {
    final parts = msg.split('|');
    msg = count == 1 ? parts[0] : (parts.length > 1 ? parts[1] : parts[0]);
  }

  // Add count to parameters
  final params = Map<String, dynamic>.from(parameters ?? {});
  params['count'] = count;

  return _replaceParameters(msg, params);
}