Moment translation
This commit is contained in:
parent
eb851a8069
commit
ff6a0c9626
5 changed files with 132 additions and 4 deletions
63
lib/customMoment.dart
Normal file
63
lib/customMoment.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) 2016, rinukkusu. All rights reserved. Use of this source code
|
||||
// is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'generated/i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Moment {
|
||||
DateTime _date;
|
||||
|
||||
Moment.now() {
|
||||
_date = new DateTime.now();
|
||||
}
|
||||
|
||||
Moment.fromDate(DateTime date) {
|
||||
_date = date;
|
||||
}
|
||||
|
||||
Moment.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch,
|
||||
{bool isUtc: false}) {
|
||||
_date = new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch,
|
||||
isUtc: isUtc);
|
||||
}
|
||||
|
||||
static Moment parse(String date) {
|
||||
return new Moment.fromDate(DateTime.parse(date));
|
||||
}
|
||||
|
||||
String toString() {
|
||||
return _date.toString();
|
||||
}
|
||||
|
||||
String fromNow(BuildContext context, [bool withoutPrefixOrSuffix = false]) {
|
||||
return from(context, new DateTime.now(), withoutPrefixOrSuffix);
|
||||
}
|
||||
|
||||
String from(BuildContext context, DateTime date, [bool withoutPrefixOrSuffix = false]) {
|
||||
Duration diff = date.difference(_date);
|
||||
|
||||
String timeString = "";
|
||||
|
||||
if (diff.inSeconds.abs() < 45) timeString = S.of(context).aF3wSeconds;
|
||||
else if (diff.inMinutes.abs() < 2) timeString = S.of(context).aMinute;
|
||||
else if (diff.inMinutes.abs() < 45) timeString = S.of(context).inMinutes(diff.inMinutes.abs().toString());
|
||||
else if (diff.inHours.abs() < 2) timeString = S.of(context).anHour;
|
||||
else if (diff.inHours.abs() < 22) timeString = S.of(context).inHours(diff.inHours.abs().toString());
|
||||
else if (diff.inDays.abs() < 2) timeString = S.of(context).aDay;
|
||||
else if (diff.inDays.abs() < 26) timeString = S.of(context).inDays(diff.inDays.abs().toString());
|
||||
else if (diff.inDays.abs() < 60) timeString = S.of(context).aMonth;
|
||||
else if (diff.inDays.abs() < 320) timeString = S.of(context).inMonths((diff.inDays.abs() ~/ 30).toString());
|
||||
else if (diff.inDays.abs() < 547) timeString = S.of(context).aYear;
|
||||
else timeString = S.of(context).inYears((diff.inDays.abs() ~/ 356).toString());
|
||||
|
||||
if (!withoutPrefixOrSuffix) {
|
||||
if (diff.isNegative)
|
||||
timeString =S.of(context).somethingAgo(timeString);
|
||||
|
||||
else
|
||||
timeString =S.of(context).inSomething(timeString);
|
||||
}
|
||||
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,11 +23,17 @@ class S implements WidgetsLocalizations {
|
|||
|
||||
String get AvoidThisStringsIfisNotPlural => "Zero One Two Few Many Other";
|
||||
String get UNDO => "UNDO";
|
||||
String get aDay => "a day";
|
||||
String get aF3wSeconds => "a few seconds";
|
||||
String get aMinute => "a minute";
|
||||
String get aMonth => "a month";
|
||||
String get aYear => "a year";
|
||||
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 anHour => "an hour";
|
||||
String get appName => "All Against The Fire!";
|
||||
String get chooseAPlace => "Choose a place";
|
||||
String get chooseAWatchRadio => "Choose a watch radio";
|
||||
|
|
@ -49,7 +55,14 @@ class S implements WidgetsLocalizations {
|
|||
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 inDays(String value) => "$value days";
|
||||
String inHours(String value) => "$value hours";
|
||||
String inMinutes(String value) => "$value minutes";
|
||||
String inMonths(String value) => "$value months";
|
||||
String inSomething(String something) => "in $something";
|
||||
String inYears(String value) => "$value years";
|
||||
String noFiresAroundThisArea(String kmAround) => "There is no fires at $kmAround км around this area";
|
||||
String somethingAgo(String something) => "$something ago";
|
||||
String subscribeToValueAroundThisArea(String sliderValue) => "Subscribe to $sliderValue км around this area";
|
||||
String updatedLastCheck(String lastCheck) => "Updated $lastCheck";
|
||||
}
|
||||
|
|
@ -71,6 +84,10 @@ class es extends S {
|
|||
@override
|
||||
String get alertWhenThereIsAFire => "Alerta cuando hay un fuego";
|
||||
@override
|
||||
String get anHour => "una hora";
|
||||
@override
|
||||
String get aMinute => "un minuto";
|
||||
@override
|
||||
String get firesInYourPlaces => "Fuegos en tus lugares";
|
||||
@override
|
||||
String get notifyAFire => "Notificar un fuego";
|
||||
|
|
@ -83,6 +100,8 @@ class es extends S {
|
|||
@override
|
||||
String get unsubscribe => "Desuscríbete";
|
||||
@override
|
||||
String get aDay => "un día";
|
||||
@override
|
||||
String get supportThisInitiative => "Apoya esta iniciativa";
|
||||
@override
|
||||
String get toFiresNotifications => "Suscríbete a alertas de fuegos";
|
||||
|
|
@ -95,8 +114,12 @@ class es extends S {
|
|||
@override
|
||||
String get appName => "¡Tod@s contra el Fuego!";
|
||||
@override
|
||||
String get aF3wSeconds => "unos segundos";
|
||||
@override
|
||||
String get activeFires => "Fuegos activos";
|
||||
@override
|
||||
String get aMonth => "un mes";
|
||||
@override
|
||||
String get firesInTheWorld => "Fuegos en el mundo";
|
||||
@override
|
||||
String get addSomePlace => "Añade otro lugar";
|
||||
|
|
@ -115,6 +138,14 @@ class es extends S {
|
|||
@override
|
||||
String get firesNearPlace => "Fuegos cercanos a ti";
|
||||
@override
|
||||
String get aYear => "un año";
|
||||
@override
|
||||
String inMonths(String value) => "$value meses";
|
||||
@override
|
||||
String inDays(String value) => "$value días";
|
||||
@override
|
||||
String inYears(String value) => "$value años";
|
||||
@override
|
||||
String noFiresAroundThisArea(String kmAround) => "No hay fuegos a $kmAround км a la redonda";
|
||||
@override
|
||||
String activeFiresWorldWide(String activeFires) => "$activeFires fuegos activos en el mundo";
|
||||
|
|
@ -123,9 +154,17 @@ class es extends S {
|
|||
@override
|
||||
String appLicense(String thisYear) => "(c) 2017-$thisYear Asociación Comunes bajo licencia GNU Affero GPL v3";
|
||||
@override
|
||||
String somethingAgo(String something) => "hace $something";
|
||||
@override
|
||||
String subscribeToValueAroundThisArea(String sliderValue) => "Suscríbete a $sliderValue км a la redonda";
|
||||
@override
|
||||
String inHours(String value) => "$value horas";
|
||||
@override
|
||||
String updatedLastCheck(String lastCheck) => "Actualizado $lastCheck";
|
||||
@override
|
||||
String inSomething(String something) => "en $something";
|
||||
@override
|
||||
String inMinutes(String value) => "$value minutos";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:simple_moment/simple_moment.dart';
|
||||
import 'dart:convert';
|
||||
import 'globals.dart' as globals;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
|
@ -7,6 +6,7 @@ import 'package:comunes_flutter/comunes_flutter.dart';
|
|||
import 'customBottomAppBar.dart';
|
||||
import 'colors.dart';
|
||||
import 'generated/i18n.dart';
|
||||
import 'customMoment.dart';
|
||||
|
||||
class GlobalFiresBottomStats extends StatefulWidget {
|
||||
@override
|
||||
|
|
@ -25,7 +25,7 @@ class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
|||
var now = Moment.now();
|
||||
var last = DateTime.parse(json.decode(result)['value']);
|
||||
setState(() {
|
||||
lastCheck = now.from(last);
|
||||
lastCheck = now.from(context, last);
|
||||
});
|
||||
} catch (e) {
|
||||
print('Cannot get the last fire check');
|
||||
|
|
|
|||
|
|
@ -29,5 +29,18 @@
|
|||
"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"
|
||||
"warningThisIsAVeryLargeArea": "Warning: this is a very large area",
|
||||
"aF3wSeconds": "a few seconds",
|
||||
"aMinute": "a minute",
|
||||
"inMinutes": "$value minutes",
|
||||
"anHour": "an hour",
|
||||
"inHours": "$value hours",
|
||||
"aDay": "a day",
|
||||
"inDays": "$value days",
|
||||
"aMonth": "a month",
|
||||
"inMonths": "$value months",
|
||||
"aYear": "a year",
|
||||
"inYears": "$value years",
|
||||
"somethingAgo": "$something ago",
|
||||
"inSomething": "in $something"
|
||||
}
|
||||
|
|
@ -29,5 +29,18 @@
|
|||
"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"
|
||||
"warningThisIsAVeryLargeArea": "Cuidado: esta zona es muy grande",
|
||||
"aF3wSeconds": "unos segundos",
|
||||
"aMinute": "un minuto",
|
||||
"inMinutes": "$value minutos",
|
||||
"anHour": "una hora",
|
||||
"inHours": "$value horas",
|
||||
"aDay": "un día",
|
||||
"inDays": "$value días",
|
||||
"aMonth": "un mes",
|
||||
"inMonths": "$value meses",
|
||||
"aYear": "un año",
|
||||
"inYears": "$value años",
|
||||
"somethingAgo": "hace $something",
|
||||
"inSomething": "en $something"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue