Rocket Lang
Rocket-lang provides a configurable enum type for multi-language rocket applications.
LangCode
A request guard corresponding to the ISO 639-1 code standard. Usage example:
Config
The behavior of the enum can be configured with the Config structure, which can be attached to a rocket instance.
When this is not used, the guard defaults to English.
accept_language
If the preferred method for language resolution is the http accept-language header, the qualities for each language can be set like this:
let config = new;
let config = 1.0;
let config = 0.5;
url
The guard can also be configured to extract the language code from a fixed position in the path:
/// takes the language code from the last path segment:
let config = new.url;
This way the language code can be retrieved from a positional url segment.
custom
If none of the previous approaches suit your needs, you may also use a closure to create a language code from a request:
let config = custom;
Composable
Other request guards can consume the structure in their API. Most notably, it can be used by foreign structures to return error messages in multiple languages.
use Error;
// here the error message displayed by
// `Unauthorized` will automatically suit the callers configuration.
// A possible implementation of `Unauthorized`