Skip to content

Commit 03769eb

Browse files
committed
多语言初始化
1 parent 5cd898b commit 03769eb

37 files changed

+1107
-202
lines changed

VERSION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* markdown htmlview 表格。
99
* 版本信息列表
1010

11+
### 1.1.0(进行中)
12+
* 切换用户切换数据库。
13+
1114
### 1.0.9
1215
* 切换主题支持
1316
* 问题修复

lib/common/dao/ReposDao.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class ReposDao {
661661
if (result > 0) {
662662
CommonUtils.showUpdateDialog(context, release.name + ": " + release.body);
663663
} else {
664-
if (showTip) Fluttertoast.showToast(msg: GSYStrings.app_not_new_version);
664+
if (showTip) Fluttertoast.showToast(msg: CommonUtils.getLocale(context).app_not_new_version);
665665
}
666666
}
667667
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:ui';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:gsy_github_app_flutter/common/style/GSYStringBase.dart';
5+
import 'package:gsy_github_app_flutter/common/style/GSYStringEn.dart';
6+
import 'package:gsy_github_app_flutter/common/style/GSYStringZh.dart';
7+
8+
class GSYLocalizations {
9+
final Locale locale;
10+
11+
GSYLocalizations(this.locale);
12+
13+
static Map<String, GSYStringBase> _localizedValues = {
14+
'en': new GSYStringEn(),
15+
'zh': new GSYStringZh(),
16+
};
17+
18+
GSYStringBase get currentLocalized {
19+
print("++++++++++++++++++++++++++++++++++");
20+
print(locale.languageCode);
21+
print("++++++++++++++++++++++++++++++++++");
22+
return _localizedValues[locale.languageCode];
23+
}
24+
25+
static GSYLocalizations of(BuildContext context) {
26+
return Localizations.of(context, GSYLocalizations);
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter/material.dart';
5+
import 'package:gsy_github_app_flutter/common/localization/DefaultLocalizations.dart';
6+
7+
/**
8+
* Created by guoshuyu
9+
* Date: 2018-08-15
10+
*/
11+
class GSYLocalizationsDelegate extends LocalizationsDelegate<GSYLocalizations> {
12+
13+
GSYLocalizationsDelegate();
14+
15+
@override
16+
bool isSupported(Locale locale) {
17+
return ['en', 'zh'].contains(locale.languageCode);
18+
}
19+
20+
@override
21+
Future<GSYLocalizations> load(Locale locale) {
22+
return new SynchronousFuture<GSYLocalizations>(new GSYLocalizations(locale));
23+
}
24+
25+
@override
26+
bool shouldReload(LocalizationsDelegate<GSYLocalizations> old) {
27+
return false;
28+
}
29+
30+
static GSYLocalizationsDelegate delegate = new GSYLocalizationsDelegate();
31+
}

lib/common/redux/GSYState.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
66
import 'package:gsy_github_app_flutter/common/redux/EventRedux.dart';
77
import 'package:gsy_github_app_flutter/common/redux/TrendRedux.dart';
88
import 'package:gsy_github_app_flutter/common/redux/ThemeRedux.dart';
9+
import 'package:gsy_github_app_flutter/common/redux/LocaleRedux.dart';
910

1011
/**
1112
* Redux全局State
@@ -26,8 +27,10 @@ class GSYState {
2627

2728
ThemeData themeData;
2829

30+
Locale locale;
31+
2932
///构造方法
30-
GSYState({this.userInfo, this.eventList, this.trendList, this.themeData});
33+
GSYState({this.userInfo, this.eventList, this.trendList, this.themeData, this.locale});
3134
}
3235

3336
///通过 Reducer 创建 store 保存的 GSYState
@@ -43,5 +46,7 @@ GSYState appReducer(GSYState state, action) {
4346
trendList: TrendReducer(state.trendList, action),
4447

4548
themeData: ThemeDataReducer(state.themeData, action),
49+
50+
locale: LocaleReducer(state.locale, action),
4651
);
4752
}

lib/common/redux/LocaleRedux.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import 'package:flutter/material.dart';
3+
import 'package:redux/redux.dart';
4+
5+
/**
6+
* 语言Redux
7+
* Created by guoshuyu
8+
* Date: 2018-07-16
9+
*/
10+
11+
final LocaleReducer = combineReducers<Locale>([
12+
TypedReducer<Locale, RefreshLocaleAction>(_refresh),
13+
]);
14+
15+
Locale _refresh(Locale locale, RefreshLocaleAction action) {
16+
locale = action.locale;
17+
return locale;
18+
}
19+
20+
class RefreshLocaleAction {
21+
final Locale locale;
22+
23+
RefreshLocaleAction(this.locale);
24+
}
25+
26+
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/**
2+
* Created by guoshuyu
3+
* Date: 2018-08-15
4+
*/
5+
abstract class GSYStringBase {
6+
7+
String welcomeMessage;
8+
9+
String app_name;
10+
11+
12+
String app_ok;
13+
14+
String app_cancel;
15+
16+
String app_empty;
17+
String app_licenses;
18+
String app_close;
19+
20+
String app_version;
21+
22+
String app_back_tip;
23+
24+
String app_not_new_version;
25+
String app_version_title;
26+
27+
String nothing_now;
28+
29+
String loading_text;
30+
31+
String option_web;
32+
33+
String option_copy;
34+
35+
String option_share;
36+
37+
String option_web_launcher_error;
38+
39+
String option_share_title;
40+
String option_share_copy_success;
41+
42+
String login_text;
43+
44+
String Login_out;
45+
46+
String home_reply;
47+
48+
String home_about;
49+
50+
String home_check_update;
51+
52+
String home_history;
53+
54+
String home_user_info;
55+
56+
String home_change_theme;
57+
58+
String home_theme_default;
59+
60+
String home_theme_1;
61+
62+
String home_theme_2;
63+
64+
String home_theme_3;
65+
66+
String home_theme_4;
67+
68+
String home_theme_5;
69+
70+
String home_theme_6;
71+
72+
String login_username_hint_text;
73+
74+
String login_password_hint_text;
75+
76+
String login_success;
77+
78+
String network_error_401;
79+
String network_error_403;
80+
81+
String network_error_404;
82+
83+
String network_error_timeout;
84+
85+
String network_error_unknown;
86+
87+
String network_error;
88+
89+
String load_more_not;
90+
91+
String load_more_text;
92+
93+
String home_dynamic;
94+
95+
String home_trend;
96+
String home_my;
97+
98+
String trend_day;
99+
100+
String trend_week;
101+
102+
String trend_month;
103+
104+
String trend_all;
105+
106+
String user_tab_repos;
107+
108+
String user_tab_fans;
109+
110+
String user_tab_focus;
111+
112+
String user_tab_star;
113+
114+
String user_tab_honor;
115+
String user_dynamic_group;
116+
117+
String user_dynamic_title;
118+
119+
String user_focus;
120+
String user_un_focus;
121+
122+
String user_focus_no_support;
123+
String user_create_at;
124+
String user_orgs_title;
125+
126+
String repos_tab_readme;
127+
128+
String repos_tab_info;
129+
130+
String repos_tab_file;
131+
132+
String repos_tab_issue;
133+
134+
String repos_tab_activity;
135+
String repos_tab_commits;
136+
String repos_tab_issue_all;
137+
String repos_tab_issue_open;
138+
String repos_tab_issue_closed;
139+
String repos_option_release;
140+
141+
String repos_fork_at;
142+
String repos_create_at;
143+
144+
String repos_last_commit;
145+
146+
String repos_all_issue_count;
147+
148+
String repos_open_issue_count;
149+
String repos_close_issue_count;
150+
151+
String repos_issue_search;
152+
153+
String issue_reply;
154+
155+
String issue_edit;
156+
157+
String issue_open;
158+
159+
String issue_close;
160+
161+
String issue_lock;
162+
String issue_unlock;
163+
164+
String issue_reply_issue;
165+
166+
String issue_commit_issue;
167+
168+
String issue_edit_issue;
169+
170+
String issue_edit_issue_commit;
171+
String issue_edit_issue_edit_commit;
172+
173+
String issue_edit_issue_delete_commit;
174+
175+
String issue_edit_issue_copy_commit;
176+
String issue_edit_issue_content_not_be_null;
177+
178+
String issue_edit_issue_title_not_be_null;
179+
180+
String issue_edit_issue_title_tip;
181+
182+
String issue_edit_issue_content_tip;
183+
184+
String notify_title;
185+
String notify_tab_all;
186+
187+
String notify_tab_part;
188+
189+
String notify_tab_unread;
190+
String notify_unread;
191+
192+
String notify_readed;
193+
194+
String notify_status;
195+
196+
String notify_type;
197+
198+
String search_title;
199+
String search_tab_repos;
200+
201+
String search_tab_user;
202+
203+
String release_tab_release;
204+
205+
String release_tab_tag;
206+
207+
String user_profile_name;
208+
209+
String user_profile_email;
210+
211+
String user_profile_link;
212+
213+
String user_profile_org;
214+
String user_profile_location;
215+
String user_profile_info;
216+
}

0 commit comments

Comments
 (0)