Allow passing language to each localization request
There should probably be an API that allows setting the language dynamically for each localization request (e.g. extracted from the Accept-Language header).
This would allow usages such as:
fn index_route(accept_language_header: String) -> String {
let language: LanguageIdentifier = negociate_language(accept_language_header); // Uses https://github.com/mike-engel/accept-language-rs to extract the languages from the header and compute the intersection with the available languages (fetched from `LanguageLoader` instance?)
fl!(LOADER, language, "greeting")
}
That seems like a good idea, thanks for the suggestion!
I'm wondering whether this should be added to the fl!() macro, only added to the FluentLanguageLoader and called separately? It may be difficult for the macro to distinguish between the language and other arguments if it is optional, because it lacks access to type information. At the moment, only a set of languages in a sequence of fallbacks are loaded. Some more thought about how this would impact the design and functionality is certainly required in a server context where the language may be switching for each request, and asynchronously. I'll have a bit more of a think about this tomorrow.
This idea doesn't fit with the current model of LanguageLoader, having a "current language" because it could change with every request and you would want all language resources to be loaded and ready to go at a moment's notice. I'm thinking the best way to approach this might be to make a new Fluent loader type, and a new macro (that shares code with the existing one).
I think the WIP pull request #62 is supposed to address this