Skip to content

Commit

Permalink
Merge pull request #34 from FredvanRijswijk/feature/add-dutch-language
Browse files Browse the repository at this point in the history
Feature/add dutch language
  • Loading branch information
nixrajput authored Nov 5, 2024
2 parents be4009a + 5054ff6 commit 10074b1
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ GetTimeAgo.setCustomLocaleMessages('en', CustomMessages());
- Urdu
- Vietnamese
- Romanian
- Dutch
- Open to accept PR for adding more languages

## Contributing
Expand Down
1 change: 1 addition & 0 deletions lib/get_time_ago.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export 'package:get_time_ago/src/messages/languages/hi_msg.dart';
export 'package:get_time_ago/src/messages/languages/id_msg.dart';
export 'package:get_time_ago/src/messages/languages/ja_msg.dart';
export 'package:get_time_ago/src/messages/languages/ko_msg.dart';
export 'package:get_time_ago/src/messages/languages/nl_msg.dart';
export 'package:get_time_ago/src/messages/languages/oc_msg.dart';
export 'package:get_time_ago/src/messages/languages/pt_br_msg.dart';
export 'package:get_time_ago/src/messages/languages/ro_msg.dart';
Expand Down
50 changes: 50 additions & 0 deletions lib/src/messages/languages/nl_msg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import '../messages.dart';

/// The [DutchMessages] class provides Dutch language-specific
/// implementations of the [Messages] interface. This class is used to format
/// the "time ago" strings in Dutch.
class DutchMessages implements Messages {
/// Prefix added before the time message.
@override
String prefixAgo() => '';

/// Suffix added after the time message.
@override
String suffixAgo() => 'geleden';

/// Message when the elapsed time is less than 15 seconds.
@override
String justNow(int seconds) => 'zojuist';

/// Message for when the elapsed time is less than a minute.
@override
String secsAgo(int seconds) => '$seconds seconden';

/// Message for when the elapsed time is about a minute.
@override
String minAgo(int minutes) => 'een minuut';

/// Message for when the elapsed time is in minutes.
@override
String minsAgo(int minutes) => '$minutes minuten';

/// Message for when the elapsed time is about an hour.
@override
String hourAgo(int minutes) => 'een uur';

/// Message for when the elapsed time is in hours.
@override
String hoursAgo(int hours) => '$hours uur';

/// Message for when the elapsed time is about a day.
@override
String dayAgo(int hours) => 'een dag';

/// Message for when the elapsed time is in days.
@override
String daysAgo(int days) => '$days dagen';

/// Word separator to be used when joining the parts of the message.
@override
String wordSeparator() => ' ';
}
2 changes: 2 additions & 0 deletions lib/src/utils/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../messages/languages/hi_msg.dart';
import '../messages/languages/id_msg.dart';
import '../messages/languages/ja_msg.dart';
import '../messages/languages/ko_msg.dart';
import '../messages/languages/nl_msg.dart';
import '../messages/languages/oc_msg.dart';
import '../messages/languages/pt_br_msg.dart';
import '../messages/languages/ro_msg.dart';
Expand Down Expand Up @@ -51,5 +52,6 @@ class Data {
'ur': UrduMessages(), // Urdu
'vi': VietnameseMessages(), // Vietnamese
'ro': RomanianMessages(), // Romanian
'nl': DutchMessages(), // Dutch
};
}
131 changes: 131 additions & 0 deletions test/messages/language/nl_msg_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import 'package:get_time_ago/get_time_ago.dart';
import 'package:test/test.dart';

void main() {
final messages = DutchMessages();

group('DutchMessages Test', () {
test('prefixAgo should return an empty string', () {
expect(messages.prefixAgo(), '');
});

test('suffixAgo should return "geleden"', () {
expect(messages.suffixAgo(), 'geleden');
});

test('justNow should return "zojuist"', () {
expect(messages.justNow(10), 'zojuist');
});

test('secsAgo should return correct seconden ago format', () {
expect(messages.secsAgo(25), '25 seconden');
});

test('minAgo should return "een minuut"', () {
expect(messages.minAgo(1), 'een minuut');
});

test('minsAgo should return correct minutes ago format', () {
expect(messages.minsAgo(5), '5 minuten');
});

test('hourAgo should return "een uur"', () {
expect(messages.hourAgo(60), 'een uur');
});

test('hoursAgo should return correct hours ago format', () {
expect(messages.hoursAgo(5), '5 uur');
});

test('dayAgo should return "een dag"', () {
expect(messages.dayAgo(24), 'een dag');
});

test('daysAgo should return correct days ago format', () {
expect(messages.daysAgo(5), '5 dagen');
});

test('wordSeparator should return a space', () {
expect(messages.wordSeparator(), ' ');
});
});

// Helper function to get the DateTime relative to now
DateTime _getRelativeDateTime(Duration duration) {
return DateTime.now().subtract(duration);
}

group('GetTimeAgo Test with Dutch Locale', () {
test('should return "just now" for time less than 15 seconds', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 0)),
locale: 'nl',
);
expect(result, 'zojuist');
});

test('should return correct format for seconds ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 20)),
locale: 'nl',
);
expect(result, '20 seconden geleden');
});

test('should return "a minute ago" for 1 minute ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
locale: 'nl',
);
expect(result, 'een minuut geleden');
});

test('should return correct format for 5 minutes ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 5)),
locale: 'nl',
);
expect(result, '5 minuten geleden');
});

test('should return "an hour ago" for 1 hour ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
locale: 'nl',
);
expect(result, 'een uur geleden');
});

test('should return correct format for 5 hours ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 5)),
locale: 'nl',
);
expect(result, '5 uur geleden');
});

test('should return "a day ago" for 1 day ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 1)),
locale: 'nl',
);
expect(result, 'een dag geleden');
});

test('should return correct format for 5 days ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 5)),
locale: 'nl',
);
expect(result, '5 dagen geleden');
});

test('should return formatted date for dates beyond 7 days', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 10)),
locale: 'nl',
);
expect(result, isNot('10 dagen geleden'));
});
});
}

0 comments on commit 10074b1

Please sign in to comment.