Skip to content

Commit

Permalink
revert formatter change #2247 because of caching not working anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Oct 25, 2024
1 parent e06b033 commit 0d719a0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 23.16.2

- revert formatter change [2247](https://github.com/i18next/i18next/pull/2247)

## 23.16.3

- fix utils imports for Deno
Expand Down
47 changes: 31 additions & 16 deletions i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,22 +1500,37 @@
this.logger = baseLogger.create('formatter');
this.options = options;
this.formats = {
number: createCachedFormatter((lng, opt) => val => new Intl.NumberFormat(lng, {
...opt
}).format(val)),
currency: createCachedFormatter((lng, opt) => val => new Intl.NumberFormat(lng, {
...opt,
style: 'currency'
}).format(val)),
datetime: createCachedFormatter((lng, opt) => val => new Intl.DateTimeFormat(lng, {
...opt
}).format(val)),
relativetime: createCachedFormatter((lng, opt) => val => new Intl.RelativeTimeFormat(lng, {
...opt
}).format(val, opt.range || 'day')),
list: createCachedFormatter((lng, opt) => val => new Intl.ListFormat(lng, {
...opt
}).format(val))
number: createCachedFormatter((lng, opt) => {
const formatter = new Intl.NumberFormat(lng, {
...opt
});
return val => formatter.format(val);
}),
currency: createCachedFormatter((lng, opt) => {
const formatter = new Intl.NumberFormat(lng, {
...opt,
style: 'currency'
});
return val => formatter.format(val);
}),
datetime: createCachedFormatter((lng, opt) => {
const formatter = new Intl.DateTimeFormat(lng, {
...opt
});
return val => formatter.format(val);
}),
relativetime: createCachedFormatter((lng, opt) => {
const formatter = new Intl.RelativeTimeFormat(lng, {
...opt
});
return val => formatter.format(val, opt.range || 'day');
}),
list: createCachedFormatter((lng, opt) => {
const formatter = new Intl.ListFormat(lng, {
...opt
});
return val => formatter.format(val);
})
};
this.init(options);
}
Expand Down
2 changes: 1 addition & 1 deletion i18next.min.js

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions src/Formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,26 @@ class Formatter {

this.options = options;
this.formats = {
number: createCachedFormatter(
(lng, opt) => (val) => new Intl.NumberFormat(lng, { ...opt }).format(val),
),
currency: createCachedFormatter(
(lng, opt) => (val) =>
new Intl.NumberFormat(lng, { ...opt, style: 'currency' }).format(val),
),
datetime: createCachedFormatter(
(lng, opt) => (val) => new Intl.DateTimeFormat(lng, { ...opt }).format(val),
),
relativetime: createCachedFormatter(
(lng, opt) => (val) =>
new Intl.RelativeTimeFormat(lng, { ...opt }).format(val, opt.range || 'day'),
),
list: createCachedFormatter(
(lng, opt) => (val) => new Intl.ListFormat(lng, { ...opt }).format(val),
),
number: createCachedFormatter((lng, opt) => {
const formatter = new Intl.NumberFormat(lng, { ...opt });
return (val) => formatter.format(val);
}),
currency: createCachedFormatter((lng, opt) => {
const formatter = new Intl.NumberFormat(lng, { ...opt, style: 'currency' });
return (val) => formatter.format(val);
}),
datetime: createCachedFormatter((lng, opt) => {
const formatter = new Intl.DateTimeFormat(lng, { ...opt });
return (val) => formatter.format(val);
}),
relativetime: createCachedFormatter((lng, opt) => {
const formatter = new Intl.RelativeTimeFormat(lng, { ...opt });
return (val) => formatter.format(val, opt.range || 'day');
}),
list: createCachedFormatter((lng, opt) => {
const formatter = new Intl.ListFormat(lng, { ...opt });
return (val) => formatter.format(val);
}),
};
this.init(options);
}
Expand Down

0 comments on commit 0d719a0

Please sign in to comment.