Skip to content

Commit ba27697

Browse files
authored
Merge pull request #5 from boerniee/i18n
Added translations
2 parents 0035897 + 7d4b763 commit ba27697

29 files changed

+798
-369
lines changed

server/controllers/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func userLogin(c *gin.Context) {
115115
Email: user.Email,
116116
Token: token,
117117
RefreshToken: refreshToken,
118-
Role: user.RoleDetail().Long,
118+
Role: user.RoleDetail().Key,
119119
}
120120
c.JSON(http.StatusOK, response)
121121
}
@@ -149,7 +149,7 @@ func refresh(c *gin.Context) {
149149
Email: user.Email,
150150
Token: token,
151151
RefreshToken: refreshToken,
152-
Role: user.RoleDetail().Long,
152+
Role: user.RoleDetail().Key,
153153
}
154154
c.JSON(http.StatusOK, response)
155155
} else {

server/db/enums.go

+17-34
Original file line numberDiff line numberDiff line change
@@ -52,75 +52,58 @@ const (
5252
)
5353

5454
type EnumDetail struct {
55-
Short string `json:"short"`
56-
Long string `json:"long"`
55+
Key string `json:"key"`
5756
}
5857

5958
var FuelUnitDetails map[FuelUnit]EnumDetail = map[FuelUnit]EnumDetail{
6059
LITRE: {
61-
Short: "Lt",
62-
Long: "Litre",
60+
Key: "litre",
6361
},
6462
GALLON: {
65-
Short: "Gal",
66-
Long: "Gallon",
63+
Key: "gallon",
6764
}, KILOGRAM: {
68-
Short: "Kg",
69-
Long: "Kilogram",
65+
Key: "kilogram",
7066
}, KILOWATT_HOUR: {
71-
Short: "KwH",
72-
Long: "Kilowatt Hour",
67+
Key: "kilowatthour",
7368
}, US_GALLON: {
74-
Short: "US Gal",
75-
Long: "US Gallon",
69+
Key: "usgallon",
7670
},
7771
MINUTE: {
78-
Short: "Mins",
79-
Long: "Minutes",
72+
Key: "minutes",
8073
},
8174
}
8275

8376
var FuelTypeDetails map[FuelType]EnumDetail = map[FuelType]EnumDetail{
8477
PETROL: {
85-
Short: "Petrol",
86-
Long: "Petrol",
78+
Key: "petrol",
8779
},
8880
DIESEL: {
89-
Short: "Diesel",
90-
Long: "Diesel",
81+
Key: "diesel",
9182
}, CNG: {
92-
Short: "CNG",
93-
Long: "CNG",
83+
Key: "cng",
9484
}, LPG: {
95-
Short: "LPG",
96-
Long: "LPG",
85+
Key: "lpg",
9786
}, ELECTRIC: {
98-
Short: "Electric",
99-
Long: "Electric",
87+
Key: "electric",
10088
}, ETHANOL: {
101-
Short: "Ethanol",
102-
Long: "Ethanol",
89+
Key: "ethanol",
10390
},
10491
}
10592

10693
var DistanceUnitDetails map[DistanceUnit]EnumDetail = map[DistanceUnit]EnumDetail{
10794
KILOMETERS: {
108-
Short: "Km",
109-
Long: "Kilometers",
95+
Key: "kilometers",
11096
},
11197
MILES: {
112-
Short: "Mi",
113-
Long: "Miles",
98+
Key: "miles",
11499
},
115100
}
116101

117102
var RoleDetails map[Role]EnumDetail = map[Role]EnumDetail{
118103
ADMIN: {
119-
Short: "Admin",
120-
Long: "ADMIN",
104+
Key: "ADMIN",
121105
},
122106
USER: {
123-
Short: "User",
124-
Long: "USER",
107+
Key: "USER",
125108
},
126109
}

ui/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
"currency-formatter": "^1.5.7",
4242
"date-fns": "2.10.0",
4343
"lodash": "^4.17.21",
44+
"node-gyp": "^9.3.1",
4445
"normalize.css": "8.0.1",
4546
"nprogress": "0.2.0",
4647
"vue": "2.6.11",
4748
"vue-chartjs": "^3.5.1",
49+
"vue-i18n": "^8.28.2",
4850
"vue-meta": "2.3.3",
4951
"vue-router": "3.1.6",
5052
"vuex": "3.1.2"

ui/src/components/createQuickEntry.vue

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020
}
2121
} else {
2222
if (this.file == null) {
23-
return 'Upload Photo'
23+
return this.$t('uploadphoto')
2424
} else {
2525
return ''
2626
}
@@ -39,7 +39,7 @@ export default {
3939
.post(`/api/quickEntries`, formData)
4040
.then((data) => {
4141
this.$buefy.toast.open({
42-
message: 'Quick Entry Created Successfully',
42+
message: this.$t('quickentrycreatedsuccessfully'),
4343
type: 'is-success',
4444
duration: 3000,
4545
})
@@ -68,9 +68,9 @@ export default {
6868
<div class="section box">
6969
<div class="columns">
7070
<div class="column is-two-thirds">
71-
<p class="title">Quick Entry</p>
71+
<p class="title">{{ $tc('quickentry',1) }}</p>
7272
<p class="subtitle"
73-
>Take a pic of the invoice or the fuel pump display to make an entry later.</p
73+
>{{ $t('quickentrydesc') }}</p
7474
></div
7575
>
7676
<div class="column is-one-third is-flex is-align-content-center">
@@ -99,10 +99,10 @@ export default {
9999
native-type="submit"
100100
:disabled="tryingToCreate"
101101
type="is-primary"
102-
value="Upload File"
102+
:value="this.$t('uploadfile')"
103103
class="control"
104104
>
105-
Upload File
105+
{{ $t('uploadfile') }}
106106
</b-button>
107107
</div></div
108108
>

ui/src/components/mileageChart.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
var labels = this.chartData.map((x) => x.date.substr(0, 10))
3131
var dataset = {
3232
steppedLine: true,
33-
label: `Mileage (${this.user.distanceUnitDetail.short}/${this.vehicle.fuelUnitDetail.short})`,
33+
label: `${this.$t('odometer')} (${this.$t('unit.short.' + this.user.distanceUnitDetail.key)}/${this.$t('unit.short.' + this.vehicle.fuelUnitDetail.key)})`,
3434
fill: true,
3535
data: this.chartData.map((x) => x.mileage),
3636
}

ui/src/components/nav-bar.vue

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@ export default {
1010
persistentNavRoutes: [
1111
{
1212
name: 'home',
13-
title: 'Home',
13+
title: this.$t('menu.home'),
1414
},
1515
],
1616
loggedInNavRoutes: [
1717
{
1818
name: 'quickEntries',
19-
title: () => 'Quick Entries',
19+
title: () => this.$t('menu.quickentries'),
2020
badge: () => this.unprocessedQuickEntries.length,
2121
},
2222
{
2323
name: 'import',
24-
title: () => 'Import',
24+
title: () => this.$t('menu.import'),
2525
},
2626
{
2727
name: 'settings',
28-
title: 'Settings',
28+
title: this.$t('menu.settings'),
2929
},
3030
{
3131
name: 'logout',
32-
title: 'Log out',
32+
title: this.$t('menu.logout'),
3333
},
3434
],
3535
loggedOutNavRoutes: [
3636
{
3737
name: 'login',
38-
title: 'Log in',
38+
title: this.$t('menu.login'),
3939
},
4040
],
4141
adminNavRoutes: [
4242
{
4343
name: 'site-settings',
44-
title: 'Site Settings',
44+
title: this.$t('menu.sitesettings'),
4545
},
4646
{
4747
name: 'users',
48-
title: 'Users',
48+
title: this.$t('menu.users'),
4949
},
5050
],
5151
}
@@ -72,7 +72,7 @@ export default {
7272
<NavBarRoutes :routes="persistentNavRoutes" />
7373
<NavBarRoutes v-if="loggedIn" :routes="loggedInNavRoutes" />
7474
<NavBarRoutes v-else :routes="loggedOutNavRoutes" />
75-
<b-navbar-dropdown v-if="loggedIn && isAdmin" label="Admin">
75+
<b-navbar-dropdown v-if="loggedIn && isAdmin" :label="$t('menu.admin')">
7676
<NavBarRoutes :routes="adminNavRoutes" />
7777
</b-navbar-dropdown>
7878
</template>

ui/src/components/quickEntryDisplay.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export default {
5050
<b-select
5151
v-if="unprocessedQuickEntries.length"
5252
v-model="quickEntry"
53-
placeholder="Refer quick entry"
53+
:placeholder="this.$t('referquickentry')"
5454
expanded
5555
@input="showQuickEntry($event)"
5656
>
5757
<option v-for="option in unprocessedQuickEntries" :key="option.id" :value="option">
58-
Taken: {{ parseAndFormatDateTime(option.createdAt) }}
58+
{{ $t('created') }}: {{ parseAndFormatDateTime(option.createdAt) }}
5959
</option>
6060
</b-select>
6161
<p class="control">

ui/src/components/shareVehicle.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default {
5555
return
5656
}
5757
this.$buefy.dialog.confirm({
58-
title: 'Transfer Vehicle',
58+
title: this.$t('transfervehicle'),
5959
message: 'Are you sure you want to do this? You will lose ownership and all editing rights if you confirm.',
6060
cancelText: 'Cancel',
6161
confirmText: 'Go Ahead',
@@ -90,7 +90,7 @@ export default {
9090

9191
<template>
9292
<div class="box" style="max-width:600px">
93-
<h1 class="subtitle">Share {{ vehicle.nickname }}</h1>
93+
<h1 class="subtitle">{{ $t('share') }} {{ vehicle.nickname }}</h1>
9494
<section>
9595
<div class="columns is-mobile" v-for="model in models" :key="model.id">
9696
<div class="column is-one-third">
@@ -101,7 +101,7 @@ export default {
101101
</b-field> </div
102102
><div class="column is-three-quarters">
103103
<b-field>
104-
<b-button v-if="model.isShared && !model.isOwner" type="is-primary is-small" @click="transferVehicle(model)">Make Owner</b-button>
104+
<b-button v-if="model.isShared && !model.isOwner" type="is-primary is-small" @click="transferVehicle(model)">{{ $t('makeowner') }}</b-button>
105105
</b-field></div
106106
></div
107107
>

ui/src/components/statsWidget.vue

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import { addDays, addMonths } from 'date-fns'
3-
import currencyFormtter from 'currency-formatter'
3+
import currencyFormatter from 'currency-formatter'
44
import { mapState } from 'vuex'
55
66
import axios from 'axios'
@@ -14,12 +14,12 @@ export default {
1414
data: function() {
1515
return {
1616
dateRangeOptions: [
17-
{ label: 'This week', value: 'this_week' },
18-
{ label: 'This month', value: 'this_month' },
19-
{ label: 'Past 30 days', value: 'past_30_days' },
20-
{ label: 'Past 3 months', value: 'past_3_months' },
21-
{ label: 'This year', value: 'this_year' },
22-
{ label: 'All Time', value: 'all_time' },
17+
{ label: this.$t('thisweek'), value: 'this_week' },
18+
{ label: this.$t('thismonth'), value: 'this_month' },
19+
{ label: this.$tc('pastxdays', 30), value: 'past_30_days' },
20+
{ label: this.$tc('pastxmonths', 3), value: 'past_3_months' },
21+
{ label: this.$t('thisyear'), value: 'this_year' },
22+
{ label: this.$t('alltime'), value: 'all_time' },
2323
],
2424
dateRangeOption: 'past_30_days',
2525
stats: [],
@@ -32,15 +32,15 @@ export default {
3232
return [
3333
[
3434
{
35-
label: 'Total Expenditure',
35+
label: this.$t('totalexpenses'),
3636
value: this.formatCurrency(0, this.user.currency),
3737
},
3838
{
39-
label: 'Fillup Costs',
39+
label: this.$t('fillupcost'),
4040
value: `${this.formatCurrency(0, this.user.currency)} (0)`,
4141
},
4242
{
43-
label: 'Other Expenses',
43+
label: this.$t('otherexpenses'),
4444
value: `${this.formatCurrency(0, this.user.currency)} (0)`,
4545
},
4646
],
@@ -49,15 +49,15 @@ export default {
4949
return this.stats.map((x) => {
5050
return [
5151
{
52-
label: 'Total Expenditure',
52+
label: this.$t('totalexpenses'),
5353
value: this.formatCurrency(x.expenditureTotal, x.currency),
5454
},
5555
{
56-
label: 'Fillup Costs',
56+
label: this.$t('fillupcost'),
5757
value: `${this.formatCurrency(x.expenditureFillups, x.currency)} (${x.countFillups})`,
5858
},
5959
{
60-
label: 'Other Expenses',
60+
label: this.$t('otherexpenses'),
6161
value: `${this.formatCurrency(x.expenditureExpenses, x.currency)} (${x.countExpenses})`,
6262
},
6363
]
@@ -80,7 +80,7 @@ export default {
8080
if (!currencyCode) {
8181
currencyCode = this.me.currency
8282
}
83-
return currencyFormtter.format(number, { code: currencyCode })
83+
return currencyFormatter.format(number, { code: currencyCode })
8484
},
8585
getStats() {
8686
axios
@@ -129,7 +129,7 @@ export default {
129129
<template>
130130
<div>
131131
<div class="columns">
132-
<div class="column" :class="isMobile ? 'has-text-centered' : ''"> <h1 class="title">Stats</h1></div>
132+
<div class="column" :class="isMobile ? 'has-text-centered' : ''"> <h1 class="title">{{ $t('statistics') }}</h1></div>
133133
<div class="column">
134134
<b-select v-model="dateRangeOption" class="is-pulled-right is-medium">
135135
<option v-for="option in dateRangeOptions" :key="option.value" :value="option.value">

ui/src/i18n.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Vue from 'vue';
2+
import VueI18n from 'vue-i18n';
3+
4+
Vue.use(VueI18n);
5+
6+
function loadLocaleMessages () {
7+
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
8+
const messages = {}
9+
locales.keys().forEach(key => {
10+
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
11+
if (matched && matched.length > 1) {
12+
const locale = matched[1]
13+
messages[locale] = locales(key)
14+
}
15+
})
16+
return messages
17+
}
18+
19+
const i18n = new VueI18n({
20+
locale: navigator.language.split('-')[0] || 'en',
21+
fallbackLocale: 'en',
22+
messages: loadLocaleMessages()
23+
});
24+
25+
export default i18n;

0 commit comments

Comments
 (0)