Add pt-br locale (#261)

This commit is contained in:
Luke Vella 2022-07-29 13:25:39 +01:00 committed by GitHub
parent 0b156fabe6
commit 1ef15682ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 226 additions and 18 deletions

View file

@ -50,6 +50,11 @@ const dayjsLocales: Record<
timeFormat: "24h",
import: () => import("dayjs/locale/sv"),
},
"pt-BR": {
weekStartsOn: "sunday",
timeFormat: "24h",
import: () => import("dayjs/locale/pt-br"),
},
};
dayjs.extend(localizedFormat);
@ -84,17 +89,17 @@ export const DayjsProvider: React.VoidFunctionComponent<{
// Using language instead of router.locale because when transitioning from homepage to
// the app via <Link locale={false}> it will be set to "en" instead of the current locale.
const locale = i18n.language;
const localeConfig = dayjsLocales[i18n.language];
const [weekStartsOn = dayjsLocales[locale].weekStartsOn, , setWeekStartsOn] =
const [weekStartsOn = localeConfig.weekStartsOn, , setWeekStartsOn] =
useLocalStorage<StartOfWeek>("rallly-week-starts-on");
const [timeFormat = dayjsLocales[locale].timeFormat, setTimeFormat] =
const [timeFormat = localeConfig.timeFormat, setTimeFormat] =
useLocalStorage<TimeFormat>("rallly-time-format");
const { value: dayjsLocale } = useAsync(async () => {
return await dayjsLocales[locale ?? "en"].import();
}, [locale]);
return await localeConfig.import();
}, [localeConfig]);
if (!dayjsLocale) {
// wait for locale to load before rendering content
@ -103,19 +108,26 @@ export const DayjsProvider: React.VoidFunctionComponent<{
dayjs.locale({
...dayjsLocale,
weekStart: weekStartsOn ? (weekStartsOn === "monday" ? 1 : 0) : undefined,
formats: {
...dayjsLocale.formats,
LT: timeFormat === "12h" ? "h:mm A" : "H:mm",
},
weekStart: weekStartsOn
? weekStartsOn === "monday"
? 1
: 0
: dayjsLocale.weekStart,
formats:
localeConfig.timeFormat !== timeFormat
? {
...dayjsLocale.formats,
LT: timeFormat === "12h" ? "h:mm A" : "H:mm",
}
: dayjsLocale.formats,
});
return (
<DayjsContext.Provider
value={{
dayjs,
weekStartsOn: weekStartsOn ?? dayjsLocales[locale].weekStartsOn,
timeFormat: timeFormat ?? dayjsLocales[locale].timeFormat,
weekStartsOn: weekStartsOn ?? localeConfig.weekStartsOn,
timeFormat: timeFormat ?? localeConfig.timeFormat,
setWeekStartsOn,
setTimeFormat,
}}