Skip to content

Commit

Permalink
fix: sync currency with i18n correctly
Browse files Browse the repository at this point in the history
closes #47
  • Loading branch information
simonwep committed Jul 6, 2024
1 parent 2bf14af commit 2b7ff69
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/store/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeepReadonly, inject, reactive, readonly, ShallowRef, shallowRef, watch } from 'vue';
import { DeepReadonly, inject, reactive, readonly, ShallowRef, shallowRef, watch, watchEffect } from 'vue';
import { useStateHistory, useTime } from '@composables';
import { AvailableLocale, i18n } from '@i18n/index';
import { Storage } from '@storage/index';
Expand Down Expand Up @@ -94,18 +94,16 @@ export const createDataStore = (storage?: Storage): Store => {
return [...currentYear.expenses, ...currentYear.income];
};

watch(
() => state.currency,
(currency) => {
for (const locale of i18n.global.availableLocales) {
const formats = i18n.global.getNumberFormat(locale);
i18n.global.setNumberFormat(locale, {
...formats,
currency: { ...formats.currency, currency }
});
}
watchEffect(() => {
for (const locale of i18n.global.availableLocales) {
const formats = i18n.global.getNumberFormat(locale);

i18n.global.setNumberFormat(locale, {
...formats,
currency: { ...formats.currency, currency: state.currency }
});
}
);
});

watch(
() => state.locale,
Expand Down

0 comments on commit 2b7ff69

Please sign in to comment.