Skip to content

Commit 5279735

Browse files
author
Meikel Philipp
committed
[ADD] Some more cases where locale formatting was needed
[ADD] filters.js to extract logic from main.js [FIX] Dashboard now uses the translation
1 parent 5ff31c0 commit 5279735

File tree

12 files changed

+74
-76
lines changed

12 files changed

+74
-76
lines changed

src/renderer/components/AccountsPane.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<p class="button is-tag is-primary">{{'ACCOUNTS_PANE.MODAL.CURRENT_AMOUNT' | translate }}</p>
5757
</div>
5858
<p class="control">
59-
<input class="input" type="number" placeholder="0.00" v-model="newAccount.amount">
59+
<input class="input" type="number" :placeholder="'0.00' | format" v-model="newAccount.amount">
6060
</p>
6161
</div>
6262
</div>
@@ -89,19 +89,19 @@
8989
<p>
9090
{{ 'ACCOUNTS_PANE.CARDS.BANK' | translate }}
9191
<span class="amount" :class="{ 'has-text-danger': account.inBank <= 0 }">
92-
{{account.inBank.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}} <icon size="is-small" :fa="account.currency"/>
92+
{{account.inBank | format}} <icon size="is-small" :fa="account.currency"/>
9393
</span>
9494
</p>
9595
<p>
9696
{{ 'ACCOUNTS_PANE.CARDS.TODAY' | translate }}
9797
<span class="amount" :class="{ 'has-text-danger': account.today <= 0 }">
98-
{{account.today.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}} <icon size="is-small" :fa="account.currency"/>
98+
{{account.today | format}} <icon size="is-small" :fa="account.currency"/>
9999
</span>
100100
</p>
101101
<p>
102102
{{ 'ACCOUNTS_PANE.CARDS.FUTURE' | translate }}
103103
<span class="amount" :class="{ 'has-text-danger': account.future <= 0 }">
104-
{{account.future.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}} <icon size="is-small" :fa="account.currency"/>
104+
{{account.future | format}} <icon size="is-small" :fa="account.currency"/>
105105
</span>
106106
</p>
107107
</small>

src/renderer/components/MainPane.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!-- NO DATA -->
1616
<div class="container has-text-centered" v-show="!$root.accounts.length" style="width: 64vw; padding-top:25%">
1717
<p class="title">{{ 'MAIN_PANE.NO_DATA.TITLE' | translate}}</p>
18-
<p class="subtitle">Create an <span class="has-text-primary link" @click="showCreateModal()">account</span> to start or <span class="has-text-info link" @click="openfile()">open a file</span> 🙂</p>
18+
<p class="subtitle" v-html="doTranslate('MAIN_PANE.NO_DATA.SUBTITLE')"></p>
1919
</div>
2020

2121
<div class="container" id="mainScreen" v-show="$root.accounts.length">
@@ -48,6 +48,7 @@ import moment from 'moment'
4848
import {ipcRenderer} from 'electron'
4949
import ChronoChart from '@/assets/ChronoChart.class'
5050
import chartJS from 'chart.js' // eslint-disable-line
51+
import { translate } from '../filters'
5152
5253
export default {
5354
name: 'main-pane',
@@ -69,7 +70,9 @@ export default {
6970
this.$root.updateSQL(tab)
7071
this.activeTab = tab
7172
},
72-
73+
doTranslate (value, option) {
74+
return translate(value, option)
75+
},
7376
openfile: function () {
7477
ipcRenderer.send('open-file')
7578
},

src/renderer/components/MainPane/accountsDetail.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<div class="columns is-centered">
77
<div class="notification is-black column is-4">
88
<div class="columns is-centered">
9-
<span class="column is-5 is-size-5 has-text-centered has-text-danger">{{balanceDown.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}}</span>
9+
<span class="column is-5 is-size-5 has-text-centered has-text-danger">{{balanceDown | format}}</span>
1010
<span class="column is-2 is-size-5 has-text-centered"><icon fa="balance-scale"/></span>
11-
<span class="column is-5 is-size-5 has-text-centered has-text-success">{{balanceUp.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}}</span>
11+
<span class="column is-5 is-size-5 has-text-centered has-text-success">{{balanceUp | format}}</span>
1212
</div>
1313
</div>
1414
</div>

src/renderer/components/MainPane/dashboard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ export default {
153153
animation: {
154154
animateScale: true,
155155
animateRotate: true
156-
}
156+
},
157+
tooltipTemplate: '<%if (label){%><%=label%>: <%}%>$<%= value %>'
157158
}
158159
}
159160

src/renderer/components/MainPane/recurrings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
</div>
106106

107107
<custom-field class="flex" :fa="newRecurringOperation.selectedAccount.currency">
108-
<input class="input" type="number" :placeholder="0.00.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})" v-model="newRecurringOperation.amount">
108+
<input class="input" type="number" :placeholder="'0.00' | format" v-model="newRecurringOperation.amount">
109109
</custom-field>
110110

111111
</div>

src/renderer/components/OperationPane.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</custom-field>
1818

1919
<custom-field class="flex" :fa="operationCurrency">
20-
<input class="input" :class="{'is-danger': this.errors[1]}" type="text" :placeholder="0.00.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})" pattern="-?[\d,.]*" v-model="newOperation.amount" @keyup.enter="isEditing? confirmEdition():addOperation()">
20+
<input class="input" :class="{'is-danger': this.errors[1]}" type="text" :placeholder="'0.00' | format" pattern="-?[\d,.]*" v-model="newOperation.amount" @keyup.enter="isEditing? confirmEdition():addOperation()">
2121
</custom-field>
2222

2323
<custom-field class="flex" fa="bank" type="select is-primary">
@@ -152,8 +152,7 @@ import jsonfile from 'jsonfile'
152152
import moment from 'moment'
153153
import path from 'path'
154154
import Vue from 'vue'
155-
156-
const decimalSeperator = 1.1.toLocaleString().substring(1, 2)
155+
import { parseLocalizedString } from '../filters'
157156
158157
export default {
159158
name: 'operation-pane',
@@ -252,18 +251,14 @@ export default {
252251
if (this.isValid()) {
253252
// Go to right tab
254253
this.$root.$emit('toggle-tab', 1)
255-
// Format data
256-
const amount = decimalSeperator === ','
257-
? this.newOperation.amount.replace(',', '.')
258-
: this.newOperation.amount
259254
260255
let data = [
261256
this.newOperation.date,
262257
this.newOperation.state,
263258
this.newOperation.beneficiary,
264259
this.newOperation.category,
265260
this.newOperation.label,
266-
parseFloat(amount),
261+
parseLocalizedString(this.newOperation.amount),
267262
this.newOperation.type
268263
]
269264

src/renderer/filters.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import jsonfile from 'jsonfile'
2+
import i18njs from 'i18njs'
3+
import Vue from 'vue'
4+
import moment from 'moment'
5+
import path from 'path'
6+
7+
const decimalSeperator = 1.1.toLocaleString().substring(1, 2)
8+
let globSettings = jsonfile.readFileSync(path.join(__static, 'settings.json'))
9+
const lang = jsonfile.readFileSync(`${__static}/lang/${globSettings.language}_.json`)
10+
i18njs.add(globSettings.language, '', lang)
11+
i18njs.setLang(globSettings.language)
12+
13+
Vue.filter('translate', (value, option) => {
14+
return translate(value, option)
15+
})
16+
Vue.filter('date', (value) => {
17+
let formattedMoment = moment(value).format(globSettings.dateFormat)
18+
return formattedMoment
19+
})
20+
21+
Vue.filter('format', (value) => {
22+
// try parse float if possible
23+
if (typeof value === 'string' || value instanceof String) {
24+
value = parseLocalizedString(value)
25+
}
26+
return format(value)
27+
})
28+
29+
export function translate (value, option) {
30+
if (!value) return ''
31+
value = value.toString()
32+
if (i18njs.has('.RENDERER.' + value)) return i18njs.get('.RENDERER.' + value, option)
33+
if (i18njs.has('.COMMON.' + value)) return i18njs.get('.COMMON.' + value, option)
34+
return i18njs.get(value, option)
35+
}
36+
37+
export function parseLocalizedString (str) {
38+
// fix decimal delimiter
39+
str = decimalSeperator === ','
40+
? str.replace(',', '.')
41+
: str
42+
return parseFloat(str)
43+
}
44+
45+
export function format (value) {
46+
if ((typeof value === 'number' || value instanceof Number) && !isNaN(value)) {
47+
// format if number and not NaN
48+
return value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})
49+
} else {
50+
return value
51+
}
52+
}

src/renderer/main.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,16 @@ import App from '@/App'
1010
// nodeModules
1111
import jsonfile from 'jsonfile'
1212
import path from 'path'
13-
import i18njs from 'i18njs'
1413
import moment from 'moment'
1514
import {ipcRenderer} from 'electron'
15+
import './filters'
1616

1717
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
1818
Vue.http = Vue.prototype.$http = axios
1919
Vue.config.productionTip = false
2020

2121
let globSettings = jsonfile.readFileSync(path.join(__static, 'settings.json'))
2222

23-
const lang = jsonfile.readFileSync(`${__static}/lang/${globSettings.language}_.json`)
24-
i18njs.add(globSettings.language, '', lang)
25-
i18njs.setLang(globSettings.language)
26-
27-
Vue.filter('translate', (value, option) => {
28-
if (!value) return ''
29-
value = value.toString()
30-
if (i18njs.has('.RENDERER.' + value)) return i18njs.get('.RENDERER.' + value, option)
31-
if (i18njs.has('.COMMON.' + value)) return i18njs.get('.COMMON.' + value, option)
32-
return i18njs.get(value, option)
33-
})
34-
Vue.filter('date', (value) => {
35-
let formattedMoment = moment(value).format(globSettings.dateFormat)
36-
return formattedMoment
37-
})
38-
3923
/* eslint-disable no-new */
4024
new Vue({
4125
components: { App },

src/renderer/reports/balanceView.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,10 @@ import 'font-awesome/css/font-awesome.css'
99
import BalanceView from '@/reports/balanceView.vue'
1010
// nodeModules
1111
import path from 'path'
12-
import i18njs from 'i18njs'
1312
import jsonfile from 'jsonfile'
13+
import './../filters'
1414

1515
let globSettings = jsonfile.readFileSync(path.join(__static, 'settings.json'))
16-
17-
const lang = jsonfile.readFileSync(`${__static}/lang/${globSettings.language}_.json`)
18-
i18njs.add(globSettings.language, '', lang)
19-
i18njs.setLang(globSettings.language)
20-
21-
Vue.filter('translate', (value, option) => {
22-
if (!value) return ''
23-
value = value.toString()
24-
if (i18njs.has('.RENDERER.' + value)) return i18njs.get('.RENDERER.' + value, option)
25-
if (i18njs.has('.COMMON.' + value)) return i18njs.get('.COMMON.' + value, option)
26-
return i18njs.get(value, option)
27-
})
28-
2916
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
3017
Vue.http = Vue.prototype.$http = axios
3118

src/renderer/reports/chronoView.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,11 @@ import 'font-awesome/css/font-awesome.css'
99
import ChronoView from '@/reports/chronoView.vue'
1010
// nodeModules
1111
import path from 'path'
12-
import i18njs from 'i18njs'
1312
import jsonfile from 'jsonfile'
13+
import './../filters'
1414

1515
let globSettings = jsonfile.readFileSync(path.join(__static, 'settings.json'))
1616

17-
const lang = jsonfile.readFileSync(`${__static}/lang/${globSettings.language}_.json`)
18-
i18njs.add(globSettings.language, '', lang)
19-
i18njs.setLang(globSettings.language)
20-
21-
Vue.filter('translate', (value, option) => {
22-
if (!value) return ''
23-
value = value.toString()
24-
if (i18njs.has('.RENDERER.' + value)) return i18njs.get('.RENDERER.' + value, option)
25-
if (i18njs.has('.COMMON.' + value)) return i18njs.get('.COMMON.' + value, option)
26-
return i18njs.get(value, option)
27-
})
28-
2917
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
3018
Vue.http = Vue.prototype.$http = axios
3119

src/renderer/reports/statisticView.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,11 @@ import 'font-awesome/css/font-awesome.css'
99
import StatisticView from '@/reports/statisticView.vue'
1010
// nodeModules
1111
import path from 'path'
12-
import i18njs from 'i18njs'
1312
import jsonfile from 'jsonfile'
13+
import './../filters'
1414

1515
let globSettings = jsonfile.readFileSync(path.join(__static, 'settings.json'))
1616

17-
const lang = jsonfile.readFileSync(`${__static}/lang/${globSettings.language}_.json`)
18-
i18njs.add(globSettings.language, '', lang)
19-
i18njs.setLang(globSettings.language)
20-
21-
Vue.filter('translate', (value, option) => {
22-
if (!value) return ''
23-
value = value.toString()
24-
if (i18njs.has('.RENDERER.' + value)) return i18njs.get('.RENDERER.' + value, option)
25-
if (i18njs.has('.COMMON.' + value)) return i18njs.get('.COMMON.' + value, option)
26-
return i18njs.get(value, option)
27-
})
28-
2917
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
3018
Vue.http = Vue.prototype.$http = axios
3119

static/lang/de_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"MAIN_PANE": {
6565
"NO_DATA": {
6666
"TITLE": "Keine Daten !",
67-
"SUBTITLE": "<span>Erstellen sie einen <span class=\"has-text-primary link\" @click=\"showCreateModal\">Account</span> um zu starten oder<span class=\"has-text-info link\" @click=\"ipc.send('open-file')\">öffnen sie eine Datei</span></span>"
67+
"SUBTITLE": "<span>Erstellen sie einen <span class=\"has-text-primary link\" @click=\"showCreateModal\">Account</span> um zu starten oder <span class=\"has-text-info link\" @click=\"ipc.send('open-file')\">öffnen sie eine Datei</span></span>"
6868
},
6969

7070
"TABS": {

0 commit comments

Comments
 (0)