From 6488957148c9e35b122314e116a0f0645dca73ce Mon Sep 17 00:00:00 2001 From: vjrj Date: Tue, 26 Jun 2018 16:50:05 +0200 Subject: [PATCH] i18n (wip) --- lib/activeFires.dart | 85 ++++++--------- lib/addZone.dart | 55 ---------- lib/firesApp.dart | 22 +++- lib/generated/i18n.dart | 182 +++++++++++++++++++++++++++++++ lib/genericMap.dart | 19 ++-- lib/globalFiresBottomStats.dart | 5 +- lib/globals.dart | 3 +- lib/homePage.dart | 8 +- lib/introPage.dart | 22 ++-- lib/locationUtils.dart | 7 +- lib/mainCommon.dart | 2 +- lib/mainDrawer.dart | 44 ++------ lib/placesAutocompleteUtils.dart | 12 +- lib/slider.dart | 16 +-- pubspec.yaml | 11 +- res/values/strings_en.arb | 33 ++++++ res/values/strings_es.arb | 33 ++++++ 17 files changed, 368 insertions(+), 191 deletions(-) delete mode 100644 lib/addZone.dart create mode 100644 lib/generated/i18n.dart create mode 100644 res/values/strings_en.arb create mode 100644 res/values/strings_es.arb diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 456ca2a..673cf98 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -1,17 +1,20 @@ -import 'package:flutter/material.dart'; -import 'mainDrawer.dart'; -import 'genericMap.dart'; import 'dart:async'; + import 'package:comunes_flutter/comunes_flutter.dart'; -import 'colors.dart'; -import 'placesAutocompleteUtils.dart'; -import 'basicLocation.dart'; -import 'locationUtils.dart'; -import 'globals.dart' as globals; -import 'basicLocationPersist.dart'; -import 'globalFiresBottomStats.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_fab_dialer/flutter_fab_dialer.dart'; +import 'basicLocation.dart'; +import 'basicLocationPersist.dart'; +import 'colors.dart'; +import 'generated/i18n.dart'; +import 'genericMap.dart'; +import 'globalFiresBottomStats.dart'; +import 'globals.dart' as globals; +import 'locationUtils.dart'; +import 'mainDrawer.dart'; +import 'placesAutocompleteUtils.dart'; + class ActiveFiresPage extends StatefulWidget { static const String routeName = '/fires'; @@ -24,25 +27,24 @@ class ActiveFiresPage extends StatefulWidget { class _ActiveFiresPageState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); - List _fabMiniMenuItemList(BuildContext context) { + List _fabMiniMenuItemList() { return [ new FabMiniMenuItem.withText( new Icon(Icons.location_searching), fires600, 8.0, - "Add your current position", + S.of(context).addYourCurrentPosition, () { onAddYourLocation(); }, - "Add your current position", + S.of(context).addYourCurrentPosition, Colors.black38, Colors.white, ), - new FabMiniMenuItem.withText( - new Icon(Icons.edit_location), fires600, 8.0, "Add some other place", - () { - onAddOtherLocation(context); - }, "Add some other place", Colors.black38, Colors.white) + new FabMiniMenuItem.withText(new Icon(Icons.edit_location), fires600, 8.0, + S.of(context).addSomePlace, () { + onAddOtherLocation(); + }, S.of(context).addSomePlace, Colors.black38, Colors.white) ]; } @@ -63,7 +65,7 @@ class _ActiveFiresPageState extends State { }), title: new Text(loc.description), onLongPress: () { - showSnackMsg('Slide horizontally to delete this location'); + showSnackMsg(S.of(context).toDeleteThisPlace); }, onTap: () { showLocationMap(loc); @@ -127,11 +129,11 @@ class _ActiveFiresPageState extends State { globals.yourLocations.remove(item); persistYourLocations(); }); - final String action = 'deleted'; + _scaffoldKey.currentState.showSnackBar(new SnackBar( - content: new Text('You $action this position'), + content: new Text(S.of(context).youDeletedThisPlace), action: new SnackBarAction( - label: 'UNDO', + label: S.of(context).UNDO, onPressed: () { handleUndo(item); }))); @@ -158,8 +160,8 @@ class _ActiveFiresPageState extends State { Widget build(BuildContext context) { var hasLocations = globals.yourLocations.length > 0; final title = hasLocations - ? 'Active fires in your places' - : 'Active fires in the world'; + ? S.of(context).firesInYourPlaces + : S.of(context).firesInTheWorld; print('Building Active Fires'); return Scaffold( key: _scaffoldKey, @@ -180,7 +182,7 @@ class _ActiveFiresPageState extends State { ? new Stack(children: [ _buildSavedLocations(), new FabDialer( - _fabMiniMenuItemList(context), fires600, new Icon(Icons.add)) + _fabMiniMenuItemList(), fires600, new Icon(Icons.add)) ]) : new Center( child: new CenteredColumn(children: [ @@ -192,35 +194,12 @@ class _ActiveFiresPageState extends State { const SizedBox(height: 26.0), new RoundedBtn( icon: Icons.edit_location, - text: 'Fires near other place', + text: S.of(context).firesNearPlace, onPressed: () { - onAddOtherLocation(context); + onAddOtherLocation(); }, backColor: fires600), ])), - floatingActionButton: hasLocations - ? Column(mainAxisAlignment: MainAxisAlignment.end, - // crossAxisAlignment: CrossAxisAlignment.center, - children: [ - /* FloatingActionButton.extended( - onPressed: onAddYourLocation, - heroTag: 'yourposition', - label: const Text('Add your position'), - icon: const Icon(Icons.location_searching), - ), - Padding( - padding: const EdgeInsets.only(top: 16.0), - child: FloatingActionButton.extended( - onPressed: () { - onAddOtherLocation(context); - }, - heroTag: 'otherplace', - label: new Text('Add some other place'), - icon: const Icon(Icons.edit_location), - ), - ), */ - ]) - : null, ); } @@ -229,8 +208,8 @@ class _ActiveFiresPageState extends State { _saveLocation(location); } - void onAddOtherLocation(BuildContext context) { - Future location = openPlacesDialog(context); + void onAddOtherLocation() { + Future location = openPlacesDialog(_scaffoldKey); _saveLocation(location); } @@ -238,7 +217,7 @@ class _ActiveFiresPageState extends State { location.then((newLocation) { if (newLocation != BasicLocation.noLocation) { if (globals.yourLocations.contains(newLocation)) { - showSnackMsg('You have already added this location'); + showSnackMsg(S.of(context).addedThisLocation); } else this.setState(() { globals.yourLocations.add(newLocation); diff --git a/lib/addZone.dart b/lib/addZone.dart deleted file mode 100644 index 5f4413d..0000000 --- a/lib/addZone.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:flutter/material.dart'; - -class HomePage extends StatelessWidget { - static const String routeName = '/home'; - - @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: const Text('Add area'), - actions: [ - IconButton( - icon: Icon(Icons.edit), - onPressed: () { - print('Filter button'); - }, - ), - ], - ), - // https://flutter.io/widgets/scrolling/ - floatingActionButton: - Column(mainAxisAlignment: MainAxisAlignment.end, children: [ - FloatingActionButton( - onPressed: () { - // - }, - heroTag: 'image0', - tooltip: 'Pick Image from gallery', - child: const Icon(Icons.photo_library), - ), - ]), - - body: new SingleChildScrollView( - child: new Column( - children: [ - new Padding( - padding: const EdgeInsets.all(16.0), - child: new Column( - children: [ - SizedBox(height: 10.0), - new TextFormField( - decoration: new InputDecoration( - border: const OutlineInputBorder(), - helperText: "Write a place to center the map", - hintText: 'Write here a place', - labelText: 'Your location')), - SizedBox(height: 20.0), - ], - ), - ) - ], - )), - ); - } -} diff --git a/lib/firesApp.dart b/lib/firesApp.dart index 870c96c..a4faf70 100644 --- a/lib/firesApp.dart +++ b/lib/firesApp.dart @@ -1,10 +1,13 @@ -import 'package:flutter/material.dart'; import 'package:comunes_flutter/comunes_flutter.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; + +import 'activeFires.dart'; +import 'generated/i18n.dart'; import 'homePage.dart'; -import 'theme.dart'; import 'introPage.dart'; import 'sandbox.dart'; -import 'activeFires.dart'; +import 'theme.dart'; class FiresApp extends StatelessWidget { static final WidgetBuilder introWidget = (context) => new IntroPage(); @@ -23,8 +26,17 @@ class FiresApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( - home: new MaterialAppWithIntroHome(introWidget, continueWidget, 'showInitialWizard234'), - title: 'All Against The Fire!', + localizationsDelegates: [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, + localeResolutionCallback: + S.delegate.resolution(fallback: new Locale("en", "")), + home: new MaterialAppWithIntroHome( + introWidget, continueWidget, 'showInitialWizard234'), + onGenerateTitle: (context) => S.of(context).appName, theme: firesTheme, routes: routes); } diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart new file mode 100644 index 0000000..dd3859b --- /dev/null +++ b/lib/generated/i18n.dart @@ -0,0 +1,182 @@ + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +// ignore_for_file: non_constant_identifier_names +// ignore_for_file: camel_case_types +// ignore_for_file: prefer_single_quotes + +//This file is automatically generated. DO NOT EDIT, all your changes would be lost. + +class S implements WidgetsLocalizations { + const S(); + + static const GeneratedLocalizationsDelegate delegate = + const GeneratedLocalizationsDelegate(); + + static S of(BuildContext context) => + Localizations.of(context, WidgetsLocalizations); + + @override + TextDirection get textDirection => TextDirection.ltr; + + String get AvoidThisStringsIfisNotPlural => "Zero One Two Few Many Other"; + String get UNDO => "UNDO"; + String get activeFires => "Active fires"; + String get addSomePlace => "Add some other place"; + String get addYourCurrentPosition => "Add your current position"; + String get addedThisLocation => "You have already added this location"; + String get alertWhenThereIsAFire => "Alert when there is a fire"; + String get appName => "All Against The Fire!"; + String get chooseAPlace => "Choose a place"; + String get chooseAWatchRadio => "Choose a watch radio"; + String get confirm => "Confirm"; + String get firesInTheWorld => "Active fires in the world"; + String get firesInYourPlaces => "Active fires in your places"; + String get firesNearPlace => "Fires near other place"; + String get getAlertsOfFiresinThatArea => "Get alerts of fires in that area"; + String get isYourUbicationEnabled => "I cannot get your current location. It's your ubication enabled?"; + String get notPermsUbication => "We don't have permission to get your location"; + String get notifyAFire => "Notify a fire"; + String get supportThisInitiative => "Support this initiative"; + String get toDeleteThisPlace => "Slide horizontally to delete this place"; + String get toFiresNotifications => "Subscribe to fires notifications"; + String get typeTheNameOfAPlace => "Type the name of a place, region, etc"; + String get unsubscribe => "Unsubscribe"; + String get warningThisIsAVeryLargeArea => "Warning: this is a very large area"; + String get youDeletedThisPlace => "You deleted this place"; + String activeFiresWorldWide(String activeFires) => "$activeFires active fires worldwide"; + String appLicense(String thisYear) => "(c) 2017-$thisYear Comunes Association under the GNU Affero GPL v3"; + String firesAroundThisArea(String numFires, String kmAround) => "$numFires fires at $kmAround км around this area"; + String noFiresAroundThisArea(String kmAround) => "There is no fires at $kmAround км around this area"; + String subscribeToValueAroundThisArea(String sliderValue) => "Subscribe to $sliderValue км around this area"; + String updatedLastCheck(String lastCheck) => "Updated $lastCheck"; +} + +class en extends S { + const en(); +} + +class es extends S { + const es(); + + @override + TextDirection get textDirection => TextDirection.ltr; + + @override + String get addYourCurrentPosition => "Añade tu ubicación actual"; + @override + String get UNDO => "DESHACER"; + @override + String get alertWhenThereIsAFire => "Alerta cuando hay un fuego"; + @override + String get firesInYourPlaces => "Fuegos en tus lugares"; + @override + String get notifyAFire => "Notificar un fuego"; + @override + String get isYourUbicationEnabled => "No podemos saber tu ubicación actual. ¿Están los servicios de ubicación en tu móvil activados?"; + @override + String get toDeleteThisPlace => "Desliza horizontalmente para borrar este lugar"; + @override + String get AvoidThisStringsIfisNotPlural => "Zero One Two Few Many Other"; + @override + String get unsubscribe => "Desuscríbete"; + @override + String get supportThisInitiative => "Apoya esta iniciativa"; + @override + String get toFiresNotifications => "Suscríbete a alertas de fuegos"; + @override + String get notPermsUbication => "No tenemos permisos para conocer tu ubicación"; + @override + String get addedThisLocation => "Ya has añadido este lugar antes"; + @override + String get typeTheNameOfAPlace => "Escribe el nombre de un lugar, zona, etc"; + @override + String get appName => "¡Tod@s contra el Fuego!"; + @override + String get activeFires => "Fuegos activos"; + @override + String get firesInTheWorld => "Fuegos en el mundo"; + @override + String get addSomePlace => "Añade otro lugar"; + @override + String get confirm => "Confirmar"; + @override + String get getAlertsOfFiresinThatArea => "Recibe alertas de fuegos en esa zona"; + @override + String get youDeletedThisPlace => "Has borrado este lugar"; + @override + String get warningThisIsAVeryLargeArea => "Cuidado: esta zona es muy grande"; + @override + String get chooseAWatchRadio => "Elige un radio de vigilancia"; + @override + String get chooseAPlace => "Elige un lugar"; + @override + String get firesNearPlace => "Fuegos cercanos a ti"; + @override + String noFiresAroundThisArea(String kmAround) => "No hay fuegos a $kmAround км a la redonda"; + @override + String activeFiresWorldWide(String activeFires) => "$activeFires fuegos activos en el mundo"; + @override + String firesAroundThisArea(String numFires, String kmAround) => "$numFires fuegos a $kmAround км a la redonda"; + @override + String appLicense(String thisYear) => "(c) 2017-$thisYear Asociación Comunes bajo licencia GNU Affero GPL v3"; + @override + String subscribeToValueAroundThisArea(String sliderValue) => "Suscríbete a $sliderValue км a la redonda"; + @override + String updatedLastCheck(String lastCheck) => "Actualizado $lastCheck"; +} + + +class GeneratedLocalizationsDelegate extends LocalizationsDelegate { + const GeneratedLocalizationsDelegate(); + + List get supportedLocales { + return const [ + + const Locale("en", ""), + const Locale("es", ""), + + ]; + } + + LocaleResolutionCallback resolution({Locale fallback}) { + return (Locale locale, Iterable supported) { + final Locale languageLocale = new Locale(locale.languageCode, ""); + if (supported.contains(locale)) + return locale; + else if (supported.contains(languageLocale)) + return languageLocale; + else { + final Locale fallbackLocale = fallback ?? supported.first; + return fallbackLocale; + } + }; + } + + @override + Future load(Locale locale) { + final String lang = getLang(locale); + switch (lang) { + + case "en": + return new SynchronousFuture(const en()); + case "es": + return new SynchronousFuture(const es()); + + default: + return new SynchronousFuture(const S()); + } + } + + @override + bool isSupported(Locale locale) => supportedLocales.contains(locale); + + @override + bool shouldReload(GeneratedLocalizationsDelegate old) => false; +} + +String getLang(Locale l) => l.countryCode != null && l.countryCode.isEmpty + ? l.languageCode + : l.toString(); diff --git a/lib/genericMap.dart b/lib/genericMap.dart index 31077d4..23673f1 100644 --- a/lib/genericMap.dart +++ b/lib/genericMap.dart @@ -16,6 +16,7 @@ import 'customBottomAppBar.dart'; import 'dummyMapPlugin.dart'; import 'fireMarkType.dart'; import 'fireMarker.dart'; +import 'generated/i18n.dart'; import 'globals.dart' as globals; import 'slider.dart'; import 'zoomMapPlugin.dart'; @@ -130,7 +131,6 @@ class _GenericMapState extends State { ), ], )); - return new Scaffold( key: _scaffoldKey, // drawer: new MainDrawer(context), @@ -164,10 +164,10 @@ class _GenericMapState extends State { color: fires600), label: new Text( operation == MapOperation.view - ? 'Subscribe to fires notifications' + ? S.of(context).toFiresNotifications : operation == MapOperation.subscriptionConfirm - ? 'Confirm' - : 'Unsubscribe', + ? S.of(context).confirm + : S.of(context).unsubscribe, style: const TextStyle(color: fires600), ), backgroundColor: Colors.white, @@ -182,11 +182,12 @@ class _GenericMapState extends State { actions: listWithoutNulls([ operation == MapOperation.subscriptionConfirm || numFires == null ? null - : numFires > 0 - ? new Text('${numFires.toString()} fires at ${kmAround - .toString()} км around this area') - : new Text( - 'There is no fires at ${kmAround.toString()} км around this area'), + : new Text(numFires > 0 + ? S.of(context).firesAroundThisArea( + numFires.toString(), kmAround.toString()) + : S + .of(context) + .noFiresAroundThisArea(kmAround.toString())), SizedBox(width: 10.0) ])), body: LayoutBuilder( diff --git a/lib/globalFiresBottomStats.dart b/lib/globalFiresBottomStats.dart index f0d8a65..b1ab75f 100644 --- a/lib/globalFiresBottomStats.dart +++ b/lib/globalFiresBottomStats.dart @@ -6,6 +6,7 @@ import 'package:http/http.dart' as http; import 'package:comunes_flutter/comunes_flutter.dart'; import 'customBottomAppBar.dart'; import 'colors.dart'; +import 'generated/i18n.dart'; class GlobalFiresBottomStats extends StatefulWidget { @override @@ -55,8 +56,8 @@ class _GlobalFiresBottomStatsState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ - new Text('$activeFires active fires worldwide'), - new Text('Updated $lastCheck') + new Text(S.of(context).activeFiresWorldWide(activeFires.toString())), + new Text(S.of(context).updatedLastCheck(lastCheck)) ]) : null, SizedBox(width: 10.0) diff --git a/lib/globals.dart b/lib/globals.dart index 84ca9bb..003cab4 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -8,9 +8,8 @@ import 'package:flutter/material.dart'; String gmapKey; String firesApiKey; String firesApiUrl; -final String appName = 'All Against The Fire!'; final String appVersion = '0.0.1'; -final String appLicense = "(c) 2017-2018 Comunes Association under the GNU Affero GPL v3"; + final Widget appMediumIcon = Image.asset('images/logo-200.png', width: 60.0, height: 60.0); final Widget appIcon = Image.asset('images/logo-200.png', width: 24.0, height: 24.0); final Future prefs = SharedPreferences.getInstance(); diff --git a/lib/homePage.dart b/lib/homePage.dart index c9d26f7..fcba053 100644 --- a/lib/homePage.dart +++ b/lib/homePage.dart @@ -4,7 +4,7 @@ import 'colors.dart'; import 'package:comunes_flutter/comunes_flutter.dart'; import 'mainDrawer.dart'; import 'activeFires.dart'; -import 'globals.dart' as globals; +import 'generated/i18n.dart'; class HomePage extends StatelessWidget { static const String routeName = '/home'; @@ -49,21 +49,21 @@ class HomePage extends StatelessWidget { new Padding( padding: const EdgeInsets.all(10.0), child: new Text( - globals.appName, + S.of(context).appName, textAlign: TextAlign.center, softWrap: true, style: _homeFont), ), new SizedBox(height: 20.0), new RoundedBtn.nav( icon: Icons.whatshot, - text: 'Active fires', + text: S.of(context).activeFires, context: context, route: ActiveFiresPage.routeName, backColor: fires600), new SizedBox(height: 20.0), new RoundedBtn.nav( icon: Icons.notifications_active, - text: 'Notify a fire', + text: S.of(context).notifyAFire, context: context, route: ActiveFiresPage.routeName, backColor: fires600), diff --git a/lib/introPage.dart b/lib/introPage.dart index 45397bd..c5d656c 100644 --- a/lib/introPage.dart +++ b/lib/introPage.dart @@ -1,18 +1,24 @@ import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:flutter/material.dart'; + import 'homePage.dart'; +import 'generated/i18n.dart'; class IntroPage extends AppIntroPage { static const String routeName = '/intro'; - static final List fireItems = [ - AppIntroItem(icon: Icons.location_on, title: 'Choose a place'), - AppIntroItem(icon: Icons.panorama_fish_eye, title: 'Choose a watch radio'), - AppIntroItem( - icon: Icons.whatshot, title: 'Get alerts of fires in that area'), - AppIntroItem( - icon: Icons.notifications_active, title: 'Alert when there is a fire'), - ]; + static final fireItems = (context) => + [ + AppIntroItem(icon: Icons.location_on, title: S.of(context).chooseAPlace), + AppIntroItem( + icon: Icons.panorama_fish_eye, title: S.of(context).chooseAWatchRadio), + AppIntroItem( + icon: Icons.whatshot, title: S.of(context).getAlertsOfFiresinThatArea), + AppIntroItem( + icon: Icons.notifications_active, + title: S.of(context).alertWhenThereIsAFire) + ]; + /* static final OnIntroFinish onFinish = diff --git a/lib/locationUtils.dart b/lib/locationUtils.dart index fb7f09d..fa6bdd8 100644 --- a/lib/locationUtils.dart +++ b/lib/locationUtils.dart @@ -5,6 +5,7 @@ import 'basicLocation.dart'; import 'package:flutter/material.dart'; import 'package:geocoder/geocoder.dart'; import 'globals.dart' as globals; +import 'generated/i18n.dart'; Future getUserLocation( GlobalKey scaffoldKey) async { @@ -32,12 +33,12 @@ Future getUserLocation( } on PlatformException catch (e) { if (e.code == 'PERMISSION_DENIED') { scaffoldKey.currentState.showSnackBar(new SnackBar( - content: new Text('We don\'t have permission to get your location'), + content: new Text(S.of(scaffoldKey.currentContext).notPermsUbication), )); } else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {} scaffoldKey.currentState.showSnackBar(new SnackBar( - content: new Text( - 'I cannot get your current location. It\'s your ubication enabled?'), + content: new Text(S.of(scaffoldKey.currentContext).isYourUbicationEnabled + ), )); return BasicLocation.noLocation; } diff --git a/lib/mainCommon.dart b/lib/mainCommon.dart index 194c159..f6253f2 100644 --- a/lib/mainCommon.dart +++ b/lib/mainCommon.dart @@ -15,7 +15,7 @@ void mainCommon() { loadSecrets().then((secrets) { globals.gmapKey = secrets['gmapKey']; globals.firesApiKey = secrets['firesApiKey']; - globals.firesApiUrl = secrets['firesApiUrl']; + globals.firesApiUrl = secrets['firesApiUrl'] + "api/v1/"; globals.prefs.then((prefs) { loadYourLocationsWithPrefs(prefs); firebaseConfig(); diff --git a/lib/mainDrawer.dart b/lib/mainDrawer.dart index c7d3731..0031dd3 100644 --- a/lib/mainDrawer.dart +++ b/lib/mainDrawer.dart @@ -4,6 +4,8 @@ import 'colors.dart'; import 'sandbox.dart'; import 'activeFires.dart'; import 'globals.dart' as globals; +import 'generated/i18n.dart'; +import 'package:comunes_flutter/comunes_flutter.dart'; class MainDrawer extends Drawer { MainDrawer(BuildContext context, {key}) @@ -14,7 +16,7 @@ Widget mainDrawer(BuildContext context) { return new ListView( // Important: Remove any padding from the ListView. padding: EdgeInsets.zero, - children: [ + children: listWithoutNulls([ new GestureDetector( onTap: () { Navigator.pushNamed(context, '/'); @@ -28,7 +30,7 @@ Widget mainDrawer(BuildContext context) { height: 80.0, ), const SizedBox(height: 20.0), - new Text(globals.appName, + new Text(S.of(context).appName, style: new TextStyle( fontSize: 24.0, color: Colors.white, @@ -40,28 +42,16 @@ Widget mainDrawer(BuildContext context) { ), ), ), - /* new ListTile( - // https://docs.flutter.io/flutter/material/CircleAvatar-class.html - leading: new CircleAvatar( - backgroundColor: Colors.brown.shade800, - child: new Text('VR'), - ), - title: new Text('Your profile'), - onTap: () { - Navigator.pushNamed(context, IntroPage.routeName); - }, - ), - new Divider(), */ new ListTile( leading: const Icon(Icons.whatshot), - title: new Text('Active fires'), + title: new Text(S.of(context).activeFires), onTap: () { Navigator.pushNamed(context, ActiveFiresPage.routeName); }, ), new ListTile( leading: const Icon(Icons.notifications_active), - title: new Text('Notify a fire'), + title: new Text(S.of(context).notifyAFire), onTap: () { // Then close the drawer Navigator.pushNamed(context, Sandbox.routeName); @@ -70,41 +60,31 @@ Widget mainDrawer(BuildContext context) { new Divider(), new ListTile( leading: const Icon(Icons.favorite), - title: new Text('Support this initiative'), + title: new Text(S.of(context).supportThisInitiative), onTap: () { // Then close the drawer Navigator.pushNamed(context, '/subscriptions'); }, ), + globals.isDevelopment ? new ListTile( leading: const Icon(Icons.bug_report), title: new Text('Sandbox'), onTap: () { Navigator.pushNamed(context, Sandbox.routeName); }, - ), - new ListTile( - // https://material.io/tools/icons/?style=baseline - leading: const Icon(Icons.settings), - title: new Text('Settings'), - onTap: () { - // Update the state of the app - // ... - // Then close the drawer - Navigator.pop(context); - }, - ), + ): null, new AboutListTile( icon: globals.appIcon, - applicationName: globals.appName, + applicationName: S.of(context).appName, applicationVersion: globals.appVersion, applicationIcon: globals.appMediumIcon, - applicationLegalese: globals.appLicense, + applicationLegalese: S.of(context).appLicense(DateTime.now().year.toString()), aboutBoxChildren: [ // new Text('What?') ] // FIXME ) - ], + ]) ); } diff --git a/lib/placesAutocompleteUtils.dart b/lib/placesAutocompleteUtils.dart index 8f1552d..cf7ce2d 100644 --- a/lib/placesAutocompleteUtils.dart +++ b/lib/placesAutocompleteUtils.dart @@ -3,22 +3,22 @@ import 'package:flutter/material.dart'; import 'dart:async'; import 'basicLocation.dart'; import 'globals.dart' as globals; +import 'generated/i18n.dart'; -Future openPlacesDialog(BuildContext context) async { +Future openPlacesDialog(GlobalKey sc) async { Mode _mode = Mode.overlay; GoogleMapsPlaces _places = new GoogleMapsPlaces(globals.gmapKey); Prediction p = await showGooglePlacesAutocomplete( - context: context, - hint: 'Type the name of a place, region, etc', + context: sc.currentContext, + hint: S.of(sc.currentContext).typeTheNameOfAPlace, apiKey: globals.gmapKey, onError: (res) { - /* homeScaffoldKey.currentState.showSnackBar( + /* sc.currentState.showSnackBar( new SnackBar(content: new Text(res.errorMessage))); */ print('Error $res'); }, mode: _mode, - // FIXME - language: "es", + language: Localizations.localeOf(sc.currentContext).languageCode, components: [ // This limit the search too much // new Component(Component.country, "es") diff --git a/lib/slider.dart b/lib/slider.dart index 58e1b4d..637f31e 100644 --- a/lib/slider.dart +++ b/lib/slider.dart @@ -1,8 +1,8 @@ -import 'package:flutter/material.dart'; -import 'colors.dart'; import 'package:comunes_flutter/comunes_flutter.dart'; -import 'package:padder/padding.dart'; -import 'package:fluttery/framing.dart'; +import 'package:flutter/material.dart'; + +import 'colors.dart'; +import 'generated/i18n.dart'; typedef void SlideCallback(int distance); @@ -25,12 +25,12 @@ class _FireDistanceSliderState extends State { this._sliderValue = initialValue; } - sizeText(_sliderValue) => - new Text('Subscribe to $_sliderValue км around this area', + sizeText(sliderValue) => + new Text(S.of(context).subscribeToValueAroundThisArea(sliderValue.toString()), style: new TextStyle(color: Colors.black87)); - warningText(_sliderValue) => _sliderValue >= 50 - ? new Text('Warning: this is a very large area', + warningText(sliderValue) => _sliderValue >= 50 + ? new Text(S.of(context).warningThisIsAVeryLargeArea, style: new TextStyle(color: fires900)) : new Text(''); diff --git a/pubspec.yaml b/pubspec.yaml index b06158a..ffc4766 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,16 +4,21 @@ description: All Against Fire dependencies: flutter: sdk: flutter - # https://pub.dartlang.org/packages/flutter - # utils + # i18n + flutter_localizations: + sdk: flutter intl: "^0.15.6" + + # https://pub.dartlang.org/packages/flutter + + # utils shared_preferences: "^0.4.2" http: "^0.11.3+16" simple_moment: "^0.0.3" just_debounce_it: "^1.0.4" comunes_flutter: path: /home/vjrj/dev/comunes_flutter - version: "^0.0.9" + version: "^0.0.10" # maps, geo, etc flutter_map: "^0.0.1" flutter_google_places_autocomplete: "^0.0.4" diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb new file mode 100644 index 0000000..00f9fbb --- /dev/null +++ b/res/values/strings_en.arb @@ -0,0 +1,33 @@ +{ + "AvoidThisStringsIfisNotPlural": "Zero One Two Few Many Other", + "appName": "All Against The Fire!", + "addYourCurrentPosition": "Add your current position", + "addSomePlace": "Add some other place", + "addedThisLocation": "You have already added this location", + "firesNearPlace": "Fires near other place", + "firesInTheWorld": "Active fires in the world", + "firesInYourPlaces": "Active fires in your places", + "youDeletedThisPlace": "You deleted this place", + "UNDO": "UNDO", + "toDeleteThisPlace": "Slide horizontally to delete this place", + "toFiresNotifications": "Subscribe to fires notifications", + "confirm": "Confirm", + "unsubscribe": "Unsubscribe", + "firesAroundThisArea": "$numFires fires at $kmAround км around this area", + "noFiresAroundThisArea": "There is no fires at $kmAround км around this area", + "activeFiresWorldWide": "$activeFires active fires worldwide", + "updatedLastCheck": "Updated $lastCheck", + "appLicense": "(c) 2017-$thisYear Comunes Association under the GNU Affero GPL v3", + "activeFires": "Active fires", + "notifyAFire": "Notify a fire", + "supportThisInitiative": "Support this initiative", + "chooseAPlace": "Choose a place", + "chooseAWatchRadio": "Choose a watch radio", + "getAlertsOfFiresinThatArea": "Get alerts of fires in that area", + "alertWhenThereIsAFire": "Alert when there is a fire", + "notPermsUbication": "We don't have permission to get your location", + "isYourUbicationEnabled": "I cannot get your current location. It's your ubication enabled?", + "typeTheNameOfAPlace": "Type the name of a place, region, etc", + "subscribeToValueAroundThisArea": "Subscribe to $sliderValue км around this area", + "warningThisIsAVeryLargeArea": "Warning: this is a very large area" +} \ No newline at end of file diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb new file mode 100644 index 0000000..e1836ba --- /dev/null +++ b/res/values/strings_es.arb @@ -0,0 +1,33 @@ +{ + "AvoidThisStringsIfisNotPlural": "Zero One Two Few Many Other", + "appName": "¡Tod@s contra el Fuego!", + "addYourCurrentPosition": "Añade tu ubicación actual", + "addSomePlace": "Añade otro lugar", + "addedThisLocation": "Ya has añadido este lugar antes", + "firesNearPlace": "Fuegos cercanos a ti", + "firesInTheWorld": "Fuegos en el mundo", + "firesInYourPlaces": "Fuegos en tus lugares", + "youDeletedThisPlace": "Has borrado este lugar", + "UNDO": "DESHACER", + "toDeleteThisPlace": "Desliza horizontalmente para borrar este lugar", + "toFiresNotifications": "Suscríbete a alertas de fuegos", + "confirm": "Confirmar", + "unsubscribe": "Desuscríbete", + "firesAroundThisArea": "$numFires fuegos a $kmAround км a la redonda", + "noFiresAroundThisArea": "No hay fuegos a $kmAround км a la redonda", + "activeFiresWorldWide": "$activeFires fuegos activos en el mundo", + "updatedLastCheck": "Actualizado $lastCheck", + "appLicense": "(c) 2017-$thisYear Asociación Comunes bajo licencia GNU Affero GPL v3", + "activeFires": "Fuegos activos", + "notifyAFire": "Notificar un fuego", + "supportThisInitiative": "Apoya esta iniciativa", + "chooseAPlace": "Elige un lugar", + "chooseAWatchRadio": "Elige un radio de vigilancia", + "getAlertsOfFiresinThatArea": "Recibe alertas de fuegos en esa zona", + "alertWhenThereIsAFire": "Alerta cuando hay un fuego", + "notPermsUbication": "No tenemos permisos para conocer tu ubicación", + "isYourUbicationEnabled": "No podemos saber tu ubicación actual. ¿Están los servicios de ubicación en tu móvil activados?", + "typeTheNameOfAPlace": "Escribe el nombre de un lugar, zona, etc", + "subscribeToValueAroundThisArea": "Suscríbete a $sliderValue км a la redonda", + "warningThisIsAVeryLargeArea": "Cuidado: esta zona es muy grande" +} \ No newline at end of file