Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A demo application that showcase how to implement a language switcher

NotificationsYou must be signed in to change notification settings

adonisjs-community/i18n-language-switcher

Repository files navigation

The repo contains code for a demo application that showcase how to implement a language switcher.

The language switcher stores the user preferred language within sessions and displays the translated text for the selected language.

Usage

Following are the steps to get the application running on your computer.

  • Clone the repo
  • Install dependencies by runningnpm install oryarn install
  • Copy.env.example to.env.
  • Start the development server by runningnode ace serve --watch

Visit the homepage and use the language dropdown on the top right to switch between the languages.

Storing the preferred language

  • Everytime the user selects a language, we make a POST request to the/language/:locale endpoint and update the user language to the selected language.
  • Yes, it should be a POST request and not GET. TheGET requests can have unwanted side-effects if you have prefetching enabled.

Displaying translated content

  • On every HTTP request, theDetectUserLocale midddleware reads the user preferred language from the session.
  • Check it against the locales supported by the application.
  • And uses theswitchLocale method to update the locale for the rest of the request.
  • From here onctx.i18n and thet helper inside templates will use the user preferred language.

About

A demo application that showcase how to implement a language switcher

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp