API Reference

class fluent.runtime.FluentLocalization(locales: List[str], resource_ids: List[str], resource_loader: AbstractResourceLoader, use_isolating: bool = False, bundle_class: Type[fluent.runtime.bundle.FluentBundle] = <class 'fluent.runtime.bundle.FluentBundle'>, functions: Optional[Dict[str, Callable[[Any], FluentType]]] = None)[source]

Generic API for Fluent applications.

This handles language fallback, bundle creation and string localization. It uses the given resource loader to load and parse Fluent data.

class fluent.runtime.AbstractResourceLoader[source]

Interface to implement for resource loaders.

resources(locale: str, resource_ids: List[str])Generator[List[Resource], None, None][source]

Yield lists of FluentResource objects, corresponding to each of the resource_ids. If there are multiple locations, this may yield multiple lists. If a resource isn’t found in any location, yield a partial list, but don’t yield empty lists.

class fluent.runtime.FluentResourceLoader(roots: Union[str, List[str]])[source]

Resource loader to read Fluent files from disk.

Different locales are in different locations based on locale code. The locale code should be encoded as {locale} in the roots, or in the resource_ids. This loader does not support loading resources for one bundle from different roots.

resources(locale: str, resource_ids: List[str])Generator[List[Resource], None, None][source]

Yield lists of FluentResource objects, corresponding to each of the resource_ids. If there are multiple locations, this may yield multiple lists. If a resource isn’t found in any location, yield a partial list, but don’t yield empty lists.

class fluent.runtime.FluentBundle(locales: List[str], functions: Optional[Dict[str, Callable[[Any], FluentType]]] = None, use_isolating: bool = True)[source]

Bundles are single-language stores of translations. They are aggregate parsed Fluent resources in the Fluent syntax and can format translation units (entities) to strings.

Always use FluentBundle.get_message to retrieve translation units from a bundle. Generate the localized string by using format_pattern on message.value or message.attributes[‘attr’]. Translations can contain references to other entities or external arguments, conditional logic in form of select expressions, traits which describe their grammatical features, and can use Fluent builtins. See the documentation of the Fluent syntax for more information.