mirror of
https://github.com/actix/examples
synced 2024-11-30 17:14:35 +01:00
1a9a15c7db
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com> |
||
---|---|---|
.. | ||
locales | ||
src | ||
templates | ||
Cargo.toml | ||
README.md |
Fluent Templates
This is an example of how to integrate Fluent Templates with Actix Web using the Handlebars templating engine.
Directory Structure
src
: Rust source code for web server and endpoint configurationtemplates
: Handlebars templates (no text content is stored in the templates)locales
: Fluent files containing translations for English (en) and French (fr)
Usage
cd templating/fluent
cargo run
After starting the server, you may visit the following pages:
- http://localhost:8080
- http://localhost:8080/Alice/documents
- http://localhost:8080/Bob/passwords
- http://localhost:8080/some-non-existing-page - 404 error rendered using template
This example implements language selection using the standard Accept-Language header, which is sent by browsers according to OS/browser settings. To view the translated pages, pass the Accept-Encoding header with en
or fr
. Values which do not have associated translation files will fall back to English.
# using HTTPie
http :8080/Alice/documents Accept-Language:fr
# using cURL
curl http://localhost:8080/Alice/documents -H 'accept-language: fr'