From c9430439c5f10748117e3c2bc082e92d18d41cf9 Mon Sep 17 00:00:00 2001 From: Maria Zadnepryanets Date: Tue, 20 Sep 2022 17:50:05 +0000 Subject: [PATCH] Chore: add translations to stats --- components/{common => stats}/StatsOverview.js | 2 +- components/{common => stats}/StatsTable.js | 2 +- components/{stats.js => stats/index.js} | 48 +++++++++++-------- i18n/en.json | 19 ++++++++ 4 files changed, 48 insertions(+), 23 deletions(-) rename components/{common => stats}/StatsOverview.js (97%) rename components/{common => stats}/StatsTable.js (98%) rename components/{stats.js => stats/index.js} (66%) diff --git a/components/common/StatsOverview.js b/components/stats/StatsOverview.js similarity index 97% rename from components/common/StatsOverview.js rename to components/stats/StatsOverview.js index 1e07953..a6317f6 100644 --- a/components/common/StatsOverview.js +++ b/components/stats/StatsOverview.js @@ -2,7 +2,7 @@ import React from 'react' import { StyleSheet, View } from 'react-native' import PropTypes from 'prop-types' -import AppText from './app-text' +import AppText from '../common/app-text' import { Sizes, Spacing, Typography } from '../../styles' diff --git a/components/common/StatsTable.js b/components/stats/StatsTable.js similarity index 98% rename from components/common/StatsTable.js rename to components/stats/StatsTable.js index c628bcc..88bc33b 100644 --- a/components/common/StatsTable.js +++ b/components/stats/StatsTable.js @@ -3,7 +3,7 @@ import { FlatList, StyleSheet, View } from 'react-native' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' -import AppText from './app-text' +import AppText from '../common/app-text' import cycleModule from '../../lib/cycle' import { Spacing, Typography, Colors } from '../../styles' diff --git a/components/stats.js b/components/stats/index.js similarity index 66% rename from components/stats.js rename to components/stats/index.js index 51af03f..29b4bc5 100644 --- a/components/stats.js +++ b/components/stats/index.js @@ -1,39 +1,45 @@ import React from 'react' import { ImageBackground, View } from 'react-native' import { ScaledSheet } from 'react-native-size-matters' +import { useTranslation } from 'react-i18next' -import AppText from './common/app-text' -import StatsOverview from './common/StatsOverview' -import StatsTable from './common/StatsTable' +import AppText from '../common/app-text' +import StatsOverview from './StatsOverview' +import StatsTable from './StatsTable' -import cycleModule from '../lib/cycle' -import { getCycleLengthStats as getCycleInfo } from '../lib/cycle-length' -import { stats as labels } from '../i18n/en/labels' +import cycleModule from '../../lib/cycle' +import { getCycleLengthStats as getCycleInfo } from '../../lib/cycle-length' -import { Containers, Sizes, Spacing, Typography } from '../styles' +import { Containers, Sizes, Spacing, Typography } from '../../styles' -const image = require('../assets/cycle-icon.png') +const image = require('../../assets/cycle-icon.png') const Stats = () => { + const { t } = useTranslation(null, { keyPrefix: 'stats' }) + const cycleLengths = cycleModule().getAllCycleLengths() const numberOfCycles = cycleLengths.length - const hasAtLeastOneCycle = numberOfCycles >= 1 - const cycleData = hasAtLeastOneCycle - ? getCycleInfo(cycleLengths) - : { minimum: '—', maximum: '—', stdDeviation: '—' } + const cycleData = + numberOfCycles > 0 + ? getCycleInfo(cycleLengths) + : { minimum: '—', maximum: '—', stdDeviation: '—' } + const standardDeviation = cycleData.stdDeviation + ? cycleData.stdDeviation + : '—' const statsData = [ - [cycleData.minimum, labels.minLabel], - [cycleData.maximum, labels.maxLabel], - [cycleData.stdDeviation ? cycleData.stdDeviation : '—', labels.stdLabel], - [numberOfCycles, labels.basisOfStatsEnd], + [cycleData.minimum, t('overview.min')], + [cycleData.maximum, t('overview.max')], + [standardDeviation, t('overview.standardDeviation')], + [numberOfCycles, t('overview.completedCycles')], ] return ( - {labels.cycleLengthExplainer} - {!hasAtLeastOneCycle && {labels.emptyStats}} - {hasAtLeastOneCycle && ( + {t('intro')} + {numberOfCycles === 0 ? ( + {t('noData')} + ) : ( { {cycleData.mean} - {labels.daysLabel} + {t('overview.days')} - {labels.averageLabel} + {t('overview.average')} diff --git a/i18n/en.json b/i18n/en.json index 08c7576..e97574c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -61,6 +61,25 @@ } } }, + "stats": { + "noData": "At least one completed cycle is needed to display stats.", + "intro": "Basic statistics about the length of your cycles.", + "overview": { + "average": "Average cycle", + "days": "days", + "min": "Shortest", + "max": "Longest", + "standardDeviation": "Standard\ndeviation", + "completedCycles": "completed\ncycles" + }, + "showStats": "Show period details", + "details": { + "cycleStart": "Cycle start", + "cycleLength": "Cycle length", + "bleedingDays": "Bleeding" + }, + "footnote": "Based on the standard deviation of all your tracked periods drip. calculates a range for the starting day of the upcoming 3 periods. The range will be 3 days if your standard deviation is smaller than 1.5 and 5 days if the value is bigger.\n\nThe standard deviation tells you how much the length of your periods vary, 0 means all your periods are exactly the same length and the bigger the value the more the period length varies." + }, "plurals": { "day": "{{count}} day", "day_plural": "{{count}} days"