@serendie/ui
Version:
Adaptive UI component library as part of Serendie Design System by Mitsubishi Electric
35 lines (34 loc) • 1.16 kB
JavaScript
import { useContext as l } from "react";
import { dictionary as u } from "./dictionary.js";
import { LanguageContext as s } from "./provider.js";
import { LanguageProvider as x, SerendieProvider as P } from "./provider.js";
function c(e) {
return function(r, t) {
let n = u[e][r];
return !n && e !== "ja" && (n = u.ja[r]), n ? (t && Object.entries(t).forEach(([a, f]) => {
const i = `{{${a}}}`;
n.includes(i) || console.warn(
`Placeholder "${i}" not found in translation "${n}"`
), n = n.replace(
new RegExp(`\\{\\{${a}\\}\\}`, "g"),
String(f)
);
}), n) : (console.warn(`Translation key "${r}" not found`), r);
};
}
function m() {
const e = l(s);
return !e && process.env.NODE_ENV === "development" && console.warn(
"SerendieProvider is not found. Using default language 'ja'. Consider wrapping your app with <SerendieProvider lang='ja'>"
), c(e || "ja");
}
function j(e, o) {
return new Date(e).toLocaleDateString(o === "en" ? "en-US" : "ja-JP");
}
export {
x as LanguageProvider,
P as SerendieProvider,
j as formatDateByLang,
c as getTranslations,
m as useTranslations
};