GithubHelp home page GithubHelp logo

kohorizon / next-intl-clean-ssr-clientside-implementation Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 63 KB

This project demonstrate a clean implemenation of an Internationalization system based on the next-intl package.

TypeScript 92.78% CSS 4.64% JavaScript 2.58%

next-intl-clean-ssr-clientside-implementation's Introduction

Clean Internationalization implementation with Next-intl

This project serves as a demonstration of how to set up internationalization (i18n) using the next-intl package in a Next.js 13 application using the App router system. A standout feature of this implementation is the customized structure of the translation folder, allowing for greater flexibility and organization of translation files.

Here an example on how you can customize your translations content.

.
├── translations
│   ├── en
│   │   ├── translations1.json
│   │   ├── common
│   │   │   └── translations2.json
│   │   └── ...
│   ├── fr
│   │   ├── translations1.json
│   │   ├── common
│   │   │   └── translations2.json
│   │   └── ...
│   └── other language 
└── ...

With this architecture, you do not have to pass any props to access your translation key in your “json files”.

If you want to access “common/translation2.json” in the client side or the server side, you can do so like this :

import { useTranslations } from "next-intl";
const t = useTranslations("common"); // This is your page

// In your tsx :
<h1>{t("translations2.keyYouWantToAccess")} </h1> // Access your key like in a regular json file

If you want to move the “translations” folder, do so by modifying this line in the i18n.ts file :

const context = require.context('./translations', true, /\.json$/);

⚠️ Do not use '.' in your Namespace keys: "." is used to express nesting.

next-intl-clean-ssr-clientside-implementation's People

Contributors

kohorizon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.