Skip to content

Commit

Permalink
feat: example with shared locales
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Apr 22, 2022
1 parent 239ea4b commit a844907
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 141 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-cycles-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@your-org/common-i18n": major
---

Initial common shared locales package example
6 changes: 6 additions & 0 deletions .changeset/slimy-maps-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs-app": minor
"remix-app": minor
---

Example and howto consume shared locales from @your-org/common-i18n
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Useful to
│ ├── remix-app (api)
│ └── vite-app
└── packages
├── common-i18n (locales...)
├── core-lib
├── db-main-prisma
├── eslint-config-bases (to shared eslint configs)
Expand All @@ -71,12 +72,13 @@ Useful to
- [packages/db-main-prisma](./packages/db-main-prisma): used by web-app. [README](./packages/db-main-prisma/README.md) | [CHANGELOG](./packages/db-main-prisma/CHANGELOG.md)
- [packages/eslint-config-bases](./packages/eslint-config-bases): [README](./packages/eslint-config-bases/README.md) | [CHANGELOG](./packages/eslint-config-bases/CHANGELOG.md)
- [packages/ui-lib](./packages/ui-lib): publishable. [README](./packages/ui-lib/README.md) | [CHANGELOG](./packages/ui-lib/CHANGELOG.md)
- [packages/common-i18n](./packages/common-i18n): [README](./packages/common-i18n/README.md) | [CHANGELOG](./packages/common-i18n/CHANGELOG.md)

> Apps can depend on packages, packages can depend on each others...
#### Shared static assets

If needed static resources like **locales**, **images**,... can be shared by using symlinks in the repo.
If needed static resources like **images**,... can be shared by using symlinks in the repo.

- See the global [static](./static) folder.

Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs-app/e2e/pages/index/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import homeJsonEn from '@/public/locales/en/demo.json';
import homeJsonFr from '@/public/locales/fr/demo.json';
import homeJsonEn from '@your-org/common-i18n/locales/en/demo.json';
import homeJsonFr from '@your-org/common-i18n/locales/fr/demo.json';

test.describe('Demo page', () => {
test('should have the title in english by default', async ({ page }) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs-app/e2e/pages/system/404.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import systemJsonEn from '@/public/locales/en/system.json';
import systemJsonFR from '@/public/locales/fr/system.json';
import systemJsonEn from '@your-org/common-i18n/locales/en/system.json';
import systemJsonFr from '@your-org/common-i18n/locales/fr/system.json';

const pageSlug = 'this-page-does-not-exist';

Expand All @@ -13,6 +13,6 @@ test.describe('404 not found page', () => {
test('should have the title in french', async ({ page }) => {
await page.goto(`/fr/${pageSlug}`);
const title = await page.title();
expect(title).toBe(systemJsonFR.notFound.title);
expect(title).toBe(systemJsonFr.notFound.title);
});
});
4 changes: 2 additions & 2 deletions apps/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"vercel-build": "yarn share-static-hardlink && next build",
"start": "next start",
"bundle-analyze": "cross-env ANALYZE=true NEXTJS_IGNORE_TYPECHECK=1 NEXTJS_IGNORE_ESLINT=1 NEXTJS_SENTRY_UPLOAD_DRY_RUN=1 yarn build",
"?share-static-symlink": "echo 'Use this command to link assets, locales... from shared static folder'",
"?share-static-symlink": "echo 'Use this command to link assets... from shared static folder'",
"share-static-symlink": "rimraf ./public/shared-assets && symlink-dir ../../static/assets ./public/shared-assets",
"?share-static-hardlink": "echo 'Use this command to link assets, locales... from shared static folder'",
"?share-static-hardlink": "echo 'Use this command to link assets... from shared static folder'",
"share-static-hardlink": "rimraf ./public/shared-assets && syncdir ../../static/assets ./public/shared-assets --copy",
"check-dist": "es-check -v",
"check-build-size": "size-limit --highlight-less",
Expand Down
10 changes: 0 additions & 10 deletions apps/nextjs-app/public/locales/en/common.json

This file was deleted.

5 changes: 0 additions & 5 deletions apps/nextjs-app/public/locales/en/demo.json

This file was deleted.

9 changes: 0 additions & 9 deletions apps/nextjs-app/public/locales/en/home.json

This file was deleted.

8 changes: 0 additions & 8 deletions apps/nextjs-app/public/locales/en/system.json

This file was deleted.

10 changes: 0 additions & 10 deletions apps/nextjs-app/public/locales/fr/common.json

This file was deleted.

5 changes: 0 additions & 5 deletions apps/nextjs-app/public/locales/fr/demo.json

This file was deleted.

9 changes: 0 additions & 9 deletions apps/nextjs-app/public/locales/fr/home.json

This file was deleted.

8 changes: 0 additions & 8 deletions apps/nextjs-app/public/locales/fr/system.json

This file was deleted.

1 change: 1 addition & 0 deletions apps/nextjs-app/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BadRequest } from '@tsed/exceptions';

import type { GetStaticProps, InferGetStaticPropsType } from 'next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { homeConfig } from '@/features/home/home.config';
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/types.d/react-i18next.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://react.i18next.com/latest/typescript
*/
import 'react-i18next';
import type { I18nNamespaces } from '@your-org/common-i18n/index';
import type { I18nNamespaces } from '@your-org/common-i18n';

declare module 'react-i18next' {
interface CustomTypeOptions {
Expand Down
5 changes: 4 additions & 1 deletion apps/nextjs-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"@/pages/*": ["./pages/*"],
"@/public/*": ["../public/*"],
"@/themes/*": ["./themes/*"],
"@your-org/common-i18n/*": ["../../../packages/common-i18n/src/*"],
"@your-org/common-i18n": ["../../../packages/common-i18n/src/index"],
"@your-org/common-i18n/locales/*": [
"../../../packages/common-i18n/src/locales/*"
],
"@your-org/ui-lib/*": ["../../../packages/ui-lib/src/*"],
"@your-org/ui-lib": ["../../../packages/ui-lib/src/index"],
"@your-org/core-lib/*": ["../../../packages/core-lib/src/*"],
Expand Down
4 changes: 2 additions & 2 deletions apps/remix-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"watch-tailwind": "tailwindcss -o ./src/tailwind.css --watch",
"remix-dev": "remix dev",
"clean": "rimraf --no-glob ./.cache ./coverage ./src/tailwind.css ./tsconfig.tsbuildinfo ./.eslintcache && jest --clear-cache",
"?share-static-symlink": "echo 'Use this command to link assets, locales... from shared static folder'",
"?share-static-symlink": "echo 'Use this command to link assets... from shared static folder'",
"share-static-symlink": "rimraf ./public/shared-assets && symlink-dir ../../static/assets ./public/shared-assets",
"?share-static-hardlink": "echo 'Use this command to link assets, locales... from shared static folder'",
"?share-static-hardlink": "echo 'Use this command to link assets... from shared static folder'",
"share-static-hardlink": "rimraf ./public/shared-assets && syncdir ../../static/assets ./public/shared-assets --copy",
"test": "yarn test-unit",
"test-unit": "jest --config jest.config.js",
Expand Down
4 changes: 4 additions & 0 deletions apps/remix-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"@/lib/*": ["./src/lib/*"],
"@/routes/*": ["./src/routes/*"],
"@/test-utils": ["./config/jest/test-utils"],
"@your-org/common-i18n": ["../../../packages/common-i18n/src/index"],
"@your-org/common-i18n/locales/*": [
"../../../packages/common-i18n/src/locales/*"
],
"@your-org/ui-lib/*": ["../../packages/ui-lib/src/*"],
"@your-org/ui-lib": ["../../packages/ui-lib/src/index"],
"@your-org/core-lib/*": ["../../packages/core-lib/src/*"],
Expand Down
51 changes: 0 additions & 51 deletions packages/common-i18n/jest.config.js

This file was deleted.

9 changes: 8 additions & 1 deletion packages/common-i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@your-org/common-i18n",
"version": "1.0.0",
"version": "0.1.0",
"license": "MIT",
"private": true,
"homepage": "https://github.com/belgattitude/nextjs-monorepo-example",
Expand All @@ -14,6 +14,13 @@
"url": "https://github.com/belgattitude"
},
"sideEffects": false,
"type": "module",
"exports": {
"./locales/*.json": {
"require": "./src/locales/*.json",
"import": "./src/locales/*.json"
}
},
"scripts": {
"clean": "rimraf --no-glob ./dist ./coverage ./tsconfig.tsbuildinfo ./.eslintcache && jest --clear-cache",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
Expand Down
4 changes: 2 additions & 2 deletions packages/common-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type demo from './locales/en/demo.json';
import type home from './locales/en/home.json';
import type system from './locales/en/system.json';

export type I18nNamespaces = {
export interface I18nNamespaces {
home: typeof home;
demo: typeof demo;
common: typeof common;
system: typeof system;
};
}
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/fr/demo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"page": {
"title": "Web-app | DAmo | nextjs-monorepo-example"
"title": "Web-app | Démo | nextjs-monorepo-example"
}
}
10 changes: 0 additions & 10 deletions static/locales/en/common.json

This file was deleted.

0 comments on commit a844907

Please sign in to comment.