Skip to content

Commit

Permalink
feat: add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovmiroslav committed Sep 2, 2023
1 parent f2c5fac commit b0b1dc1
Show file tree
Hide file tree
Showing 137 changed files with 1,706 additions and 312 deletions.
23 changes: 23 additions & 0 deletions @types/i18next.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import "i18next";
import common from "../public/locales/en/common.json";
import home from "../public/locales/en/home.json";
import discover from "../public/locales/en/discover.json";
import settings from "../public/locales/en/settings.json";
import search from "../public/locales/en/search.json";
import movie from "../public/locales/en/movie.json";

export const i18Resources = {
common,
home,
discover,
settings,
search,
movie,
} as const;

declare module "i18next" {
interface CustomTypeOptions {
defaultNS: "common";
resources: typeof i18Resources;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- e2e tests (Playwright)
- deployment to Vercel
- sensitive information security (environment variables)
- i18n

### Lighthouse reports
- Home page mobile
Expand Down
1 change: 1 addition & 0 deletions __mocks__/next/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "next-router-mock";
18 changes: 10 additions & 8 deletions e2e/app.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { test, expect, Page } from "@playwright/test";
import {
MOVIE_PAGE_TITLE_TEST_ID,
TITLE_MOVIE_CARD_TITLE_ATTRIBUTE_VALUE,
} from "../src/constants/e2e";
import { expect, Page, test } from "@playwright/test";
import { MOVIE_PAGE_TITLE_TEST_ID } from "../src/constants/e2e";
import { i18Resources } from "../@types/i18next";

const clickOnFirstMovieCardAndCheckMoviePageTitle = async (page: Page) => {
const elementTitle = i18Resources.common.components.TitleMovieCard.title;

const movieCard = await page
.getByRole("link")
.filter({ has: page.getByTitle(TITLE_MOVIE_CARD_TITLE_ATTRIBUTE_VALUE) })
.filter({ has: page.getByTitle(elementTitle) })
.first();

const movieCardTitle = await movieCard
.getByTitle(TITLE_MOVIE_CARD_TITLE_ATTRIBUTE_VALUE)
.getByTitle(elementTitle)
.first()
.textContent();

Expand Down Expand Up @@ -40,7 +40,9 @@ test(
await page.goto("/");

const navigation = await page.getByRole("navigation");
const searchLink = await navigation.getByText("Search");
const searchLink = await navigation.getByText(
i18Resources.common.tabs.search
);

await searchLink.click();

Expand Down
17 changes: 17 additions & 0 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @type {import('next-i18next').UserConfig}
*/
module.exports = {
debug: process.env.NODE_ENV === "development",
i18n: {
defaultLocale: "en",
locales: ["bg", "da", "de", "en", "es", "fr", "it", "nl", "pl", "pt", "ru"],
},
/** To avoid issues when deploying to some paas (vercel...) */
localePath:
typeof window === "undefined"
? require("path").resolve("./public/locales")
: "/locales",

reloadOnPrerender: process.env.NODE_ENV === "development",
};
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/** @type {import('next').NextConfig} */

const { i18n } = require("./next-i18next.config.js");

const nextConfig = {
reactStrictMode: true,
swcMinify: true,
Expand All @@ -14,6 +17,7 @@ const nextConfig = {

return config;
},
i18n,
};

module.exports = nextConfig;
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
"date-fns": "^2.29.3",
"eslint": "8.28.0",
"eslint-config-next": "13.0.5",
"i18next": "^22.0.0",
"lodash": "^4.17.21",
"next": "13.0.5",
"next-i18next": "^14.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "^13.1.2",
"react-intersection-observer": "^9.4.1",
"sanitize.css": "^13.0.0",
"typescript": "4.9.3",
Expand All @@ -47,6 +50,7 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"msw": "^0.49.2",
"next-router-mock": "^0.9.9",
"prettier": "^2.8.0",
"sass": "^1.56.1"
}
Expand Down
1 change: 1 addition & 0 deletions public/assets/icons/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions public/locales/bg/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tabs": {
"main": "Главна",
"search": "Търсене",
"favorites": "Любими",
"settings": "Настройки"
},
"components": {
"BackButton": {
"backButtonAriaLabel": "назад"
},
"FavoriteButton": {
"addToFavoritesAriaLabel": "добави към любими",
"removeFromFavoritesAriaLabel": "премахни от любими"
},
"TitleMovieCard": {
"title": "заглавие на филм"
}
},
"utils": {
"dates": {
"formatDurationToString": {
"hours": "ч",
"minutes": "м"
}
}
}
}
3 changes: 3 additions & 0 deletions public/locales/bg/discover.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"header": "Преглед"
}
11 changes: 11 additions & 0 deletions public/locales/bg/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"popular": {
"header": "Популярни"
},
"topRated": {
"header": "Най-добър рейтинг"
},
"genres": {
"header": "Жанрове"
}
}
14 changes: 14 additions & 0 deletions public/locales/bg/movie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"posters": {
"header": "Плакати"
},
"backdrops": {
"header": "Изображения"
},
"recommendations": {
"header": "Препоръки"
},
"similar": {
"header": "Подобни"
}
}
6 changes: 6 additions & 0 deletions public/locales/bg/search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"header": {
"inputPlaceholder": "Търсене",
"clearButton": "изчисти"
}
}
6 changes: 6 additions & 0 deletions public/locales/bg/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"language": {
"header": "Език"
},
"saveButtonText": "съхрани"
}
28 changes: 28 additions & 0 deletions public/locales/da/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tabs": {
"main": "Hoved",
"search": "Søg",
"favorites": "Foretrukne",
"settings": "Indstillinger"
},
"components": {
"BackButton": {
"backButtonAriaLabel": "tilbage"
},
"FavoriteButton": {
"addToFavoritesAriaLabel": "Tilføj til favoritter",
"removeFromFavoritesAriaLabel": "fjerne fra favoritter"
},
"TitleMovieCard": {
"title": "film titel"
}
},
"utils": {
"dates": {
"formatDurationToString": {
"hours": "t",
"minutes": "m"
}
}
}
}
3 changes: 3 additions & 0 deletions public/locales/da/discover.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"header": "Opdag"
}
11 changes: 11 additions & 0 deletions public/locales/da/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"popular": {
"header": "Populært"
},
"topRated": {
"header": "Bedst bedømt"
},
"genres": {
"header": "Genrer"
}
}
14 changes: 14 additions & 0 deletions public/locales/da/movie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"posters": {
"header": "Plakater"
},
"backdrops": {
"header": "Baggrunde"
},
"recommendations": {
"header": "Anbefalinger"
},
"similar": {
"header": "Lignende"
}
}
6 changes: 6 additions & 0 deletions public/locales/da/search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"header": {
"inputPlaceholder": "Søg",
"clearButton": "slet"
}
}
6 changes: 6 additions & 0 deletions public/locales/da/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"language": {
"header": "Sprog"
},
"saveButtonText": "gem"
}
28 changes: 28 additions & 0 deletions public/locales/de/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tabs": {
"main": "Startseite",
"search": "Suchen",
"favorites": "Favoriten",
"settings": "Einstellungen"
},
"components": {
"BackButton": {
"backButtonAriaLabel": "geh zurück"
},
"FavoriteButton": {
"addToFavoritesAriaLabel": "Zu den Favoriten hinzufügen",
"removeFromFavoritesAriaLabel": "Von Favoriten entfernen"
},
"TitleMovieCard": {
"title": "filmtitel"
}
},
"utils": {
"dates": {
"formatDurationToString": {
"hours": "s",
"minutes": "m"
}
}
}
}
3 changes: 3 additions & 0 deletions public/locales/de/discover.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"header": "Entdecken"
}
11 changes: 11 additions & 0 deletions public/locales/de/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"popular": {
"header": "Beliebt"
},
"topRated": {
"header": "Bestbewertet"
},
"genres": {
"header": "Genres"
}
}
14 changes: 14 additions & 0 deletions public/locales/de/movie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"posters": {
"header": "Poster"
},
"backdrops": {
"header": "Hintergründe"
},
"recommendations": {
"header": "Empfehlungen"
},
"similar": {
"header": "Ähnlich"
}
}
6 changes: 6 additions & 0 deletions public/locales/de/search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"header": {
"inputPlaceholder": "Suche",
"clearButton": "zu löschen"
}
}
6 changes: 6 additions & 0 deletions public/locales/de/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"language": {
"header": "Sprache"
},
"saveButtonText": "speichern"
}
28 changes: 28 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tabs": {
"main": "Main",
"search": "Search",
"favorites": "Favorites",
"settings": "Settings"
},
"components": {
"BackButton": {
"backButtonAriaLabel": "go back"
},
"FavoriteButton": {
"addToFavoritesAriaLabel": "add to favorites",
"removeFromFavoritesAriaLabel": "remove from favorites"
},
"TitleMovieCard": {
"title": "movie title"
}
},
"utils": {
"dates": {
"formatDurationToString": {
"hours": "h",
"minutes": "m"
}
}
}
}
3 changes: 3 additions & 0 deletions public/locales/en/discover.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"header": "Discover"
}
11 changes: 11 additions & 0 deletions public/locales/en/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"popular": {
"header": "Popular"
},
"topRated": {
"header": "Top rated"
},
"genres": {
"header": "Genres"
}
}
Loading

1 comment on commit b0b1dc1

@vercel
Copy link

@vercel vercel bot commented on b0b1dc1 Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.