Skip to content

Commit

Permalink
fix some nasty bugs and add internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
mytja committed Nov 12, 2023
1 parent 0270832 commit ed9571f
Show file tree
Hide file tree
Showing 20 changed files with 1,170 additions and 765 deletions.
20 changes: 8 additions & 12 deletions tarok/lib/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tarok/constants.dart';

class About extends StatefulWidget {
class About extends StatelessWidget {
const About({super.key});

@override
State<About> createState() => _AboutState();
}

class _AboutState extends State<About> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("Palčka"),
title: Text("palcka".tr),
actions: [
IconButton(
icon: const Icon(Icons.cancel),
Expand All @@ -39,14 +35,14 @@ class _AboutState extends State<About> {
),
],
),
body: const Center(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Tarok Palčka", style: TextStyle(fontSize: 40)),
Text("Copyright 2023 Mitja Ševerkar"),
Text("Licencirano pod AGPLv3 licenco."),
Text("Verzija $RELEASE"),
Text("tarock_palcka".tr, style: const TextStyle(fontSize: 40)),
Text("copyright".tr),
Text("licensed_under".tr),
Text("version".trParams({"version": RELEASE})),
],
),
),
Expand Down
56 changes: 27 additions & 29 deletions tarok/lib/admin/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Users extends StatelessWidget {
onPressed: () async {
await controller.getUsers();
},
child: const Text("Osveži podatke"),
child: Text("refresh_data".tr),
),
),
const SizedBox(
Expand All @@ -49,68 +49,68 @@ class Users extends StatelessWidget {
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: const <DataColumn>[
columns: <DataColumn>[
DataColumn(
label: Expanded(
child: Text(
'Uporabniški ID',
style: TextStyle(fontStyle: FontStyle.italic),
"user_id".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Ime',
style: TextStyle(fontStyle: FontStyle.italic),
"name".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Elektronski naslov',
style: TextStyle(fontStyle: FontStyle.italic),
"email".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Odigranih iger',
style: TextStyle(fontStyle: FontStyle.italic),
"played_games".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Rola',
style: TextStyle(fontStyle: FontStyle.italic),
"role".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Onemogočen račun',
style: TextStyle(fontStyle: FontStyle.italic),
"account_disabled".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Preverjen elektronski naslov',
style: TextStyle(fontStyle: FontStyle.italic),
"verified_email".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
DataColumn(
label: Expanded(
child: Text(
'Registriran dne',
style: TextStyle(fontStyle: FontStyle.italic),
"registered_on".tr,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
),
Expand All @@ -132,13 +132,13 @@ class Users extends StatelessWidget {
controller.controller.value.text = m.name;
Get.dialog(
AlertDialog(
title: const Text(
"Sprememba uporabnikovega imena"),
title: Text("change_user_name".tr),
content: IntrinsicHeight(
child: Column(
children: [
Text(
"Uporabnikovo trenutno ime je ${m.name}."),
Text("user_current_name"
.trParams(
{"name": m.name})),
TextField(
controller: controller
.controller.value,
Expand All @@ -151,20 +151,20 @@ class Users extends StatelessWidget {
onPressed: () async {
Get.back();
},
child: const Text("Prekliči"),
child: Text("cancel".tr),
),
TextButton(
onPressed: () async {
await controller
.changeName(m.userId);
Get.back();
},
child: const Text("Spremeni"),
child: Text("change".tr),
),
]),
);
},
child: const Text("Spremeni ime"),
child: Text("change_user_name".tr),
),
],
),
Expand All @@ -184,10 +184,8 @@ class Users extends StatelessWidget {
.promoteDemoteUser(m.userId);
},
child: m.role == "admin"
? const Text(
"Pretvori administratorja v uporabnika")
: const Text(
"Pretvori uporabnika v administratorja"),
? Text("admin_to_user".tr)
: Text("user_to_admin".tr),
),
],
),
Expand Down
61 changes: 39 additions & 22 deletions tarok/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:media_kit/media_kit.dart';
import 'package:stockskis/stockskis.dart';
import 'package:tarok/lobby/lobby_controller.dart';

part 'constants.g.dart';

Expand All @@ -31,7 +32,7 @@ const WS_URL =
kReleaseMode ? "wss://palcka.si/api/ws" : "ws://localhost:8080/ws";
const LOBBY_WS_URL =
kReleaseMode ? "wss://palcka.si/api/lobby" : "ws://localhost:8080/lobby";
const RELEASE = "DEBUG";
const RELEASE = "0.0.5 Beta";
bool OMOGOCI_STOCKSKIS_PREDLOGE = true;
bool SLEPI_TAROK = false;
bool AVTOPOTRDI_ZALOZITEV = false;
Expand All @@ -40,6 +41,7 @@ bool PREMOVE = false;
bool DEVELOPER_MODE = false;
bool SKISFANG = false;
String THEME = "";
Locale LOCALE = Get.deviceLocale ?? const Locale("sl", "SI");

const double ANGLE = 25;
const int ANIMATION_TIME = 75;
Expand Down Expand Up @@ -85,12 +87,12 @@ final List<LocalCard> KINGS = [
LocalCard(asset: "/src/kralj", worth: 5, worthOver: 8, alt: "Src kralj"),
];

const List<String> KONTRE = [
"Ni kontre",
"Kontra",
"Rekontra",
"Subkontra",
"Mortkontra",
List<String> KONTRE = [
"no_kontra".tr,
"kontra".tr,
"rekontra".tr,
"subkontra".tr,
"mortkontra".tr,
];

const List<String> BOT_NAMES = [
Expand All @@ -116,11 +118,11 @@ const List<String> BOT_NAMES = [
"Žiga",
];

const BOTS = [
List BOTS = [
{
"type": "normalni",
"preferred_names": BOT_NAMES,
"name": "Normalni boti",
"name": "normal_bots".tr,
},
{
"type": "vrazji",
Expand All @@ -135,7 +137,7 @@ const BOTS = [
"Žiga",
"Mark",
],
"name": "Vražji boti",
"name": "advanced_bots".tr,
},
{
"type": "berac",
Expand All @@ -145,7 +147,7 @@ const BOTS = [
"Marko",
"Lojze",
],
"name": "Berač boti",
"name": "beggar_bots".tr,
},
{
"type": "klop",
Expand All @@ -155,7 +157,7 @@ const BOTS = [
"Marija",
"Marko",
],
"name": "Klop boti",
"name": "klop_bots".tr,
},
];

Expand All @@ -168,15 +170,30 @@ int hashCode(String str) {
}

Future<void> logout() async {
await dio.post(
'$BACKEND_URL/logout',
options: Options(
headers: {"X-Login-Token": await storage.read(key: "token")},
validateStatus: (s) {
return true;
},
),
);
String? token = await storage.read(key: "token");
if (!(token == "a" || token == "" || token == null)) {
try {
await dio.post(
'$BACKEND_URL/logout',
options: Options(
headers: {"X-Login-Token": token},
validateStatus: (s) {
return true;
},
),
);
} catch (e) {}
}
await storage.deleteAll();
Get.toNamed("/login");
await Get.toNamed("/login");
await Get.delete<LobbyController>();
}

void parseLocale(String? locale) {
if (locale == null) return;
List locales = locale.split("_");
LOCALE = Locale(
locales[0].toString().toLowerCase(),
locales[1].toString().toUpperCase(),
);
}
Loading

0 comments on commit ed9571f

Please sign in to comment.