Skip to content

Commit

Permalink
Merge pull request #77 from simonverzelen/main
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke authored Jan 6, 2025
2 parents c3e116d + a26aacf commit 09d5214
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/src/codecs/text/l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../../utils.dart';
import 'en.dart';

export 'en.dart';
export 'nl.dart';

/// Contains localized strings used by [RecurrenceRule.toText].
///
Expand Down
163 changes: 163 additions & 0 deletions lib/src/codecs/text/l10n/nl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:meta/meta.dart';

import '../../../frequency.dart';
import 'l10n.dart';

@immutable
class RruleL10nNl extends RruleL10n {
const RruleL10nNl._();

static Future<RruleL10nNl> create() async {
await initializeDateFormatting('nl');
return const RruleL10nNl._();
}

@override
String get locale => 'nl';

@override
String frequencyInterval(Frequency frequency, int interval) {
String plurals({required String one, required String singular, required String plural}) {
return switch (interval) {
1 => one,
2 => 'Om de twee $plural',
_ => 'Om de $interval $plural',
};
}

return {
Frequency.secondly: plurals(one: 'Elke seconde', singular: 'seconde', plural: 'seconden'),
Frequency.minutely: plurals(one: 'Elke minuut', singular: 'minuut', plural: 'minuten'),
Frequency.hourly: plurals(one: 'Elk uur', singular: 'uur', plural: 'uren'),
Frequency.daily: plurals(one: 'Dagelijks', singular: 'dag', plural: 'dagen'),
Frequency.weekly: plurals(one: 'Wekelijks', singular: 'week', plural: 'weken'),
Frequency.monthly: plurals(one: 'Maandelijks', singular: 'maand', plural: 'maanden'),
Frequency.yearly: plurals(one: 'Jaarlijks', singular: 'jaar', plural: 'jaar'),
}[frequency]!;
}

@override
String until(DateTime until, Frequency frequency) {
final untilString = formatWithIntl(
() => DateFormat('EEEE d MMMM yyyy \'om\' H:mm \'uur\'', 'nl').format(until),
);
return ', tot $untilString';
}

@override
String count(int count) {
return switch (count) {
1 => ', één keer',
2 => ', twee keer',
_ => ', $count keer',
};
}

@override
String onInstances(String instances) => 'op de $instances';

@override
String inMonths(String months, {InOnVariant variant = InOnVariant.simple}) {
final suffix = variant == InOnVariant.also ? ' vallen' : '';
return '${_inVariant(variant)} $months$suffix';
}

@override
String inWeeks(String weeks, {InOnVariant variant = InOnVariant.simple}) {
final suffix = variant == InOnVariant.also ? ' vallen' : '';
return '${_inVariant(variant)} de $weeks week$suffix';
}

String _inVariant(InOnVariant variant) {
return switch (variant) {
InOnVariant.simple => 'in',
InOnVariant.also => 'die tevens in',
InOnVariant.instanceOf => 'van',
};
}

@override
String onDaysOfWeek(
String days, {
bool indicateFrequency = false,
DaysOfWeekFrequency? frequency = DaysOfWeekFrequency.monthly,
InOnVariant variant = InOnVariant.simple,
}) {
assert(variant != InOnVariant.also);

final frequencyString = frequency == DaysOfWeekFrequency.monthly ? 'de maand' : 'het jaar';
final suffix = indicateFrequency ? ' van $frequencyString' : '';
return '${_onVariant(variant)} $days$suffix';
}

@override
String? get weekdaysString => 'weekdagen';
@override
String get everyXDaysOfWeekPrefix => 'elke ';
@override
String nthDaysOfWeek(Iterable<int> occurrences, String daysOfWeek) {
if (occurrences.isEmpty) return daysOfWeek;

final ordinals = list(
occurrences.map(ordinal).toList(),
ListCombination.conjunctiveShort,
);
return 'de $ordinals $daysOfWeek';
}

@override
String onDaysOfMonth(
String days, {
DaysOfVariant daysOfVariant = DaysOfVariant.dayAndFrequency,
InOnVariant variant = InOnVariant.simple,
}) {
final suffix = {
DaysOfVariant.simple: '',
DaysOfVariant.day: ' dag',
DaysOfVariant.dayAndFrequency: ' dag van de maand',
}[daysOfVariant];
final suffix2 = variant == InOnVariant.also ? ' zijn' : '';
return '${_onVariant(variant)} de $days$suffix$suffix2';
}

@override
String onDaysOfYear(
String days, {
InOnVariant variant = InOnVariant.simple,
}) {
final suffix = variant == InOnVariant.also ? ' zijn' : '';
return '${_onVariant(variant)} de $days dag van het jaar$suffix';
}

String _onVariant(InOnVariant variant) {
return switch (variant) {
InOnVariant.simple => 'op',
InOnVariant.also => 'die tevens',
InOnVariant.instanceOf => 'van',
};
}

@override
String list(List<String> items, ListCombination combination) {
final two = combination == ListCombination.disjunctive ? ' of ' : ' en ';
final end = combination == ListCombination.conjunctiveLong ? ', en ' : two;
return RruleL10n.defaultList(items, two: two, end: end);
}

@override
String ordinal(int number) {
assert(number != 0);

const special = {1: 'eerste', -1: 'laatste', -2: 'voorlaatste'};
final result = special[number];
if (result != null) return result;

final n = number.abs();
final remain = n % 100;
final string = (remain <= 1 || remain == 8 || remain >= 20) ? '${n}ste' : '${n}de';

return number < 0 ? '$n-na-laatste' : string;
}
}
Loading

0 comments on commit 09d5214

Please sign in to comment.