Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bn language support #227

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/timeago/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ main() async {
timeago.setLocaleMessages('az_short', timeago.AzShortMessages());
timeago.setLocaleMessages('ca', timeago.CaMessages());
timeago.setLocaleMessages('ca_short', timeago.CaShortMessages());
timeago.setLocaleMessages('bn', timeago.BnMessages());
timeago.setLocaleMessages('bn_short', timeago.BnShortMessages());
timeago.setLocaleMessages('cs', timeago.CsMessages());
timeago.setLocaleMessages('cs_short', timeago.CsShortMessages());
timeago.setLocaleMessages('bn', timeago.BnMessages());
Expand Down
59 changes: 40 additions & 19 deletions packages/timeago/lib/src/messages/bn_messages.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import 'package:timeago/src/messages/lookupmessages.dart';

/// English Messages
const Map<String, String> banglaDigits = {
'0': '০',
'1': '১',
'2': '২',
'3': '৩',
'4': '৪',
'5': '৫',
'6': '৬',
'7': '৭',
'8': '৮',
'9': '৯'
};

String convertToBanglaNumerals(String input) {
return input.split('').map((char) => banglaDigits[char] ?? char).join();
}

/// Bangla Messages
class BnMessages implements LookupMessages {
@override
String prefixAgo() => '';
Expand All @@ -13,30 +30,31 @@ class BnMessages implements LookupMessages {
@override
String lessThanOneMinute(int seconds) => 'কিছুক্ষন';
@override
String aboutAMinute(int minutes) => 'এক মিনিট';
String aboutAMinute(int minutes) => 'প্রায় এক মিনিট';
@override
String minutes(int minutes) => '$minutes মিনিট';
@override
String aboutAnHour(int minutes) => 'এক ঘন্টা';
String aboutAnHour(int minutes) => 'প্রায় এক ঘন্টা';
@override
String hours(int hours) => '$hours ঘন্টা';
@override
String aDay(int hours) => 'এক দিন';
@override
String days(int days) => '$days দিন';
String days(int days) => '${convertToBanglaNumerals(days.toString())} দিন';
@override
String aboutAMonth(int days) => 'এক মাস';
String aboutAMonth(int days) => 'প্রায় এক মাস';
@override
String months(int months) => '$months মাস';
String months(int months) =>
'${convertToBanglaNumerals(months.toString())} মাস';
@override
String aboutAYear(int year) => 'এক বছর';
String aboutAYear(int year) => 'প্রায় এক বছর';
@override
String years(int years) => '$years বছর';
String years(int years) => '${convertToBanglaNumerals(years.toString())} বছর';
@override
String wordSeparator() => ' ';
}

/// English short Messages
/// Bangla short Messages
class BnShortMessages implements LookupMessages {
@override
String prefixAgo() => '';
Expand All @@ -49,25 +67,28 @@ class BnShortMessages implements LookupMessages {
@override
String lessThanOneMinute(int seconds) => 'এখন';
@override
String aboutAMinute(int minutes) => '1মিনিট';
String aboutAMinute(int minutes) => '১মিনিট ';
@override
String minutes(int minutes) => '${minutes}মাস';
String minutes(int minutes) =>
'${convertToBanglaNumerals(minutes.toString())}মিনিট';
@override
String aboutAnHour(int minutes) => '~1ঘন্টা';
String aboutAnHour(int minutes) => '~১ঘন্টা';
@override
String hours(int hours) => '${hours}ঘন্টা';
String hours(int hours) =>
'${convertToBanglaNumerals(hours.toString())}ঘন্টা';
@override
String aDay(int hours) => '~1দিন';
String aDay(int hours) => '~১দি';
@override
String days(int days) => '${days}দিন';
String days(int days) => '${convertToBanglaNumerals(days.toString())}দি';
@override
String aboutAMonth(int days) => '~1মাস';
String aboutAMonth(int days) => '~১মাস';
@override
String months(int months) => '${months}মাস';
String months(int months) =>
'${convertToBanglaNumerals(months.toString())}মাস';
@override
String aboutAYear(int year) => '~1বছর';
String aboutAYear(int year) => '~১বছর';
@override
String years(int years) => '${years}বছর';
String years(int years) => '${convertToBanglaNumerals(years.toString())}বছর';
@override
String wordSeparator() => ' ';
}
3 changes: 2 additions & 1 deletion packages/timeago/lib/src/timeago.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ String format(DateTime date,
{String? locale, DateTime? clock, bool allowFromNow = false}) {
final _locale = locale ?? _default;
if (_lookupMessagesMap[_locale] == null) {
print("Locale [$_locale] has not been added, using [$_default] as fallback. To add a locale use [setLocaleMessages]");
print(
"Locale [$_locale] has not been added, using [$_default] as fallback. To add a locale use [setLocaleMessages]");
}
final _allowFromNow = allowFromNow;
final messages = _lookupMessagesMap[_locale] ?? EnMessages();
Expand Down