Skip to content

Commit

Permalink
Feature/Add Nepali Locale (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabin6969 authored Jan 26, 2025
1 parent 0494139 commit 8a547be
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ GetTimeAgo.setCustomLocaleMessages('en', CustomMessages());
- Vietnamese
- Romanian
- Dutch
- Nepali
- Open to accept PR for adding more languages

## Contributing
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Map<String, String> languageNames = {
'vi': 'Vietnamese',
'ro': 'Romanian',
'nl': 'Dutch',
"ne": 'Nepali'
};

class _GetTimeAgoExampleScreenState extends State<GetTimeAgoExampleScreen> {
Expand Down
43 changes: 43 additions & 0 deletions lib/src/messages/languages/ne_msg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:get_time_ago/get_time_ago.dart';

class NepaliMessages extends Messages {
/// Message for approximately 1 day ago. [hours]: The number of hours that have passed (usually 24).
@override
String dayAgo(int hours) => "एक दिन";

/// Message when the elapsed time is in days. [days]: The number of days that have passed.
@override
String daysAgo(int days) => "$days दिन";

/// Message for approximately 1 hour ago. [minutes]: The number of minutes that have passed (usually 60).
@override
String hourAgo(int minutes) => "एक घण्टा";

/// Message when the elapsed time is in hours. [hours]: The number of hours that have passed.
@override
String hoursAgo(int hours) => "$hours घण्टा";

/// Message when the elapsed time is less than 15 seconds. [seconds]: The number of seconds that have passed.
@override
String justNow(int seconds) => "भर्खरै";

/// Message for approximately 1 minute ago. [minutes]: The number of minutes that have passed (usually 1).
@override
String minAgo(int minutes) => "एक मिनेट";

/// Message when the elapsed time is in minutes. [minutes]: The number of minutes that have passed.
@override
String minsAgo(int minutes) => "$minutes मिनेट";

/// Prefix added before the time ago message
@override
String prefixAgo() => "";

/// Message when the elapsed time is less than a minute. [seconds]: The number of seconds that have passed.
@override
String secsAgo(int seconds) => "$seconds सेकेन्ड";

/// Suffix added after the time ago message.
@override
String suffixAgo() => "अघि";
}
3 changes: 3 additions & 0 deletions lib/src/utils/data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:get_time_ago/src/messages/languages/ne_msg.dart';

import '../messages/languages/ar_msg.dart';
import '../messages/languages/de_msg.dart';
import '../messages/languages/en_msg.dart';
Expand Down Expand Up @@ -53,5 +55,6 @@ class Data {
'vi': VietnameseMessages(), // Vietnamese
'ro': RomanianMessages(), // Romanian
'nl': DutchMessages(), // Dutch
"ne": NepaliMessages(), // Nepali
};
}
163 changes: 163 additions & 0 deletions test/messages/language/ne_msg_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import 'package:get_time_ago/get_time_ago.dart';
import 'package:get_time_ago/src/messages/languages/ne_msg.dart';
import 'package:test/test.dart';

void main() {
var nepaliMessages = NepaliMessages();

group("Nepali Message Test", () {
test("Just now should return भर्खरै", () {
expect(nepaliMessages.justNow(5), "भर्खरै");
});

test("daysAgo should return 1 दिन", () {
expect(nepaliMessages.daysAgo(1), "1 दिन");
});

test("dayAgo should return एक दिन", () {
expect(nepaliMessages.dayAgo(24), "एक दिन");
});

test("minAgo should return एक मिनेट", () {
expect(nepaliMessages.minAgo(1), "एक मिनेट");
});

test("minsAgo should return 10 मिनेट", () {
expect(nepaliMessages.minsAgo(10), "10 मिनेट");
});

test("prefixAgo should return empty string", () {
expect(nepaliMessages.prefixAgo(), "");
});

test("suffixAgo should return अघि", () {
expect(nepaliMessages.suffixAgo(), "अघि");
});

test("secondsAgo should return 20 सेकेन्ड", () {
expect(nepaliMessages.secsAgo(20), "20 सेकेन्ड");
});

test('wordSeperator should return " " ', () {
expect(nepaliMessages.wordSeparator(), " ");
});

test("hourAgo should return एक घण्टा", () {
expect(nepaliMessages.hourAgo(40), "एक घण्टा");
});

test("hoursAgo should return 3 घण्टा", () {
expect(nepaliMessages.hoursAgo(3), "3 घण्टा");
});
});

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

group("GetTimeAgo with Nepali Locale", () {
test("should return भर्खरै for time ellapsed less than 15 seconds", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(seconds: 0),
),
locale: "ne",
);
expect(result, "भर्खरै");
});

test("should return भर्खरै for time ellapsed less than 15 seconds", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(seconds: 13),
),
locale: "ne",
);
expect(result, "भर्खरै");
});

test("should return 20 सेकेन्ड अघि for time ellapsed more than 15 seconds",
() {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(seconds: 25),
),
locale: "ne",
);
expect(result, "25 सेकेन्ड अघि");
});

test("should return एक मिनेट अघि for time 1 min ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
locale: "ne",
);
expect(result, "एक मिनेट अघि");
});

test("should return 2 मिनेट अघिn for time 2 minutes ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 2)),
locale: "ne",
);
expect(result, "2 मिनेट अघि");
});

test("should return एक घण्टा अघि for time 1 hour ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
locale: "ne",
);

expect(result, "एक घण्टा अघि");
});

test("should return 2 घण्टा अघि for time 2 hour ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 2)),
locale: "ne",
);

expect(result, "2 घण्टा अघि");
});

test("should return एक दिन अघि for time 24 hours ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(hours: 24),
),
locale: "ne",
);
expect(result, "एक दिन अघि");
});

test("should return 3 दिन अघि for time 3 day ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(days: 3),
),
locale: "ne",
);
expect(result, "3 दिन अघि");
});

test("should return 7 दिन अघि for time 7 day ago", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(
const Duration(days: 7),
),
locale: "ne",
);
expect(result, "7 दिन अघि");
});

test("should return formatted data for duration beyond 7 days", () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 8)),
locale: "ne",
);
expect(result, isNot("8 दिन अघि"));
});
});
}

0 comments on commit 8a547be

Please sign in to comment.