Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added flutter internationalizing #128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run the main I get an error because it looks like that the word dashboard doesn't have a translation in the Italian file, you can check the missing words by adding here untranslated-messages-file: missingWords.txt

5 changes: 5 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ const darkAccountColorList = [
darkAccount5,
];

const supportedLocales = [
Locale('en'),
Locale('it')
];

List<Color> categoryColorListTheme = categoryColorList;
List<Color> accountColorListTheme = accountColorList;

Expand Down
9 changes: 7 additions & 2 deletions lib/constants/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import '../constants/style.dart';
import '../model/transaction.dart';

mixin Functions {
String numToCurrency(num? value) {
String numToCurrency(num? value, String localeCode) {
if (value == null) return '';
return value.toStringAsFixed(2).replaceAll(".", ",");

//create formatter instance
final formatter = NumberFormat.currency(locale: localeCode, symbol: '');

//format and return value
return formatter.format(value);
}

num currencyToNum(String value) {
Expand Down
5 changes: 3 additions & 2 deletions lib/custom_widgets/account_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AccountDialog extends StatelessWidget with Functions {

@override
Widget build(BuildContext context) {
final Locale currentLocale = Localizations.localeOf(context);
return SingleChildScrollView(
child: Column(
children: [
Expand All @@ -38,7 +39,7 @@ class AccountDialog extends StatelessWidget with Functions {
),
const Padding(padding: EdgeInsets.all(12)),
Text(
numToCurrency(amount),
numToCurrency(amount, currentLocale.languageCode),
style: const TextStyle(
color: Color(0xffffffff),
fontSize: 32.0,
Expand Down Expand Up @@ -152,7 +153,7 @@ class AccountDialog extends StatelessWidget with Functions {
text: TextSpan(
children: [
TextSpan(
text: "-280,00",
text: numToCurrency(-280.00, currentLocale.languageCode),
style: Theme.of(context).textTheme.labelSmall),
TextSpan(
text: "€",
Expand Down
4 changes: 3 additions & 1 deletion lib/custom_widgets/accounts_sum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AccountsSum extends ConsumerWidget with Functions {

@override
Widget build(BuildContext context, WidgetRef ref) {
final Locale currentLocale = Localizations.localeOf(context);
return Container(
width: 160.0,
margin: const EdgeInsets.fromLTRB(0, 4, 16, 6),
Expand Down Expand Up @@ -95,7 +96,8 @@ class AccountsSum extends ConsumerWidget with Functions {
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(accountSum),
text: numToCurrency(accountSum,
currentLocale.languageCode),
style:
Theme.of(context).textTheme.titleSmall!.copyWith(color: darkBlue7),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/custom_widgets/budget_circular_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import '../constants/functions.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

/// This class shows account summaries in dashboard
class BudgetCircularIndicator extends StatelessWidget with Functions {
Expand All @@ -21,6 +22,7 @@ class BudgetCircularIndicator extends StatelessWidget with Functions {

@override
Widget build(BuildContext context) {
final Locale currentLocale = Localizations.localeOf(context);
return Column(
children: [
CircularPercentIndicator(
Expand All @@ -36,7 +38,7 @@ class BudgetCircularIndicator extends StatelessWidget with Functions {
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(amount),
text: numToCurrency(amount, currentLocale.languageCode),
style: Theme.of(context)
.textTheme
.titleMedium!
Expand All @@ -57,7 +59,7 @@ class BudgetCircularIndicator extends StatelessWidget with Functions {
),
const SizedBox(height: 6),
Text(
"LEFT",
AppLocalizations.of(context)!.left,
style: Theme.of(context).textTheme.labelLarge!.copyWith(color: Theme.of(context).colorScheme.primary),
),
],
Expand Down
5 changes: 3 additions & 2 deletions lib/custom_widgets/transactions_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TransactionTitle extends StatelessWidget with Functions {
@override
Widget build(BuildContext context) {
final color = sum >= 0 ? green : red;
final Locale currentLocale = Localizations.localeOf(context);
return Padding(
padding: EdgeInsets.only(top: first ? 0 : 24),
child: Column(
Expand All @@ -118,7 +119,7 @@ class TransactionTitle extends StatelessWidget with Functions {
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(sum),
text: numToCurrency(sum, currentLocale.languageCode),
style: Theme.of(context).textTheme.bodyLarge!.copyWith(color: color),
),
TextSpan(
Expand Down Expand Up @@ -244,7 +245,7 @@ class TransactionRow extends ConsumerWidget with Functions {
children: [
TextSpan(
text:
'${transaction.type == Type.expense ? "-" : ""}${numToCurrency(transaction.amount)}',
'${transaction.type == Type.expense ? "-" : ""}${numToCurrency(transaction.amount,'en_US')}',
style: Theme.of(context)
.textTheme
.labelLarge!
Expand Down
31 changes: 31 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"title": "Sossoldi",
"dashboard": "Dashboard",
"transactions": "Transactions",
"planning": "Planning",
"graphs": "Graphs",
"currentMonth": "Current month",
"lastMonth":"Last month",
"newAccount": "New Account",
"lastTransaction": "Last Transaction",
"yourBudgets": "Your budgets",
"yourAccounts":"Your accounts",
"monthlyBalance":"MONTHLY BALANCE",
"expenses": "EXPENSES",
"income": "INCOME",
"left": "LEFT",
"view": "view:",
"list": "List",
"categories": "Categories",
"accounts": "Accounts",
"monthlyBudget":"Monthly budget",
"manageBudgets":"Manage budgets",
"manage":"MANAGE",
"recurringPayments":"Recurring payments",
"progress": "Progress",
"composition":"Composition",
"addCategoryBudget": "Add category budget",
"planned": "PLANNED",
"recurrentSubTitle":"All recurring payments will be displayed here",
"addRecurring":"Add recurring payment"
}
30 changes: 30 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"title": "Sossoldi",
"transactions": "Transazioni",
"planning": "Pianificazione",
"graphs": "Grafici",
"currentMonth": "Mese corrente",
"lastMonth":"Ultimo mese",
"newAccount": "Nuovo Account",
"lastTransaction": "Ultima Transazione",
"yourBudgets": "Budgets",
"yourAccounts":"I tuoi account",
"monthlyBalance":"SALDO MENSILE",
"expenses": "SPESE",
"income": "ENTRATE",
"left": "Rimasto",
"view": "Vista:",
"list": "Lista",
"categories": "Categorie",
"accounts": "Accounts",
"monthlyBudget":"Budget mensile",
"manageBudgets":"Gestisci budget",
"manage":"Gestisci",
"recurringPayments":"Pagamenti ricorrenti",
"progress": "Progresso",
"composition":"Composizione",
"addCategoryBudget": "Aggiunti categoria al budget",
"planned": "PIANIFICATO",
"recurrentSubTitle":"Tutti i pagamenti ricorrenti saranno mostrati qui",
"addRecurring":"Aggiunti pagamento ricorrente"
}
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sossoldi/providers/theme_provider.dart';
import 'package:sossoldi/utils/app_theme.dart';
import 'routes.dart';
import 'package:intl/date_symbol_data_local.dart';

import 'package:flutter_gen/gen_l10n/app_localizations.dart';
void main() {
initializeDateFormatting('it_IT', null)
.then((_) => runApp(const ProviderScope(child: Launcher())));
Expand All @@ -24,6 +25,8 @@ class Launcher extends ConsumerWidget {
themeMode:
appThemeState.isDarkModeEnabled ? ThemeMode.dark : ThemeMode.light,
onGenerateRoute: makeRoute,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
initialRoute: '/',
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/account_page/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _AccountPage extends ConsumerState<AccountPage> with Functions {
Widget build(BuildContext context) {
final accountName = ref.read(accountNameProvider);
final accountAmount = ref.read(accountStartingValueProvider);

final Locale currentLocale = Localizations.localeOf(context);
return Scaffold(
appBar: AppBar(
title: Text(accountName ?? "", style: const TextStyle(color: white)),
Expand All @@ -35,7 +35,7 @@ class _AccountPage extends ConsumerState<AccountPage> with Functions {
child: Column(
children: [
Text(
numToCurrency(accountAmount),
numToCurrency(accountAmount,currentLocale.languageCode),
style: const TextStyle(
color: white,
fontSize: 32.0,
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/add_page/add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class _AddPageState extends ConsumerState<AddPage> with Functions {

@override
void initState() {
Locale currentLocale = Localizations.localeOf(context);
amountController.text =
numToCurrency(ref.read(selectedTransactionUpdateProvider)?.amount);
numToCurrency(ref.read(selectedTransactionUpdateProvider)?.amount,
currentLocale.languageCode);
noteController.text =
ref.read(selectedTransactionUpdateProvider)?.note ?? '';
super.initState();
Expand Down Expand Up @@ -58,6 +60,8 @@ class _AddPageState extends ConsumerState<AddPage> with Functions {
final trnscTypes = ref.watch(transactionTypesProvider);
final selectedTransaction = ref.watch(selectedTransactionUpdateProvider);
final selectedType = trsncTypeList[trnscTypes.indexOf(true)];
final selectedRecurringPay = ref.watch(selectedRecurringPayProvider);

// I listen servono a evitare che il provider faccia il dispose subito dopo essere stato aggiornato
ref.listen(amountProvider, (_, __) {});
ref.listen(noteProvider, (_, __) {});
Expand Down
30 changes: 17 additions & 13 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../constants/style.dart';
import '../model/bank_account.dart';
import '../custom_widgets/accounts_sum.dart';
import '../custom_widgets/line_chart.dart';

import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class HomePage extends ConsumerStatefulWidget {
const HomePage({super.key});

Expand All @@ -23,6 +23,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
Widget build(BuildContext context) {
final accountList = ref.watch(accountsProvider);
final transactionList = ref.watch(transactionsProvider);
final Locale currentLocale = Localizations.localeOf(context);
return ListView(
children: [
Column(
Expand All @@ -35,7 +36,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"MONTHLY BALANCE",
AppLocalizations.of(context)!.monthlyBalance,
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: Theme.of(context).colorScheme.primary),
),
Expand All @@ -44,7 +45,8 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(-1536.65),
text: numToCurrency(-1536.65,
currentLocale.languageCode),
style: Theme.of(context)
.textTheme
.headlineLarge
Expand All @@ -71,15 +73,16 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"INCOME",
AppLocalizations.of(context)!.income,
style: Theme.of(context).textTheme.labelMedium,
),
RichText(
textScaleFactor: MediaQuery.of(context).textScaleFactor,
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(1050.65),
text: numToCurrency(1050.65,
currentLocale.languageCode),
style: Theme.of(context)
.textTheme
.bodyMedium
Expand All @@ -102,15 +105,16 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"EXPENSES",
AppLocalizations.of(context)!.expenses,
style: Theme.of(context).textTheme.labelMedium,
),
RichText(
textScaleFactor: MediaQuery.of(context).textScaleFactor,
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(-1050.65),
text: numToCurrency(-1050.65,
currentLocale.languageCode),
style: Theme.of(context)
.textTheme
.bodyMedium
Expand Down Expand Up @@ -204,7 +208,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
),
const SizedBox(width: 4),
Text(
"Current month",
AppLocalizations.of(context)!.currentMonth,
style: Theme.of(context)
.textTheme
.labelMedium
Expand All @@ -221,7 +225,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
),
const SizedBox(width: 4),
Text(
"Last month",
AppLocalizations.of(context)!.lastMonth,
style: Theme.of(context)
.textTheme
.labelMedium
Expand All @@ -248,7 +252,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
Padding(
padding: const EdgeInsets.fromLTRB(16, 24, 16, 8),
child: Text(
"Your accounts",
AppLocalizations.of(context)!.yourAccounts,
style: Theme.of(context).textTheme.titleLarge,
),
),
Expand Down Expand Up @@ -297,7 +301,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
),
),
label: Text(
"New Account",
AppLocalizations.of(context)!.newAccount,
style: Theme.of(context)
.textTheme
.bodyLarge!
Expand Down Expand Up @@ -328,7 +332,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 32, 16, 8),
child: Text(
"Last transactions",
AppLocalizations.of(context)!.lastTransaction,
style: Theme.of(context).textTheme.titleLarge,
),
),
Expand All @@ -345,7 +349,7 @@ class _HomePageState extends ConsumerState<HomePage> with Functions {
child: Padding(
padding: const EdgeInsets.only(left: 16),
child: Text(
"Your budgets",
AppLocalizations.of(context)!.yourBudgets,
style: Theme.of(context).textTheme.titleLarge,
),
),
Expand Down
Loading
Loading