From bd58fccff04c098541dd4480eb896f999ea84f51 Mon Sep 17 00:00:00 2001 From: Fred van Rijswijk Date: Mon, 4 Nov 2024 12:23:51 +0000 Subject: [PATCH 1/5] adding dutch language --- lib/get_time_ago.dart | 1 + lib/src/messages/languages/nl_msg.dart | 50 ++++++++++++++++++++++++++ lib/src/utils/data.dart | 2 ++ 3 files changed, 53 insertions(+) create mode 100644 lib/src/messages/languages/nl_msg.dart diff --git a/lib/get_time_ago.dart b/lib/get_time_ago.dart index 6664858..b9638fd 100644 --- a/lib/get_time_ago.dart +++ b/lib/get_time_ago.dart @@ -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'; diff --git a/lib/src/messages/languages/nl_msg.dart b/lib/src/messages/languages/nl_msg.dart new file mode 100644 index 0000000..9292d35 --- /dev/null +++ b/lib/src/messages/languages/nl_msg.dart @@ -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 uren'; + + /// 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() => ' '; +} diff --git a/lib/src/utils/data.dart b/lib/src/utils/data.dart index c0162a0..d8fdbd3 100644 --- a/lib/src/utils/data.dart +++ b/lib/src/utils/data.dart @@ -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'; @@ -51,5 +52,6 @@ class Data { 'ur': UrduMessages(), // Urdu 'vi': VietnameseMessages(), // Vietnamese 'ro': RomanianMessages(), // Romanian + 'nl': DutchMessages(), // Dutch }; } From b05fb3400c6ec3de3de77ff48638e7e380f296aa Mon Sep 17 00:00:00 2001 From: Fred van Rijswijk Date: Mon, 4 Nov 2024 12:46:36 +0000 Subject: [PATCH 2/5] Add feature/fix: Adding the Dutch language + test --- test/messages/language/nl_msg_test.dart | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 test/messages/language/nl_msg_test.dart diff --git a/test/messages/language/nl_msg_test.dart b/test/messages/language/nl_msg_test.dart new file mode 100644 index 0000000..03b2281 --- /dev/null +++ b/test/messages/language/nl_msg_test.dart @@ -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 hours'); + }); + + 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')); + }); + }); +} From ab0bb58fc620f292bb1095e2a52feb60c0afb808 Mon Sep 17 00:00:00 2001 From: Fred van Rijswijk Date: Mon, 4 Nov 2024 16:36:59 +0000 Subject: [PATCH 3/5] fix test 5 hours ago --- test/messages/language/nl_msg_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/messages/language/nl_msg_test.dart b/test/messages/language/nl_msg_test.dart index 03b2281..d17c938 100644 --- a/test/messages/language/nl_msg_test.dart +++ b/test/messages/language/nl_msg_test.dart @@ -34,7 +34,7 @@ void main() { }); test('hoursAgo should return correct hours ago format', () { - expect(messages.hoursAgo(5), '5 hours'); + expect(messages.hoursAgo(5), '5 uren'); }); test('dayAgo should return "een dag"', () { From 268558e7b956eec3d5c293587761afea81f88537 Mon Sep 17 00:00:00 2001 From: Fred van Rijswijk Date: Mon, 4 Nov 2024 16:38:10 +0000 Subject: [PATCH 4/5] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ed381cf..b5f579e 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ GetTimeAgo.setCustomLocaleMessages('en', CustomMessages()); - Urdu - Vietnamese - Romanian +- Dutch - Open to accept PR for adding more languages ## Contributing From 5054ff62982d1bcc6f3d76d49b6daca2e9ae4356 Mon Sep 17 00:00:00 2001 From: Fred van Rijswijk Date: Tue, 5 Nov 2024 08:23:00 +0000 Subject: [PATCH 5/5] fix 5 hours ago / 5 uur geleden --- lib/src/messages/languages/nl_msg.dart | 2 +- test/messages/language/nl_msg_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/messages/languages/nl_msg.dart b/lib/src/messages/languages/nl_msg.dart index 9292d35..b0cf056 100644 --- a/lib/src/messages/languages/nl_msg.dart +++ b/lib/src/messages/languages/nl_msg.dart @@ -34,7 +34,7 @@ class DutchMessages implements Messages { /// Message for when the elapsed time is in hours. @override - String hoursAgo(int hours) => '$hours uren'; + String hoursAgo(int hours) => '$hours uur'; /// Message for when the elapsed time is about a day. @override diff --git a/test/messages/language/nl_msg_test.dart b/test/messages/language/nl_msg_test.dart index d17c938..a6c9136 100644 --- a/test/messages/language/nl_msg_test.dart +++ b/test/messages/language/nl_msg_test.dart @@ -34,7 +34,7 @@ void main() { }); test('hoursAgo should return correct hours ago format', () { - expect(messages.hoursAgo(5), '5 uren'); + expect(messages.hoursAgo(5), '5 uur'); }); test('dayAgo should return "een dag"', () {