Commit 4f96ce61 authored by  JosephK's avatar JosephK

Merge branch 'master' into 'master'

EUR function replaced by vue-i18n number localization

See merge request !29
parents 5cc8dbb2 a234e65e
Pipeline #136078 passed with stage
in 2 minutes and 37 seconds
......@@ -111,16 +111,14 @@ export default {
if (!this.list[i].monthly
&& new Date(this.start) < new Date(this.list[i].date.replace(/ /g,"T"))) {
if (this.list[i].campaign === 'mobilizon') {
for (let j = 0; j < this.rewards.length; j += 1) {
if (this.list[i].don >= this.rewards[j]) {
if (j !== this.rewards.length - 1) {
if (this.list[i].don < this.rewards[j + 1]) {
this.donators[`rwd-${this.rewards[j]}`].push(this.list[i]);
}
} else {
for (let j = 0; j < this.rewards.length; j += 1) {
if (this.list[i].don >= this.rewards[j]) {
if (j !== this.rewards.length - 1) {
if (this.list[i].don < this.rewards[j + 1]) {
this.donators[`rwd-${this.rewards[j]}`].push(this.list[i]);
}
} else {
this.donators[`rwd-${this.rewards[j]}`].push(this.list[i]);
}
}
}
......@@ -128,11 +126,6 @@ export default {
}
this.rewards = this.rewards.reverse();
},
EUR(number) {
return new Intl
.NumberFormat(this.$i18n.locale, { style: 'currency', currency: 'EUR', minimumSignificantDigits: 1 })
.format(Number.parseFloat(number).toFixed(2));
},
}
}
</script>
......@@ -17,8 +17,8 @@
<!-- Right column -->
<b-col id="funding" lg="5" order-lg="12">
<p>
<span id="donations" class="h2" v-text="EUR(progress.total)"></span><br>
<span class="text-muted" v-html="`${$t('home.funding.goal')} ${EUR(progress.max)}`"></span>
<span id="donations" class="h2" v-text="$n(progress.total, 'eur')"></span><br>
<span class="text-muted" v-html="`${$t('home.funding.goal')} ${$n(progress.max, 'eur')}`"></span>
</p>
<div v-if="activeStep === 0">
......@@ -30,7 +30,7 @@
<div class="progress-meter">
<div class="meter meter-right" style="width: 100%;">
<span class="meter-text">
{{ EUR(steps[0]) }}<br><span v-html="$t('home.funding.step-on', {step: 1, max: steps.length})"></span>
{{ $n(steps[0], 'eur') }}<br><span v-html="$t('home.funding.step-on', {step: 1, max: steps.length})"></span>
</span>
</div>
</div>
......@@ -44,7 +44,7 @@
<div class="progress-meter">
<div class="meter meter-right" style="width: 43%;">
<span class="meter-text">
{{ EUR(steps[1]) }}<br><span v-html="$t('home.funding.step-on', {step: 2, max: steps.length})"></span>
{{ $n(steps[1], 'eur') }}<br><span v-html="$t('home.funding.step-on', {step: 2, max: steps.length})"></span>
</span></div>
<div class="meter meter-right" style="width: 57%;">
<span class="meter-text"></span>
......@@ -59,7 +59,7 @@
</b-progress-bar>
</b-progress>
<div class="progress-meter">
<div class="meter meter-right" style="width: 30%;"><span class="meter-text">{{ EUR(steps[2]) }}</span></div>
<div class="meter meter-right" style="width: 30%;"><span class="meter-text">{{ $n(steps[2], 'eur') }}</span></div>
<div class="meter meter-right" style="width: 30%;"><span class="meter-text"></span></div>
<div class="meter meter-right" style="width: 40%;"><span class="meter-text"></span></div>
</div>
......@@ -226,7 +226,7 @@
<h4 class="text-center font-weight-bolder">
<span v-html="$t(`home.steps.${file}.title`)"></span><br>
<i v-if="index < 3"
v-html="EUR(steps[index])"
v-html="$n(steps[index], 'eur')"
></i>
</h4>
<b-card-img :src="`${$root['/']}img/0${index + 1}-palier-mobilizon-${file}.png`" class="rounded-0"></b-card-img>
......@@ -294,8 +294,6 @@
</template>
<script>
import utils from '../utils';
import ShareAndFollow from '../partials/ShareAndFollow.vue';
import Allocation from './sections/Allocation.vue';
......@@ -387,9 +385,6 @@ export default {
}
}
},
EUR(number) {
return utils.cachedEUR(this.$i18n.locale, number);
},
},
}
</script>
......@@ -15,11 +15,11 @@
<b-card-body>
<h4>
<span v-html="$t('home.allocation.if')"></span>
<b-dropdown right :text="EUR(steps[i])" variant="outline-secondary">
<b-dropdown right :text="$n(steps[i], 'eur')" variant="outline-secondary">
<b-dropdown-item v-for="(step, j in steps" :key="j"
@click="active = j"
>
{{ EUR(steps[j]) }}
{{ $n(steps[j], 'eur') }}
</b-dropdown-item>
</b-dropdown>
</h4>
......@@ -52,12 +52,5 @@ export default {
required: true,
}
},
methods: {
EUR(number) {
return new Intl
.NumberFormat(this.$i18n.locale, { style: 'currency', currency: 'EUR', minimumSignificantDigits: 1 })
.format(Number.parseFloat(number).toFixed(2));
},
}
}
</script>
......@@ -242,7 +242,7 @@
<div id="defiscalise">
<p
v-if="/(FR|GP|GF|RE|MQ|YT|NC|PF|PM|WF)/.test(form.country)"
v-html="$t('form.step3.defisc_text', { percent: `${form.defisc} %`, amount: `<b>${EUR(form.don)}</b>`, defisc: `<b>${EUR(+(Math.round(form.don - form.don * form.defisc / 100 + 'e+2') + 'e-2'))}</b>` })"
v-html="$t('form.step3.defisc_text', { percent: `${form.defisc} %`, amount: `<b>${$n(form.don, 'eur')}</b>`, defisc: `<b>${$n(form.don - form.don * form.defisc / 100, 'eur')}</b>` })"
></p>
</div>
</div>
......@@ -278,7 +278,7 @@
<button id="btnVerif" name="submit" value=""
class="btn btn-lg">
<span style="font-size: 22px;" v-html="$t('form.step3.i_give')"></span><br>
<span v-if="!isNaN(form.don)">{{ EUR(form.don) }}</span>
<span v-if="!isNaN(form.don)">{{ $n(form.don, 'eur') }}</span>
<span v-html="$t('form.step3.now')"></span>
</button>
</p>
......@@ -286,8 +286,6 @@
</template>
<script>
import utils from '../../utils';
export default {
props: {
amount: {
......@@ -340,9 +338,6 @@ export default {
}
},
methods: {
EUR(number) {
return utils.cachedEUR(this.$i18n.locale, number);
},
check(input) {
if (!this.form.state.defisc) {
// Fill requiered fields for DB
......
<template>
<b-collapse :id="`donators-${reward}`"
v-if="donators[`rwd-${reward}`].length > 0">
v-if="donators[`rwd-${reward}`].length > 0">
<b-list-group>
<b-list-group-item
href="#"
......@@ -12,27 +12,28 @@
<small>{{ donator.date | moment('from', 'now') }}</small>
</div>
<span v-if="donator.nickname !== 'Anonymous'"
class="rounded-circle letter-avatar pull-left"
:style="`background: ${['#ffd4d0', '#ffddbe', '#d7f0dc', '#b8efff'][Math.floor(Math.random() * 4)]}`"
v-text="donator.nickname.replace(/[^a-zA-Z0-9]/g, '').substr(0, 1).toUpperCase()"
class="rounded-circle letter-avatar pull-left"
aria-hidden="true"
:style="`background: ${['#ffd4d0', '#ffddbe', '#d7f0dc', '#b8efff'][Math.floor(Math.random() * 4)]}`"
v-text="donator.nickname.replace(/[^a-zA-Z0-9]/g, '').substr(0, 1).toUpperCase()"
></span>
<span v-else
class="rounded-circle letter-avatar pull-left"
aria-hidden="true"
class="rounded-circle letter-avatar pull-left"
aria-hidden="true"
>
<i class="fa fa-user"></i>
</span>
<i class="fa fa-user"></i>
</span>
<h5 class="pull-left">
<span class="don">
{{ EUR(donator.don) }}
</span><br>
<span class="don">
{{ $n(donator.don, 'eur') }}
</span>
<br>
<span v-if="donator.nickname !== 'Anonymous'" class="nickname">
{{ donator.nickname }}
</span>
{{ donator.nickname }}
</span>
<span v-else
v-html="$t('home.funding.anonymous')"
class="nickname"
v-html="$t('home.funding.anonymous')"
class="nickname"
></span>
</h5>
......@@ -43,8 +44,6 @@
</template>
<script>
import utils from '../../utils';
export default {
props: {
donators: {
......@@ -56,10 +55,5 @@ export default {
required: true,
},
},
methods: {
EUR(number) {
return utils.cachedEUR(this.$i18n.locale, number);
},
},
}
</script>
import * as memoize from 'memoizee';
const cachedEUR = memoize((locale, number) => new Intl
.NumberFormat(locale, { style: 'currency', currency: 'EUR', minimumSignificantDigits: 1 })
.format(Number.parseFloat(number).toFixed(2)), { length: 1000 });
export default { cachedEUR };
......@@ -66,6 +66,7 @@ const userLang = navigator.languages
let defaultRouteLang = '';
const messages = {};
const numberFormats = {};
messages.locales = require('./data/lang.yml'); // eslint-disable-line
messages.locales.available = Object.keys(messages.locales).filter(n => locales.indexOf(n) > -1);
......@@ -119,11 +120,18 @@ Object.keys(data.link).forEach((k) => {
const routes = [];
for (let i = 0; i < locales.length; i += 1) {
messages[locales[i]] = {};
numberFormats[locales[i]] = {};
// Locales import
/* eslint-disable */
messages[locales[i]] = require(`./locales/${locales[i]}.yml`);
messages[locales[i]].data = data;
messages[locales[i]].lang = locales[i];
numberFormats[locales[i]].eur = {
style: 'currency',
currency: 'EUR',
maximumFractionDigits: 2,
minimumFractionDigits: 0,
};
if (dataLocales.includes(locales[i])) {
const dataLocale = require(`./data/locales/${locales[i]}.yml`);
......@@ -179,6 +187,7 @@ const i18n = new VueI18n({
locale: lang,
fallbackLocale: defaultLocale,
messages,
numberFormats,
silentTranslationWarn: true,
});
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment