Skip to content

Commit 6ce5696

Browse files
committed
Adding gen-l10n
1 parent ab280ca commit 6ce5696

7 files changed

Lines changed: 93 additions & 10 deletions

File tree

.github/workflows/quality.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
with:
1212
flutter-version: ${{ env.FLUTTER_VERSION }}
1313
- run: flutter pub get
14+
15+
- name: Generate localization files
16+
run: flutter gen-l10n
17+
1418
- run: dart format --set-exit-if-changed .
1519
- run: flutter analyze
1620
- name: Run Dart Code Metrics

lib/design/dimensions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CustomString {
2424
return _localized('disconnecting');
2525
}
2626

27-
String get All_app {
27+
String get allapp {
2828
return _localized('all_apps');
2929
}
3030

lib/l10n/app_zh.arb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"@@locale": "zh",
3+
"app_name": "VPN客户端",
4+
"apps_selection": "应用选择",
5+
"search": "搜索",
6+
"your_location": "你的位置",
7+
"auto_select": "自动选择",
8+
"kazakhstan": "哈萨克斯坦",
9+
"turkey": "土耳其",
10+
"poland": "波兰",
11+
"fastest": "最快",
12+
"selected_server": "已选择服务器",
13+
"server_selection": "服务器选择",
14+
"all_servers": "所有服务器",
15+
"country_name": "国家名称",
16+
"all_apps": "所有应用",
17+
"done": "完成",
18+
"cancel": "取消",
19+
"recently_searched": "最近搜索",
20+
"nothing_found": "未找到内容",
21+
"connected": "已连接",
22+
"disconnected": "已断开连接",
23+
"connecting": "连接中",
24+
"disconnecting": "断开中"
25+
}
26+

lib/l10n/app_zh_cn.arb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"@@locale": "zh_CN",
3+
"app_name": "VPN客户端",
4+
"apps_selection": "应用选择",
5+
"search": "搜索",
6+
"your_location": "你的位置",
7+
"auto_select": "自动选择",
8+
"kazakhstan": "哈萨克斯坦",
9+
"turkey": "土耳其",
10+
"poland": "波兰",
11+
"fastest": "最快",
12+
"selected_server": "已选择服务器",
13+
"server_selection": "服务器选择",
14+
"all_servers": "所有服务器",
15+
"country_name": "国家名称",
16+
"all_apps": "所有应用",
17+
"done": "完成",
18+
"cancel": "取消",
19+
"recently_searched": "最近搜索",
20+
"nothing_found": "未找到内容",
21+
"connected": "已连接",
22+
"disconnected": "已断开连接",
23+
"connecting": "连接中",
24+
"disconnecting": "断开中"
25+
}
26+

lib/main.dart

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,39 @@ class App extends StatelessWidget {
2424
Widget build(BuildContext context) {
2525
final themeProvider = Provider.of<ThemeProvider>(context);
2626

27-
var language = const Locale(
28-
'th',
29-
); //<-- You can change language here manually
27+
// If you want to override it manually, do it here (or leave as null to use system):
28+
// final Locale? manualLocale = const Locale('ru'); // ← override example
29+
final Locale? manualLocale = null; // ← use system by default
3030

3131
return MaterialApp(
3232
debugShowCheckedModeBanner: false,
3333
title: 'VPN Client',
3434
theme: lightTheme,
3535
darkTheme: darkTheme,
36-
locale: language,
36+
locale: manualLocale,
37+
localeResolutionCallback: (locale, supportedLocales) {
38+
if (locale == null) return const Locale('en');
39+
40+
// Check for exact match
41+
for (var supportedLocale in supportedLocales) {
42+
if (supportedLocale.languageCode == locale.languageCode &&
43+
(supportedLocale.countryCode == null ||
44+
supportedLocale.countryCode == locale.countryCode)) {
45+
return supportedLocale;
46+
}
47+
}
48+
49+
// If Chinese variants are not supported, fallback to zh
50+
if (locale.languageCode == 'zh') {
51+
return supportedLocales.contains(const Locale('zh'))
52+
? const Locale('zh')
53+
: const Locale('en');
54+
}
55+
56+
// Fallback to 'en' if not found
57+
return const Locale('en');
58+
},
59+
3760
themeMode: themeProvider.themeMode,
3861
home: const MainScreen(),
3962

@@ -43,7 +66,12 @@ class App extends StatelessWidget {
4366
GlobalWidgetsLocalizations.delegate,
4467
GlobalCupertinoLocalizations.delegate,
4568
],
46-
supportedLocales: const [Locale('en'), Locale('ru'), Locale('th')],
69+
supportedLocales: const [
70+
Locale('en'),
71+
Locale('ru'),
72+
Locale('th'),
73+
Locale('zh'),
74+
],
4775
);
4876
}
4977
}

lib/pages/apps/apps_list.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class AppsListState extends State<AppsList> {
3232
}
3333
}
3434

35-
late String Text_All_Apps;
35+
late String textallapps;
3636
bool _initialized = false;
3737

3838
@override
3939
void didChangeDependencies() {
4040
super.didChangeDependencies();
4141
if (!_initialized) {
4242
final statusText = CustomString(context);
43-
Text_All_Apps = statusText.All_app;
43+
textallapps = statusText.allapp;
4444
_loadApps();
4545
_initialized = true;
4646
}
@@ -68,7 +68,7 @@ class AppsListState extends State<AppsList> {
6868
{
6969
'icon': null,
7070
'image': null,
71-
'text': Text_All_Apps,
71+
'text': textallapps,
7272
'isSwitch': true,
7373
'isActive': false,
7474
},

lib/pages/main/main_btn.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22
import 'dart:developer';
3-
import 'dart:developer';
43
import 'package:flutter/material.dart';
54
import 'package:vpn_client/design/colors.dart';
65
import 'package:vpn_client/design/dimensions.dart';

0 commit comments

Comments
 (0)