Skip to content

Commit 1ce6fb2

Browse files
committed
update time lang
1 parent f190602 commit 1ce6fb2

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

lib/common/dao/user_dao.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class UserDao {
7373
if (localeIndex != null && localeIndex.length != 0) {
7474
CommonUtils.changeLocale(store, int.parse(localeIndex));
7575
} else {
76+
CommonUtils.curLocale = store.state.platformLocale;
7677
store.dispatch(RefreshLocaleAction(store.state.platformLocale));
7778
}
7879

lib/common/utils/common_utils.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class CommonUtils {
4040

4141
static final double DAYS_LIMIT = 30 * HOURS_LIMIT;
4242

43+
static Locale curLocale;
44+
4345
static String getDateStr(DateTime date) {
4446
if (date == null || date.toString() == null) {
4547
return "";
@@ -58,19 +60,33 @@ class CommonUtils {
5860

5961
///日期格式转换
6062
static String getNewsTimeStr(DateTime date) {
61-
int subTime =
63+
int subTimes =
6264
DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
6365

64-
if (subTime < MILLIS_LIMIT) {
65-
return "刚刚";
66-
} else if (subTime < SECONDS_LIMIT) {
67-
return (subTime / MILLIS_LIMIT).round().toString() + " 秒前";
68-
} else if (subTime < MINUTES_LIMIT) {
69-
return (subTime / SECONDS_LIMIT).round().toString() + " 分钟前";
70-
} else if (subTime < HOURS_LIMIT) {
71-
return (subTime / MINUTES_LIMIT).round().toString() + " 小时前";
72-
} else if (subTime < DAYS_LIMIT) {
73-
return (subTime / HOURS_LIMIT).round().toString() + " 天前";
66+
if (subTimes < MILLIS_LIMIT) {
67+
return (curLocale != null)
68+
? (curLocale.languageCode != "zh") ? "right now" : "刚刚"
69+
: "刚刚";
70+
} else if (subTimes < SECONDS_LIMIT) {
71+
return (subTimes / MILLIS_LIMIT).round().toString() +
72+
((curLocale != null)
73+
? (curLocale.languageCode != "zh") ? " seconds ago" : " 秒前"
74+
: " 秒前");
75+
} else if (subTimes < MINUTES_LIMIT) {
76+
return (subTimes / SECONDS_LIMIT).round().toString() +
77+
((curLocale != null)
78+
? (curLocale.languageCode != "zh") ? " min ago" : " 分钟前"
79+
: " 分钟前");
80+
} else if (subTimes < HOURS_LIMIT) {
81+
return (subTimes / MINUTES_LIMIT).round().toString() +
82+
((curLocale != null)
83+
? (curLocale.languageCode != "zh") ? " hours ago" : " 小时前"
84+
: " 小时前");
85+
} else if (subTimes < DAYS_LIMIT) {
86+
return (subTimes / HOURS_LIMIT).round().toString() +
87+
((curLocale != null)
88+
? (curLocale.languageCode != "zh") ? " days ago" : " 天前"
89+
: " 天前");
7490
} else {
7591
return getDateStr(date);
7692
}
@@ -148,7 +164,6 @@ class CommonUtils {
148164
return ThemeData(primarySwatch: color, platform: TargetPlatform.android);
149165
}
150166

151-
152167
static showLanguageDialog(BuildContext context, Store store) {
153168
List<String> list = [
154169
CommonUtils.getLocale(context).home_language_default,
@@ -174,6 +189,7 @@ class CommonUtils {
174189
locale = Locale('en', 'US');
175190
break;
176191
}
192+
curLocale = locale;
177193
store.dispatch(RefreshLocaleAction(locale));
178194
}
179195

0 commit comments

Comments
 (0)