diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 6b40475..09f0538 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -59,6 +59,8 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CFACD96C23E07D4800D7C471 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Main.strings; sourceTree = ""; }; + CFACD96D23E07D4800D7C471 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/LaunchScreen.strings; sourceTree = ""; }; CFF572AC227F58EC009AA360 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Downloads/GoogleService-Info.plist"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -200,6 +202,7 @@ English, en, Base, + es, ); mainGroup = 97C146E51CF9000F007C117D; productRefGroup = 97C146EF1CF9000F007C117D /* Products */; @@ -328,6 +331,7 @@ isa = PBXVariantGroup; children = ( 97C146FB1CF9000F007C117D /* Base */, + CFACD96C23E07D4800D7C471 /* es */, ); name = Main.storyboard; sourceTree = ""; @@ -336,6 +340,7 @@ isa = PBXVariantGroup; children = ( 97C147001CF9000F007C117D /* Base */, + CFACD96D23E07D4800D7C471 /* es */, ); name = LaunchScreen.storyboard; sourceTree = ""; diff --git a/ios/Runner/es.lproj/LaunchScreen.strings b/ios/Runner/es.lproj/LaunchScreen.strings new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ios/Runner/es.lproj/LaunchScreen.strings @@ -0,0 +1 @@ + diff --git a/ios/Runner/es.lproj/Main.strings b/ios/Runner/es.lproj/Main.strings new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ios/Runner/es.lproj/Main.strings @@ -0,0 +1 @@ + diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..df29e2b --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,31 @@ +home: + emptyList: Add an expense to begin +add: + category: Category + today: Today + categories: + - Shoppint + - Alcohol + - Fast food + - Bills + - Transport + - Other + currency: $ + add: Add expense +settings: + title: Settings + dark_mode: Use dark mode? + signout: Sign Out +months: + jan: January + feb: February + mar: March + apr: April + may: May + jun: June + jul: July + aug: August + sep: September + oct: October + nov: November + dec: December \ No newline at end of file diff --git a/lang/es.yml b/lang/es.yml new file mode 100644 index 0000000..0e5247a --- /dev/null +++ b/lang/es.yml @@ -0,0 +1,31 @@ +home: + emptyList: Agregue un gasto para comenzar +add: + category: Categoría + today: Hoy + categories: + - Compras + - Alcohol + - Comida Rápida + - Facturas + - Transporte + - Otros + currency: $ + add: Agregar Gasto +settings: + title: Opciones + dark_mode: Usar modo oscuro? + signout: Salir +months: + jan: Enero + feb: Febrero + mar: Marzo + apr: Abril + may: Mayo + jun: Junio + jul: Julio + aug: Agosto + sep: Septiembre + oct: Octubre + nov: Noviembre + dec: Diciembre \ No newline at end of file diff --git a/lib/como_gasto_localizations.dart b/lib/como_gasto_localizations.dart new file mode 100644 index 0000000..18c2ad3 --- /dev/null +++ b/lib/como_gasto_localizations.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:yaml/yaml.dart'; + +class ComoGastoLocalizations { + final String localeName; + + ComoGastoLocalizations(this.localeName); + + static const LocalizationsDelegate delegate = + _ComoGastoLocalizationsDelegate(); + + YamlMap translations; + YamlMap translationsFallback; + + Future load() async { + String yamlString = await rootBundle.loadString('lang/$localeName.yml'); + translations = loadYaml(yamlString); + + String yamlString1 = await rootBundle.loadString('lang/en.yml'); + translationsFallback = loadYaml(yamlString1); + } + + dynamic t(String key) { + try { + var keys = key.split("."); + dynamic translated = translations; + keys.forEach((k) => translated = translated[k]); + + if (translated == null) { + return _fallback(key); + } + return translated; + } catch (e) { + return _fallback(key); + } + } + + dynamic _fallback(String key) { + try { + var keys = key.split("."); + dynamic translated = translationsFallback; + keys.forEach((k) => translated = translated[k]); + + if (translated == null) { + return "Key not found....: $key"; + } + return translated; + } catch (e) { + return "Key not found: $key"; + } + } + + static ComoGastoLocalizations of(BuildContext context) { + return Localizations.of( + context, ComoGastoLocalizations); + } +} + +class _ComoGastoLocalizationsDelegate + extends LocalizationsDelegate { + const _ComoGastoLocalizationsDelegate(); + + @override + bool isSupported(Locale locale) { + print(locale.languageCode); + return ['es', 'en'].contains(locale.languageCode); + } + + @override + Future load(Locale locale) async { + var t = ComoGastoLocalizations(locale.languageCode); + await t.load(); + return t; + } + + @override + bool shouldReload(LocalizationsDelegate old) { + return false; + } +} diff --git a/lib/main.dart b/lib/main.dart index 9e168dd..4d64024 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,8 +6,10 @@ import 'package:como_gasto/pages/details_page_container.dart'; import 'package:como_gasto/pages/home_page.dart'; import 'package:como_gasto/pages/login_page.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:provider/provider.dart'; +import 'como_gasto_localizations.dart'; import 'expenses_repository.dart'; import 'states/theme_state.dart'; @@ -73,6 +75,16 @@ class MyApp extends StatelessWidget { } }, }, + supportedLocales: [ + Locale('en'), + Locale('es'), + ], + localizationsDelegates: [ + ComoGastoLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], ); }, ), diff --git a/lib/pages/add_page.dart b/lib/pages/add_page.dart index 0825e62..0810fcb 100644 --- a/lib/pages/add_page.dart +++ b/lib/pages/add_page.dart @@ -1,11 +1,13 @@ import 'dart:io'; +import 'package:como_gasto/como_gasto_localizations.dart'; import 'package:como_gasto/others/category_selection_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:image_picker/image_picker.dart'; import 'package:provider/provider.dart'; import 'package:local_auth/local_auth.dart'; +import 'package:yaml/yaml.dart'; import '../como_gasto_icons.dart'; import '../expenses_repository.dart'; @@ -27,7 +29,7 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { String category; int value = 0; - String dateStr = "hoy"; + String dateStr = null; DateTime date = DateTime.now(); File _selectedPicture; @@ -71,6 +73,11 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { @override Widget build(BuildContext context) { + ComoGastoLocalizations localizations = ComoGastoLocalizations.of(context); + if (dateStr == null) { + dateStr = localizations.t('add.today'); + } + var h = MediaQuery.of(context).size.height; return Stack( children: [ @@ -88,7 +95,7 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { backgroundColor: Colors.transparent, elevation: 0.0, title: Text( - "Category ($dateStr)", + "${localizations.t('add.category')} ($dateStr)", style: TextStyle( color: Colors.grey, ), @@ -130,25 +137,25 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { ) ], ), - body: _body(), + body: _body(localizations), ), ), - _submit(), + _submit(localizations), ], ); } - Widget _body() { + Widget _body(ComoGastoLocalizations localizations) { var h = MediaQuery.of(context).size.height; return Column( children: [ - _categorySelector(), + _categorySelector(localizations), if (_selectedPicture != null) SizedBox( height: 100, child: Image.file(_selectedPicture), ), - _currentValue(), + _currentValue(localizations), _numpad(), SizedBox( height: h - widget.buttonRect.top, @@ -157,30 +164,33 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { ); } - Widget _categorySelector() { + Widget _categorySelector(ComoGastoLocalizations localizations) { + YamlList categories = localizations.t('add.categories'); + print(categories); + return Container( height: 80.0, child: CategorySelectionWidget( categories: { - "Shopping": Icons.shopping_cart, - "Alcohol": FontAwesomeIcons.beer, - "Fast food": FontAwesomeIcons.hamburger, - "Bills": FontAwesomeIcons.wallet, - "Transport": FontAwesomeIcons.carAlt, - "Other": FontAwesomeIcons.infinity, + categories[0]: Icons.shopping_cart, + categories[1]: FontAwesomeIcons.beer, + categories[2]: FontAwesomeIcons.hamburger, + categories[3]: FontAwesomeIcons.wallet, + categories[4]: FontAwesomeIcons.carAlt, + categories[5]: FontAwesomeIcons.infinity, }, onValueChanged: (newCategory) => category = newCategory, ), ); } - Widget _currentValue() { + Widget _currentValue(ComoGastoLocalizations localizations) { var realValue = value / 100.0; return Padding( padding: const EdgeInsets.symmetric(vertical: 32.0), child: Text( - "\$${realValue.toStringAsFixed(2)}", + "${localizations.t('add.currency')}${realValue.toStringAsFixed(2)}", style: TextStyle( fontSize: 50.0, color: Colors.blueAccent, @@ -271,7 +281,7 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { ); } - Widget _submit() { + Widget _submit(ComoGastoLocalizations localizations) { if (_controller.value < 1) { var buttonWidth = widget.buttonRect.right - widget.buttonRect.left; var w = MediaQuery.of(context).size.width; @@ -298,7 +308,7 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { child: MaterialButton( onPressed: () {}, child: Text( - "Add expense", + localizations.t("add.add"), style: TextStyle( color: Colors.white, fontSize: 20.0, @@ -321,7 +331,7 @@ class _AddPageState extends State with SingleTickerProviderStateMixin { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - "Add expense", + localizations.t("add.add"), style: TextStyle( color: Colors.white, fontSize: 20.0, diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index c185a35..5780a52 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,5 +1,6 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:como_gasto/como_gasto_icons.dart'; +import 'package:como_gasto/como_gasto_localizations.dart'; import 'package:como_gasto/others/month_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -99,10 +100,11 @@ class _HomePageState extends State { } Widget _body() { + ComoGastoLocalizations localizations = Localizations.of(context, ComoGastoLocalizations); return SafeArea( child: Column( children: [ - _selector(), + _selector(localizations), StreamBuilder( stream: _query, builder: (BuildContext context, AsyncSnapshot data) { @@ -122,7 +124,7 @@ class _HomePageState extends State { Image.asset('assets/no_data.png'), SizedBox(height: 80), Text( - "Add an expense to begin", + localizations.t('home.emptyList'), style: Theme.of(context).textTheme.caption, ) ], @@ -173,7 +175,7 @@ class _HomePageState extends State { ); } - Widget _selector() { + Widget _selector(ComoGastoLocalizations localizations) { return SizedBox.fromSize( size: Size.fromHeight(70.0), child: PageView( @@ -187,18 +189,18 @@ class _HomePageState extends State { }, controller: _controller, children: [ - _pageItem("January", 0), - _pageItem("February", 1), - _pageItem("March", 2), - _pageItem("April", 3), - _pageItem("May", 4), - _pageItem("June", 5), - _pageItem("July", 6), - _pageItem("August", 7), - _pageItem("September", 8), - _pageItem("October", 9), - _pageItem("November", 10), - _pageItem("December", 11), + _pageItem(localizations.t("months.jan"), 0), + _pageItem(localizations.t("months.feb"), 1), + _pageItem(localizations.t("months.mar"), 2), + _pageItem(localizations.t("months.apr"), 3), + _pageItem(localizations.t("months.may"), 4), + _pageItem(localizations.t("months.jun"), 5), + _pageItem(localizations.t("months.jul"), 6), + _pageItem(localizations.t("months.aug"), 7), + _pageItem(localizations.t("months.sep"), 8), + _pageItem(localizations.t("months.oct"), 9), + _pageItem(localizations.t("months.nov"), 10), + _pageItem(localizations.t("months.dec"), 11), ], ), ); diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 63007dd..8eb323e 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -1,3 +1,4 @@ +import 'package:como_gasto/como_gasto_localizations.dart'; import 'package:como_gasto/states/theme_state.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -5,9 +6,10 @@ import 'package:provider/provider.dart'; class SettingsPage extends StatelessWidget { @override Widget build(BuildContext context) { + ComoGastoLocalizations localizations = ComoGastoLocalizations.of(context); return Scaffold( appBar: AppBar( - title: Text("Settings"), + title: Text(localizations.t('settings.title')), ), body: Padding( padding: const EdgeInsets.all(12.0), @@ -20,7 +22,7 @@ class SettingsPage extends StatelessWidget { mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: Text("Use Dark mode?"), + child: Text(localizations.t('settings.dark_mode')), ), Switch( value: state.isDarkModeEnabled, @@ -41,7 +43,7 @@ class SettingsPage extends StatelessWidget { onPressed: () { //Provider.of(context).logout(); }, - child: Text("Sign Out"), + child: Text(localizations.t('settings.signout')), ), ) ], diff --git a/pubspec.lock b/pubspec.lock index a8f59e3..fb18d69 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,14 +42,14 @@ packages: name: charts_common url: "https://pub.dartlang.org" source: hosted - version: "0.6.0" + version: "0.8.1" charts_flutter: dependency: "direct main" description: name: charts_flutter url: "https://pub.dartlang.org" source: hosted - version: "0.6.0" + version: "0.8.1" cloud_firestore: dependency: "direct main" description: @@ -91,7 +91,7 @@ packages: name: datetime_picker_formfield url: "https://pub.dartlang.org" source: hosted - version: "0.4.0" + version: "1.0.0" firebase_auth: dependency: "direct main" description: @@ -132,6 +132,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_cupertino_localizations: + dependency: "direct main" + description: + name: flutter_cupertino_localizations + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" flutter_launcher_icons: dependency: "direct main" description: @@ -146,6 +153,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.8.0" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -185,7 +197,7 @@ packages: name: intl url: "https://pub.dartlang.org" source: hosted - version: "0.15.8" + version: "0.16.0" local_auth: dependency: "direct main" description: @@ -346,12 +358,12 @@ packages: source: hosted version: "3.5.0" yaml: - dependency: transitive + dependency: "direct main" description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.16" + version: "2.2.0" sdks: dart: ">=2.4.0 <3.0.0" flutter: ">=1.10.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 09f6e0e..ad532be 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,10 @@ environment: dependencies: flutter: sdk: flutter - charts_flutter: ^0.6.0 + flutter_localizations: + sdk: flutter + flutter_cupertino_localizations: ^1.0.1 + charts_flutter: ^0.8.1 font_awesome_flutter: ^8.4.0 cloud_firestore: ^0.13.0+1 firebase_storage: ^3.0.8 @@ -39,8 +42,9 @@ dependencies: rect_getter: ^0.0.1 flutter_launcher_icons: ^0.7.2+1 flutter_local_notifications: ^0.8.0 - datetime_picker_formfield: ^0.4.0 + datetime_picker_formfield: ^1.0.0 flare_flutter: + yaml: ^2.2.0 dev_dependencies: flutter_test: @@ -66,6 +70,7 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/ + - lang/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.io/assets-and-images/#resolution-aware.