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

Add look up messages map #188

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2cb911c
Added time ago messages for Amharic language.
Aug 11, 2022
1fe9a55
added amharic language example
Aug 12, 2022
e374318
added look up messages map for amharic language
Aug 12, 2022
539e063
added look up messages map for arabic language
Aug 12, 2022
d709f2d
added look up messages map for Azeri language
Aug 12, 2022
8a04fe8
added look up messages map for Catalan language
Aug 12, 2022
b91f0a1
added look up messages map for Czech language
Aug 12, 2022
416c346
added look up messages map for Danish language
Aug 12, 2022
8241e41
added look up messages map for German language
Aug 12, 2022
3b5d95a
added look up messages map for Divehi language
Aug 12, 2022
05f29e9
added look up messages map for Estonian language
Aug 12, 2022
37b2d87
added look up messages map for Farsi language
Aug 12, 2022
f72db6e
added look up messages map for Finnish language
Aug 12, 2022
46e3c9d
added look up messages map for French language
Aug 12, 2022
68c2925
added look up messages map for Greek language
Aug 12, 2022
2772c60
added look up messages map for Hebrew language
Aug 12, 2022
c9d205f
added look up messages map for Hindi language
Aug 12, 2022
b359447
added look up messages map for Hungarian language
Aug 12, 2022
74d3258
added look up messages map for Indonesian language
Aug 12, 2022
4da023d
added look up messages map for Italian language
Aug 12, 2022
ea1d220
added look up messages map for Japanese language
Aug 12, 2022
607f4e7
added look up messages map for Cambodian language
Aug 12, 2022
44289dd
added look up messages map for Korean language
Aug 12, 2022
9470f3d
added look up messages map for Kurdish language
Aug 12, 2022
91d0d52
added look up messages map for Mongolian language
Aug 12, 2022
1e919a1
added look up messages map for Malay-Malaysia lang
Aug 12, 2022
7545d00
look up message map for Norwegian-Bokm-Norway lang
Aug 12, 2022
de202d3
added look up messages map for Dutch language
Aug 12, 2022
8d094fa
look up message map for Norwegian-Nynorsk-Norway lang
Aug 12, 2022
68188df
added look up messages map for Polish language
Aug 12, 2022
921bd0a
added look up messages map for Portuguese language
Aug 12, 2022
d2821fc
added look up messages map for Romanian language
Aug 12, 2022
f74f788
added look up messages map for Russian language
Aug 12, 2022
3a821c5
added look up messages map for Kinyarwanda language
Aug 12, 2022
8a38984
added look up messages map for Swedish language
Aug 12, 2022
c692d71
added look up messages map for Tamil language
Aug 12, 2022
9c4fe25
added look up messages map for Thai language
Aug 12, 2022
03c43e1
added look up messages map for Turkish language
Aug 12, 2022
090b69f
added look up messages map for Ukrainian language
Aug 12, 2022
cf43d31
added look up messages map for Urdu language
Aug 12, 2022
9becf26
added look up messages map for Vietnamese language
Aug 12, 2022
aef145f
added look up messages map for Chinese-China language
Aug 12, 2022
f17ffd5
added look up messages map for Chinese language
Aug 12, 2022
85a9afe
change locale from ko to en
Aug 12, 2022
7a627a8
Merge pull request #1 from knatnaela/test-bug-fix
knatnaela Aug 12, 2022
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 @@ -8,6 +8,8 @@ final listContainer = querySelector("#list");
var locale = 'en';

main() async {
timeago.setLocaleMessages('am', timeago.AmMessages());
timeago.setLocaleMessages('am_short', timeago.AmShortMessages());
timeago.setLocaleMessages('ar', timeago.ArMessages());
timeago.setLocaleMessages('ar_short', timeago.ArShortMessages());
timeago.setLocaleMessages('az', timeago.AzMessages());
Expand Down
113 changes: 113 additions & 0 deletions packages/timeago/lib/src/messages/am_messages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:timeago/src/messages/lookupmessages.dart';

/// Amharic Messages
class AmMessages implements LookupMessages {
@override
String aDay(int hours) => 'ቀን';

@override
String aboutAMinute(int minutes) => 'አንድ ደቂቃ';

@override
String aboutAMonth(int days) => 'አንድ ወር ገደማ';

@override
String aboutAYear(int year) => 'አንድ ዓመት ገደማ';

@override
String aboutAnHour(int minutes) => 'ለአንድ ሰዓት ያህል';

@override
String days(int days) {
if (days == 1) {
return '$days ቀን';
}
return '$days ቀናት';
}

@override
String hours(int hours) {
if (hours == 1) {
'$hours ሰአት';
}
return '$hours ሰአታት';
}

@override
String lessThanOneMinute(int seconds) => 'አንድ አፍታ';

@override
String minutes(int minutes) {
if (minutes == 1) {
return '$minutes ደቂቃ';
}
return '$minutes ደቂቃዎች';
}

@override
String months(int months) {
if (months == 1) {
return '$months ወር';
}
return '$months ወራት';
}

@override
String prefixAgo() => '';

@override
String prefixFromNow() => '';

@override
String suffixAgo() => 'በፊት';

@override
String suffixFromNow() => 'ከአሁን ጀምሮ';
@override
String wordSeparator() => ' ';

@override
String years(int years) {
if (years == 1) {
return '$years አመት';
}
return '$years አመታት';
}
}

/// Amharic short Messages

class AmShortMessages implements LookupMessages {
@override
String prefixAgo() => '';
@override
String prefixFromNow() => '';
@override
String suffixAgo() => '';
@override
String suffixFromNow() => '';
@override
String lessThanOneMinute(int seconds) => 'አሁን';
@override
String aboutAMinute(int minutes) => '1ደ';
@override
String minutes(int minutes) => '${minutes}ደ';
@override
String aboutAnHour(int minutes) => '~1ሰ';
@override
String hours(int hours) => '${hours}ሰ';
@override
String aDay(int hours) => '~1ቀ';
@override
String days(int days) => '${days}ቀ';
@override
String aboutAMonth(int days) => '~1ወር';
@override
String months(int months) => '${months}ወር';
@override
String aboutAYear(int year) => '~1ዓ';
@override
String years(int years) => '${years}ዓ';
@override
String wordSeparator() => ' ';
}
117 changes: 116 additions & 1 deletion packages/timeago/lib/src/timeago.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,128 @@
import 'package:timeago/src/messages/am_messages.dart';
import 'package:timeago/src/messages/az_messages.dart';
import 'package:timeago/src/messages/ca_messages.dart';
import 'package:timeago/src/messages/cs_messages.dart';
import 'package:timeago/src/messages/da_messages.dart';
import 'package:timeago/src/messages/de_messages.dart';
import 'package:timeago/src/messages/dv_messages.dart';
import 'package:timeago/src/messages/en_messages.dart';
import 'package:timeago/src/messages/es_messages.dart';
import 'package:timeago/src/messages/et_messages.dart';
import 'package:timeago/src/messages/fa_messages.dart';
import 'package:timeago/src/messages/fi_messages.dart';
import 'package:timeago/src/messages/fr_messages.dart';
import 'package:timeago/src/messages/gr_messages.dart';
import 'package:timeago/src/messages/he_messages.dart';
import 'package:timeago/src/messages/hi_messages.dart';
import 'package:timeago/src/messages/hu_messages.dart';
import 'package:timeago/src/messages/id_messages.dart';
import 'package:timeago/src/messages/it_messages.dart';
import 'package:timeago/src/messages/ja_messages.dart';
import 'package:timeago/src/messages/km_messages.dart';
import 'package:timeago/src/messages/ko_messages.dart';
import 'package:timeago/src/messages/ku_messages.dart';
import 'package:timeago/src/messages/lookupmessages.dart';
import 'package:timeago/src/messages/mn_messages.dart';
import 'package:timeago/src/messages/ms_my_messages.dart';
import 'package:timeago/src/messages/nb_no_messages.dart';
import 'package:timeago/src/messages/nl_messages.dart';
import 'package:timeago/src/messages/nn_no_messages.dart';
import 'package:timeago/src/messages/pl_messages.dart';
import 'package:timeago/src/messages/pt_br_messages.dart';
import 'package:timeago/src/messages/ro_messages.dart';
import 'package:timeago/src/messages/ru_messages.dart';
import 'package:timeago/src/messages/rw_messages.dart';
import 'package:timeago/src/messages/sv_messages.dart';
import 'package:timeago/src/messages/ta_messages.dart';
import 'package:timeago/src/messages/th_messages.dart';
import 'package:timeago/src/messages/tr_messages.dart';
import 'package:timeago/src/messages/uk_messages.dart';
import 'package:timeago/src/messages/ur_messages.dart';
import 'package:timeago/src/messages/vi_messages.dart';
import 'package:timeago/src/messages/zh_cn_messages.dart';
import 'package:timeago/src/messages/zh_messages.dart';

import 'messages/ar_messages.dart';

String _default = 'en';

Map<String, LookupMessages> _lookupMessagesMap = {
'am': AmMessages(),
'am_short': AmShortMessages(),
'ar': ArMessages(),
'ar_short': ArShortMessages(),
'az': AzMessages(),
'az_short': AzShortMessages(),
'ca': CaMessages(),
'ca_short': CaShortMessages(),
'cs': CsMessages(),
'cs_short': CsShortMessages(),
'da': DaMessages(),
'da_short': DaShortMessages(),
'de': DeMessages(),
'de_short': DeShortMessages(),
'dv': DvMessages(),
'dv_short': DvShortMessages(),
'en': EnMessages(),
'en_short': EnShortMessages(),
'es': EsMessages(),
'es_short': EsShortMessages(),
'et': EtMessages(),
'et_short': EtShortMessages(),
'fa': FaMessages(),
'fi': FiMessages(),
'fi_short': FiShortMessages(),
'fr': FrMessages(),
'fr_short': FrShortMessages(),
'gr': GrMessages(),
'gr_short': GrShortMessages(),
'he': HeMessages(),
'he_short': HeShortMessages(),
'hi': HiMessages(),
'hi_short': HiShortMessages(),
'hu': HuMessages(),
'hu_short': HuShortMessages(),
'id': IdMessages(),
'it': ItMessages(),
'it_short': ItShortMessages(),
'ja': JaMessages(),
'km': KmMessages(),
'km_short': KmShortMessages(),
'ko': KoMessages(),
'ku': KuMessages(),
'ku_short': KuShortMessages(),
'mn': MnMessages(),
'mn_short': MnShortMessages(),
'ms_my': MsMyMessages(),
'ms_my_short': MsMyShortMessages(),
'nb_no': NbNoMessages(),
'nb_no_short': NbNoShortMessages(),
'nl': NlMessages(),
'nl_short': NlShortMessages(),
'nn_no': NnNoMessages(),
'nn_no_short': NnNoShortMessages(),
'pl': PlMessages(),
'pt_br': PtBrMessages(),
'pt_br_short': PtBrShortMessages(),
'ro': RoMessages(),
'ro_short': RoShortMessages(),
'ru': RuMessages(),
'ru_short': RuShortMessages(),
'rw': RwMessages(),
'rw_short': RwShortMessages(),
'sv': SvMessages(),
'sv_short': SvShortMessages(),
'ta': TaMessages(),
'th': ThMessages(),
'th_short': ThShortMessages(),
'tr': TrMessages(),
'uk': UkMessages(),
'uk_short': UkShortMessages(),
'ur': UrMessages(),
'vi': ViMessages(),
'vi_short': ViShortMessages(),
'zh_cn': ZhCnMessages(),
'zh': ZhMessages(),
};

/// Sets the default [locale]. By default it is `en`.
Expand Down Expand Up @@ -51,7 +165,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
2 changes: 1 addition & 1 deletion packages/timeago/test/all_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
() async {
final clock = now.add(Duration(seconds: 1));

var result = timeago.format(now, locale: 'ko', clock: clock);
var result = timeago.format(now, locale: 'en', clock: clock);
expect(result, equals('a moment ago'));
});

Expand Down