Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexxandergrib/i18n-typescript-how-to
TypeScript + i18n done properly
https://github.com/alexxandergrib/i18n-typescript-how-to
i18n typesafe typescript
Last synced: 1 day ago
JSON representation
TypeScript + i18n done properly
- Host: GitHub
- URL: https://github.com/alexxandergrib/i18n-typescript-how-to
- Owner: AlexXanderGrib
- Created: 2023-04-08T15:36:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-04-08T15:39:08.000Z (over 1 year ago)
- Last Synced: 2024-05-21T04:52:51.176Z (6 months ago)
- Topics: i18n, typesafe, typescript
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TypeScript + i18n done properly
**All source in [`i18n/`](./i18n)**
- Absolute type safety, no more "`translation.common.app.name`"
- Works with TypeScript 4.9+
- Requires no interaction with `fs` or `fetch`. All done by your bundler/runtime
- Caches loaded locales.
- No codegen## Example (Next.JS)
```typescript
// @/i18n/locales/en/index.tsexport const en = {
hello: "Hello world!"
}```
```tsx
// pages/index.tsx
import { loadLocale, checkLocale } from "@/i18n";
import type { GetStaticProps, InferGetStaticPropsType } from "next"export function getStaticProps({ locale }) {
return {
props: {
translation: await loadLocale(checkLocale(locale))
}
}
} satisfies GetStaticProps;export function Home({ translation }: InferGetStaticPropsType) {
return{translation.hello}
;
// ^? (property) hello: string
}```