recipes/i18n

I18n

Internationalization support.

Fiber with i18n

Github StackBlitz

This is a quick example of how to use nicksnyder/go-i18n package to translate your Fiber application into multiple languages.

Demo

  • Run Fiber application;
  • Open http://127.0.0.1:3000/?unread=1 and see:
Hello Bob

    I have 1 unread email.
    Bob has 1 unread email.
  • Next, go to http://127.0.0.1:3000/?unread=4 and see pluralization of your message:
Hello Bob

    I have 4 unread emails.
    Bob has 4 unread emails.
  • OK. Try translation of other languages, just add &lang=es (or &lang=ru) query to the URL:
Hola Bob

    Tengo 4 correos electrΓ³nicos no leΓ­dos
    Bob tiene 4 correos electrΓ³nicos no leΓ­dos

Getting Started

go run main.go

Set ENV=development to enable template hot-reload:

ENV=development go run main.go

File Structure

i18n/
β”œβ”€β”€ lang/
β”‚   β”œβ”€β”€ active.en.toml   # English translations (default)
β”‚   β”œβ”€β”€ active.es.toml   # Spanish translations
β”‚   └── active.ru.toml   # Russian translations
β”œβ”€β”€ templates/
β”‚   └── index.html       # HTML template
β”œβ”€β”€ main.go              # Application entry point
β”œβ”€β”€ go.mod
└── go.sum

go-i18n docs