Localization

main
Serdar1112 2023-06-14 02:46:11 +02:00
parent 392a02b38d
commit 51b311f933
7 changed files with 154 additions and 40 deletions

View File

@ -27,7 +27,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion flutter.compileSdkVersion compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion ndkVersion "25.1.8937393"
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8

View File

@ -0,0 +1,24 @@
{
"title" : "Finanzplaner",
"delete" : "Löschen",
"deleteaccount" : "Account Löschen",
"sure" : "Sind Sie sicher, dass Sie dieses Konto löschen möchten?",
"balance" : "Bilanz",
"addaccount" : "Konto hinzufügen",
"entername" : "Bitte geben Sie einen Namen ein",
"enterbalance" : "Bitte geben Sie einen Saldo ein",
"entervalidnumber" : "Bitte geben Sie eine gültige Nummer ein",
"cancel" : "Abbrechen",
"add" : "Hinzufügen",
"income": "Einnahmen",
"expenditures": "Ausgaben",
"addtrans": "Transaktion hinzufügen",
"entertitle": "Bitte geben Sie einen Titel ein",
"amount": "Betrag",
"enteramount": "Bitte geben Sie einen Betrag ein",
"expense": "Ausgabe",
"settings": "Einstellungen",
"darkmode": "Dunkel Modus",
"language": "Sprache",
"currency": "Währung"
}

View File

@ -0,0 +1,24 @@
{
"title" : "Financial Planner",
"delete" : "Delete",
"deleteaccount" : "Delete Account",
"sure" : "Are you sure you want to delete this account?",
"balance" : "Balance",
"addaccount" : "Add Account",
"entername" : "Please enter a name",
"enterbalance" : "Please enter a balance",
"entervalidnumber" : "Please enter a valid number",
"cancel" : "Cancel",
"add" : "Add",
"income": "Income",
"expenditures": "Expenditures",
"addtrans": "Add Transaction",
"entertitle": "Please enter a title",
"amount": "Amount",
"enteramount": "Please enter an amount",
"expense": "Expense",
"settings": "Settings",
"darkmode": "Dark Mode",
"language": "Language",
"currency": "Currency"
}

View File

@ -8,10 +8,17 @@ import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:tests/preferences.dart'; import 'package:tests/preferences.dart';
import 'package:tests/theme/theme_constants.dart'; import 'package:tests/theme/theme_constants.dart';
import 'package:tests/theme/theme_manager.dart'; import 'package:tests/theme/theme_manager.dart';
import "package:easy_localization/easy_localization.dart";
void main() { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const FinancialPlannerApp()); await EasyLocalization.ensureInitialized();
runApp(EasyLocalization(
supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
path: 'lib/assets/translations', // <-- change the path of the translation files
fallbackLocale: Locale('en', 'US'),
child: const FinancialPlannerApp()
),);
} }
ThemeManager _themeManager = ThemeManager(); ThemeManager _themeManager = ThemeManager();
@ -21,8 +28,11 @@ class FinancialPlannerApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'Financial Planner', title: 'title'.tr(),
theme: lightTheme, theme: lightTheme,
darkTheme: darkTheme, darkTheme: darkTheme,
themeMode: _themeManager.themeMode, themeMode: _themeManager.themeMode,
@ -102,9 +112,9 @@ class HomePageState extends State<HomePage> {
centerTitle: true, centerTitle: true,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
elevation: 0, elevation: 0,
title: const Text( title: Text(
'Financial Planner', 'title'.tr(),
style: TextStyle( style: const TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.black54, color: Colors.black54,
@ -114,11 +124,15 @@ class HomePageState extends State<HomePage> {
Padding( Padding(
padding: const EdgeInsets.only(right: 16.0, top: 3, bottom: 7), padding: const EdgeInsets.only(right: 16.0, top: 3, bottom: 7),
child: NeumorphicButton( child: NeumorphicButton(
onPressed: () { onPressed: () async {
Navigator.push(
String value = await Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => Settings()), MaterialPageRoute(builder: (context) => Settings()),
); );
setState(() {
});
}, },
style: NeumorphicStyle( style: NeumorphicStyle(
shape: NeumorphicShape.convex, shape: NeumorphicShape.convex,
@ -139,15 +153,15 @@ class HomePageState extends State<HomePage> {
return GestureDetector( return GestureDetector(
onLongPress: () { onLongPress: () {
AwesomeDialog( AwesomeDialog(
btnOkText: "Delete", btnOkText: "Delete".tr(),
btnOkColor: Colors.lightGreen, btnOkColor: Colors.lightGreen,
btnCancelColor: Colors.grey, btnCancelColor: Colors.grey,
context: context, context: context,
animType: AnimType.bottomSlide, animType: AnimType.bottomSlide,
dialogType: DialogType.info, dialogType: DialogType.info,
title: 'Delete Account', title: 'deleteaccount'.tr(),
headerAnimationLoop: false, headerAnimationLoop: false,
desc: 'Are you sure you want to delete this account?', desc: 'sure'.tr(),
btnCancelOnPress: () {}, btnCancelOnPress: () {},
btnOkOnPress: () { btnOkOnPress: () {
deleteAccount(accounts[index]); deleteAccount(accounts[index]);
@ -166,7 +180,7 @@ class HomePageState extends State<HomePage> {
), ),
child: ListTile( child: ListTile(
title: Text(accounts[index].name), title: Text(accounts[index].name),
subtitle: Text('Balance: \$${accounts[index].balance.toStringAsFixed(2)}'), subtitle: Text('${'balance'.tr()}: \$${accounts[index].balance.toStringAsFixed(2)}'),
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
@ -274,8 +288,8 @@ class AddAccountDialogState extends State<AddAccountDialog> {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),
), ),
title: const Text( title: Text(
'Add Account', 'addaccount'.tr(),
), ),
titleTextStyle: TextStyle( titleTextStyle: TextStyle(
color: Colors.black54, color: Colors.black54,
@ -304,7 +318,7 @@ class AddAccountDialogState extends State<AddAccountDialog> {
), ),
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return 'Please enter a name'; return 'entername'.tr();
} }
return null; return null;
}, },
@ -323,17 +337,17 @@ class AddAccountDialogState extends State<AddAccountDialog> {
child: TextFormField( child: TextFormField(
controller: _balanceController, controller: _balanceController,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Balance', labelText: 'balance'.tr(),
border: InputBorder.none, border: InputBorder.none,
contentPadding: EdgeInsets.fromLTRB(12, 16, 12, 16), contentPadding: EdgeInsets.fromLTRB(12, 16, 12, 16),
), ),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return 'Please enter a balance'; return 'enterbalance'.tr();
} }
if (double.tryParse(value) == null) { if (double.tryParse(value) == null) {
return 'Please enter a valid number'; return 'entervalidnumber'.tr();
} }
return null; return null;
}, },
@ -358,7 +372,7 @@ class AddAccountDialogState extends State<AddAccountDialog> {
), ),
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16), padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text( child: Text(
'Cancel', 'cancel'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -378,7 +392,7 @@ class AddAccountDialogState extends State<AddAccountDialog> {
), ),
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16), padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text( child: Text(
'Add', 'add'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -533,9 +547,9 @@ class AccountDetailPageState extends State<AccountDetailPage> with SingleTickerP
TabBar( TabBar(
controller: _tabController, controller: _tabController,
labelColor: Colors.black, labelColor: Colors.black,
tabs: const [ tabs: [
Tab(text: 'Einnahmen'), Tab(text: 'income'.tr()),
Tab(text: 'Ausgaben'), Tab(text: 'expenditures'.tr()),
], ],
), ),
Expanded( Expanded(
@ -702,7 +716,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),
), ),
title: Text( title: Text(
'Add Transaction', 'addtrans'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
color: Colors.black54, color: Colors.black54,
@ -732,7 +746,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
), ),
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return 'Please enter a title'; return 'entertitle'.tr();
} }
return null; return null;
}, },
@ -751,7 +765,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
child: TextFormField( child: TextFormField(
controller: _amountController, controller: _amountController,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Amount', labelText: 'amount'.tr(),
border: InputBorder.none, border: InputBorder.none,
contentPadding: EdgeInsets.symmetric( contentPadding: EdgeInsets.symmetric(
vertical: 12, vertical: 12,
@ -761,10 +775,10 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return 'Please enter an amount'; return 'enteramount'.tr();
} }
if (double.tryParse(value) == null) { if (double.tryParse(value) == null) {
return 'Please enter a valid number'; return 'entervalidnumber'.tr();
} }
return null; return null;
}, },
@ -783,7 +797,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
}, },
), ),
SizedBox(width: 8), SizedBox(width: 8),
Text('Expense', style: TextStyle(color: Colors.black87),), Text('expense'.tr(), style: TextStyle(color: Colors.black87),),
], ],
), ),
], ],
@ -804,7 +818,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
), ),
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16), padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text( child: Text(
'Cancel', 'cancel'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -824,7 +838,7 @@ class AddTransactionDialogState extends State<AddTransactionDialog> {
), ),
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16), padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text( child: Text(
'Add', 'add'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

View File

@ -1,3 +1,4 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart'; import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:tests/theme/theme_manager.dart'; import 'package:tests/theme/theme_manager.dart';
@ -18,6 +19,15 @@ class SettingsState extends State<Settings> {
final List<String> _languages = ['English', 'Deutsch']; final List<String> _languages = ['English', 'Deutsch'];
final List<String> _currencies = ['Euro', 'Dollar', 'CHF']; final List<String> _currencies = ['Euro', 'Dollar', 'CHF'];
void checkForLanguage(BuildContext context){
String language = context.locale.toString();
print(language);
switch(language){
case "en_US": _selectedLanguage = "English"; break;
case "de_DE": _selectedLanguage = "Deutsch"; break;
}
}
@override @override
void dispose() { void dispose() {
_themeManager.removeListener(themeListener); _themeManager.removeListener(themeListener);
@ -34,18 +44,21 @@ class SettingsState extends State<Settings> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_themeManager.addListener(themeListener); _themeManager.addListener(themeListener);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
checkForLanguage(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
elevation: 0, elevation: 0,
toolbarHeight: 80, toolbarHeight: 80,
title: Text( title: Text(
'Settings', 'settings'.tr(),
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -64,7 +77,8 @@ class SettingsState extends State<Settings> {
padding: const EdgeInsets.only(left: 16.0), padding: const EdgeInsets.only(left: 16.0),
child: NeumorphicButton( child: NeumorphicButton(
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context, "Change");
}, },
style: NeumorphicStyle( style: NeumorphicStyle(
shape: NeumorphicShape.flat, shape: NeumorphicShape.flat,
@ -90,7 +104,7 @@ class SettingsState extends State<Settings> {
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)), boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)),
), ),
child: ListTile( child: ListTile(
title: const Text('Dark Mode'), title: Text('darkmode'.tr()),
trailing: NeumorphicSwitch( trailing: NeumorphicSwitch(
value: _themeManager.themeMode == ThemeMode.dark, value: _themeManager.themeMode == ThemeMode.dark,
onChanged: (bool value) { onChanged: (bool value) {
@ -122,12 +136,17 @@ class SettingsState extends State<Settings> {
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)), boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)),
), ),
child: ListTile( child: ListTile(
title: const Text('Language'), title: Text('language'.tr()),
trailing: DropdownButton<String>( trailing: DropdownButton<String>(
value: _selectedLanguage, value: _selectedLanguage,
onChanged: (String? newValue) { onChanged: (String? newValue) {
setState(() { setState(() {
_selectedLanguage = newValue!; _selectedLanguage = newValue!;
switch(_selectedLanguage){
case "English": context.setLocale(Locale('en', 'US')); break;
case "Deutsch": context.setLocale(Locale('de', 'DE')); break;
}
// Hier kannst du die Spracheinstellung entsprechend anpassen // Hier kannst du die Spracheinstellung entsprechend anpassen
// z.B. mit einer Funktion, die die App-Sprache ändert. // z.B. mit einer Funktion, die die App-Sprache ändert.
}); });
@ -151,7 +170,7 @@ class SettingsState extends State<Settings> {
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)), boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)),
), ),
child: ListTile( child: ListTile(
title: const Text('Currency'), title: Text('currency'.tr()),
trailing: DropdownButton<String>( trailing: DropdownButton<String>(
value: _selectedCurrency, value: _selectedCurrency,
onChanged: (String? newValue) { onChanged: (String? newValue) {

View File

@ -1,6 +1,14 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
args:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.2"
async: async:
dependency: transitive dependency: transitive
description: description:
@ -73,6 +81,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
easy_localization:
dependency: "direct main"
description:
name: easy_localization
sha256: "30ebf25448ffe169e0bd9bc4b5da94faa8398967a2ad2ca09f438be8b6953645"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
easy_logger:
dependency: transitive
description:
name: easy_logger
sha256: c764a6e024846f33405a2342caf91c62e357c24b02c04dbc712ef232bf30ffb7
url: "https://pub.dev"
source: hosted
version: "0.0.2"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -110,6 +134,11 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_localizations:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_neumorphic: flutter_neumorphic:
dependency: "direct main" dependency: "direct main"
description: description:
@ -385,10 +414,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: syncfusion_flutter_core name: syncfusion_flutter_core
sha256: "4aa69e3541d38810533b1455aa38997a89755f9928e16ef813b62b2e8bcc398c" sha256: "8db8f55c77f56968681447d3837c10f27a9e861e238a898fda116c7531def979"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "21.2.9" version: "21.2.10"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:

View File

@ -39,6 +39,7 @@ dependencies:
syncfusion_flutter_charts: ^21.2.4 syncfusion_flutter_charts: ^21.2.4
flutter_neumorphic: ^3.2.0 flutter_neumorphic: ^3.2.0
awesome_dialog: ^3.1.0 awesome_dialog: ^3.1.0
easy_localization: ^3.0.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -62,6 +63,9 @@ flutter:
# the material Icons class. # the material Icons class.
uses-material-design: true uses-material-design: true
assets:
- lib/assets/translations/
fonts: fonts:
- family: Montserrat - family: Montserrat
fonts: fonts: