-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathi18n.js
32 lines (27 loc) · 989 Bytes
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"use strict";
const NextI18Next = require("next-i18next");
const DEFAULT_LANGUAGE_FULL_CODE = "en-US";
const DEFAULT_LANGUAGE_SHORT_CODE = "en";
const options = {
defaultLanguage: DEFAULT_LANGUAGE_SHORT_CODE,
fallbackLng: DEFAULT_LANGUAGE_SHORT_CODE,
otherLanguages: ["fr"],
interpolation: {
format: function(value, format, lng) {
if (format === "uppercase") {
return value.toUpperCase();
}
if (format === "currency") {
return new Intl.NumberFormat(lng).format(Number(value)); // under node 11, only formats in US currency
}
if (value instanceof Date) {
return require("moment")(value).format(format); // @todo use lighter lib than moment
}
return value;
}
}
};
const nextI18NextInstance = new NextI18Next(options);
module.exports = nextI18NextInstance;
module.exports.DEFAULT_LANGUAGE_FULL_CODE = DEFAULT_LANGUAGE_FULL_CODE;
module.exports.DEFAULT_LANGUAGE_SHORT_CODE = DEFAULT_LANGUAGE_SHORT_CODE;