Skip to content

Commit 477f4e9

Browse files
WishyutCpkongkha
authored andcommitted
Add localized support and clean up with flutter analyze
1 parent b2868d9 commit 477f4e9

21 files changed

Lines changed: 1180 additions & 61 deletions

devtools_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: This file stores settings for Dart & Flutter DevTools.
2+
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
3+
extensions:

lib/design/dimensions.dart

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
1-
// text
2-
const String connectionStatusConnected = 'ПОДКЛЮЧЕН';
3-
const String connectionStatusDisconnected = 'ОТКЛЮЧЕН';
4-
const String connectionStatusConnecting = 'ПОДКЛЮЧЕНИЕ';
5-
const String connectionStatusDisconnecting = 'ОТКЛЮЧЕНИЕ';
1+
import 'package:flutter/material.dart';
62

3+
class CustomString {
4+
final BuildContext context;
5+
late Locale locale;
6+
7+
CustomString(this.context) {
8+
locale = Localizations.localeOf(context);
9+
}
10+
11+
String get connected {
12+
return _localized('connected');
13+
}
14+
15+
String get disconnected {
16+
return _localized('disconnected');
17+
}
18+
19+
String get connecting {
20+
return _localized('connecting');
21+
}
22+
23+
String get disconnecting {
24+
return _localized('disconnecting');
25+
}
26+
27+
String get All_app{
28+
return _localized('all_apps');
29+
}
30+
31+
String _localized(String key) {
32+
switch (locale.languageCode) {
33+
case 'ru':
34+
return {
35+
'connected': 'ПОДКЛЮЧЕН',
36+
'disconnected': 'ОТКЛЮЧЕН',
37+
'connecting': 'ПОДКЛЮЧЕНИЕ',
38+
'disconnecting': 'ОТКЛЮЧЕНИЕ',
39+
"all_apps": "Все приложения",
40+
41+
42+
}[key]!;
43+
case 'th':
44+
return{
45+
"connected": "เชื่อมต่อแล้ว",
46+
"disconnected": "ไม่ได้เชื่อมต่อ",
47+
"connecting": "กำลังเชื่อมต่อ",
48+
"disconnecting": "กำลังตัดการเชื่อมต่อ",
49+
"all_apps": "แอปทั้งหมด",
50+
51+
52+
}[key]!;
53+
case 'en':
54+
default:
55+
return {
56+
'connected': 'CONNECTED',
57+
'disconnected': 'DISCONNECTED',
58+
'connecting': 'CONNECTING',
59+
'disconnecting': 'DISCONNECTING',
60+
"all_apps": "All Applications",
61+
62+
}[key]!;
63+
}
64+
}
65+
}
766
// style
867
const double elevation0 = 0;
968

lib/l10n/app_en.arb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"@@locale": "en",
3+
"app_name": "VPN Client",
4+
"apps_selection": "App Selection",
5+
"search": "Search",
6+
"your_location": "Your Location",
7+
"auto_select": "Auto Select",
8+
"kazakhstan": "Kazakhstan",
9+
"turkey": "Turkey",
10+
"poland": "Poland",
11+
"fastest": "Fastest",
12+
"selected_server": "Selected server",
13+
"server_selection": "Server selection",
14+
"all_servers": "All servers",
15+
"country_name": "Country name",
16+
"all_apps": "All Applications",
17+
"done": "Done",
18+
"cancel": "Cancel",
19+
"recently_searched": "Recently searched",
20+
"nothing_found": "Nothing found",
21+
"connected": "CONNECTED",
22+
"disconnected": "DISCONNECTED",
23+
"connecting": "CONNECTING",
24+
"disconnecting": "DISCONNECTING"
25+
26+
27+
28+
29+
30+
}
31+

lib/l10n/app_ru.arb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"@@locale": "ru",
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+
27+
28+
29+
30+
}

lib/l10n/app_th.arb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"@@locale": "th",
3+
"app_name": "VPN Client",
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+
27+
28+
29+
}
30+

lib/main.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_localizations/flutter_localizations.dart';
3+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
24
import 'package:provider/provider.dart';
5+
36
import 'package:vpn_client/pages/apps/apps_page.dart';
47
import 'package:vpn_client/pages/main/main_page.dart';
58
import 'package:vpn_client/pages/servers/servers_page.dart';
@@ -17,17 +20,36 @@ void main() {
1720
class App extends StatelessWidget {
1821
const App({super.key});
1922

23+
24+
2025
@override
2126
Widget build(BuildContext context) {
2227
final themeProvider = Provider.of<ThemeProvider>(context);
2328

29+
var language = const Locale('th');//<-- You can change language here manually
30+
2431
return MaterialApp(
2532
debugShowCheckedModeBanner: false,
2633
title: 'VPN Client',
2734
theme: lightTheme,
2835
darkTheme: darkTheme,
36+
locale: language,
2937
themeMode: themeProvider.themeMode,
3038
home: const MainScreen(),
39+
40+
41+
localizationsDelegates: const [
42+
AppLocalizations.delegate,
43+
GlobalMaterialLocalizations.delegate,
44+
GlobalWidgetsLocalizations.delegate,
45+
GlobalCupertinoLocalizations.delegate,
46+
],
47+
supportedLocales: const [
48+
Locale('en'),
49+
Locale('ru'),
50+
Locale('th'),
51+
52+
],
3153
);
3254
}
3355
}

lib/pages/apps/apps_list.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:shared_preferences/shared_preferences.dart';
3+
import 'package:vpn_client/design/dimensions.dart';
34
import 'apps_list_item.dart';
45
import 'dart:convert';
56

@@ -31,6 +32,21 @@ class AppsListState extends State<AppsList> {
3132
}
3233
}
3334

35+
late String Text_All_Apps;
36+
bool _initialized = false;
37+
38+
@override
39+
void didChangeDependencies() {
40+
super.didChangeDependencies();
41+
if (!_initialized) {
42+
final statusText = CustomString(context);
43+
Text_All_Apps = statusText.All_app;
44+
_loadApps();
45+
_initialized = true;
46+
}
47+
48+
}
49+
3450
@override
3551
void didUpdateWidget(covariant AppsList oldWidget) {
3652
super.didUpdateWidget(oldWidget);
@@ -47,13 +63,14 @@ class AppsListState extends State<AppsList> {
4763
setState(() {
4864
_isLoading = true;
4965
});
66+
5067

5168
try {
5269
List<Map<String, dynamic>> appsList = [
5370
{
5471
'icon': null,
5572
'image': null,
56-
'text': 'Все приложения',
73+
'text': Text_All_Apps,
5774
'isSwitch': true,
5875
'isActive': false,
5976
},

0 commit comments

Comments
 (0)