Extract labels

This commit is contained in:
Julia Friesel
2018-08-09 08:36:57 +02:00
parent 77bda6bf53
commit d3d72a396e
2 changed files with 43 additions and 16 deletions
+21 -8
View File
@@ -1,11 +1,24 @@
export const settings = {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
shared: {
cancel: 'Cancel'
},
exportTitle: 'My Drip data export',
exportSubject: 'My Drip data export',
exportLabel: 'Export data',
importLabel: 'Import data'
export: {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
},
title: 'My Drip data export',
subject: 'My Drip data export',
button: 'Export data',
},
import: {
button: 'Import data',
title: 'Keep existing data?',
message: `There are two options for the import:
1. Keep existing cycle days and replace only the ones in the import file.
2. Delete all existing cycle days and import cycle days from file.`,
replaceOption: 'Import and replace',
deleteOption: 'Import and delete existing'
}
}
+22 -8
View File
@@ -22,13 +22,27 @@ export default class Settings extends Component {
<View style={styles.homeButton}>
<Button
onPress={ openShareDialogAndExport }
title={labels.exportLabel}>
title={labels.export.button}>
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={ getFileContentAndImport }
title={labels.importLabel}>
title={labels.import.button}
onPress={() => {
Alert.alert(
labels.import.title,
labels.import.message,
[{
text: labels.import.replaceOption,
onPress: () => getFileContentAndImport({deleteExisting: false})
}, {
text: labels.import.deleteOption,
onPress: () => getFileContentAndImport({deleteExisting: true})
}, {
text: labels.shared.cancel, style: 'cancel', onPress: () => { }
}]
)
}}>
</Button>
</View>
</View>
@@ -51,19 +65,19 @@ async function openShareDialogAndExport() {
try {
await Share.open({
title: labels.exportTitle,
title: labels.export.title,
url: data,
subject: labels.exportSubject,
subject: labels.export.subject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return alertError(labels.errors.problemSharing)
return alertError(labels.export.errors.problemSharing)
}
}
async function getFileContentAndImport() {
async function getFileContentAndImport({ deleteExisting }) {
let fileInfo
try {
fileInfo = await new Promise((resolve, reject) => {
@@ -87,7 +101,7 @@ async function getFileContentAndImport() {
}
try {
await importCsv(fileContent, false)
await importCsv(fileContent, deleteExisting)
Alert.alert('Success', 'Data successfully imported')
} catch(err) {
alertError(err.message)