Skip to content

Commit

Permalink
feat: add german language support
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrehm authored and itlamb committed Feb 6, 2024
1 parent 6b4e5a2 commit 48dcfb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion development.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ To set up the project locally for development and testing, please follow these s
```
- **constants** - all constants that are globally used and should not change during usage of app, e.g.: height and width of cell, width of single tile.
- **context** - folder that consists CalendarProvider and LocaleProvider
- **locales** - folder that consists files with translations (currently en / pl)
- **locales** - folder that consists files with translations (currently en / pl / de)
- **types** - folder that consists all global types and type guards
- **utils** - folder that consists all utility functions used within app (e.g. drawing all the grid, data parsers etc.)
Expand Down
5 changes: 4 additions & 1 deletion src/context/LocaleProvider/LocaleProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useState } from "react";
import dayjs from "dayjs";
import en from "dayjs/locale/en";
import pl from "dayjs/locale/pl";
import de from "dayjs/locale/de";
import { LangCodes } from "@/types/global";
import { localeContext } from "./localeContext";
import { locales } from "./locales";
Expand All @@ -14,7 +15,9 @@ const LocaleProvider = ({ children, lang }: LocaleProviderProps) => {
const locale = locales.find((l) => {
return l.id === localLang;
});
locale?.id === "en" ? dayjs.locale({ ...en }) : dayjs.locale({ ...pl });
locale?.id === "en" && dayjs.locale({ ...en });
locale?.id === "pl" && dayjs.locale({ ...pl });
locale?.id === "de" && dayjs.locale({ ...de });
return locale || locales[0];
}, [localLang]);

Expand Down
7 changes: 7 additions & 0 deletions src/context/LocaleProvider/locales.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { en } from "@/locales/en";
import { pl } from "@/locales/pl";
import { de } from "@/locales/de";
import { LocaleType } from "./types";

export const locales: LocaleType[] = [
Expand All @@ -14,5 +15,11 @@ export const locales: LocaleType[] = [
name: "POLISH",
lang: pl,
translateCode: "pl-PL"
},
{
id: "de",
name: "GERMAN",
lang: de,
translateCode: "de-DE"
}
];
17 changes: 17 additions & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const de = {
feelingEmpty: "Keine Ergebnisse...",
free: "Frei",
loadNext: "Weiter",
loadPrevious: "Zurück",
over: "über",
taken: "Gebucht",
topbar: {
filters: "Filter",
next: "vor",
prev: "zurück",
today: "Heute",
view: "Ansicht"
},
search: "Suche",
week: "Woche"
};
4 changes: 2 additions & 2 deletions src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type FilterButtonState = -1 | 0 | 1;
type ZoomLevelTuple = typeof allZoomLevel;

export type ZoomLevel = ZoomLevelTuple[number];
export type LangCodes = "en" | "pl";
export type LangCodes = "en" | "pl" | "de";
export type Config = {
zoom: ZoomLevel;
/**
Expand All @@ -16,7 +16,7 @@ export type Config = {
*/
filterButtonState?: number;
/**
* Language code: "en" | "pl"
* Language code: "en" | "pl" | "de"
*/
lang?: LangCodes;
isFiltersButtonVisible?: boolean;
Expand Down

0 comments on commit 48dcfb9

Please sign in to comment.