libfluent v0.2.0 Fluent

Module

Link to this section Summary

Types

Name for Fluent's assembly. Should be valid module, that usesFluent.Assembly

Native container, that is firstly identified and then used for translations

Represents locale. Basically it's a string, that has valid locale identifier

Functions

Gets the locale for the current process and the given assembly. This function returns the value of the locale for the current process and the given assembly. If there is no locale for the current process and the given assembly, then either the global Fluent locale (if set), or the default locale for the given assembly, or the global default locale is returned. See the "Locale" section in the module documentation for more information.

Returns all the locales for which FTL files exist for the given assembly. If the translations directory for the given assembly doesn't exist, then an empty list is returned.

Sets the locale for the current process and the given assembly. The locale is stored in the process dictionary. locale must be a string; if it's not, an ArgumentError exception is raised.

Runs fun with the global Fluent locale set to locale. This function just sets the global Fluent locale to locale before running fun and sets it back to its previous value afterwards. Note that put_locale/2 is used to set the locale, which is thus set only for the current process (keep this in mind if you plan on spawning processes inside fun). The value returned by this function is the return value of fun.

Runs fun with the Fluent.Assembly locale set to locale for the given assembly. This function just sets the Fluent.Assembly locale for assembly to locale before running fun and sets it back to its previous value afterwards. Note that put_locale/2 is used to set the locale, which is thus set only for the current process (keep this in mind if you plan on spawning processes inside fun). The value returned by this function is the return value of fun.

Link to this section Types

Link to this type

assembly()

assembly() :: module()

Name for Fluent's assembly. Should be valid module, that usesFluent.Assembly

Link to this type

bundle()

bundle() :: reference()

Native container, that is firstly identified and then used for translations

Link to this type

locale()

locale() :: String.t()

Represents locale. Basically it's a string, that has valid locale identifier

Link to this section Functions

Link to this function

get_locale(assembly)

get_locale(assembly()) :: locale()

Gets the locale for the current process and the given assembly. This function returns the value of the locale for the current process and the given assembly. If there is no locale for the current process and the given assembly, then either the global Fluent locale (if set), or the default locale for the given assembly, or the global default locale is returned. See the "Locale" section in the module documentation for more information.

Examples

Fluent.get_locale(MyApp.Fluent)
#=> "en"
Link to this function

known_locales(assembly)

known_locales(assembly()) :: [locale()]

Returns all the locales for which FTL files exist for the given assembly. If the translations directory for the given assembly doesn't exist, then an empty list is returned.

Examples

With the following assembly:

defmodule MyApp.Fluent do
  use Fluent.Assembly, otp_app: :my_app
end

and the following translations directory:

my_app/priv/fluent
 en
 it
 pt_BR

then:

Fluent.known_locales(MyApp.Fluent)
#=> ["en", "it", "pt_BR"]
Link to this function

put_locale(locale)

put_locale(locale()) :: nil
Link to this function

put_locale(assembly, locale)

put_locale(assembly(), locale()) :: nil

Sets the locale for the current process and the given assembly. The locale is stored in the process dictionary. locale must be a string; if it's not, an ArgumentError exception is raised.

Examples

Fluent.put_locale(MyApp.Fluent, "pt_BR")
#=> nil
Fluent.get_locale(MyApp.Fluent)
#=> "pt_BR"
Link to this function

with_locale(locale, fun)

with_locale(locale(), (() -> result)) :: result when result: var

Runs fun with the global Fluent locale set to locale. This function just sets the global Fluent locale to locale before running fun and sets it back to its previous value afterwards. Note that put_locale/2 is used to set the locale, which is thus set only for the current process (keep this in mind if you plan on spawning processes inside fun). The value returned by this function is the return value of fun.

Examples

Fluent.put_locale("fr")
MyApp.Fluent.ftl("Hello world")
#=> "Bonjour monde"
Fluent.Assembly.with_locale "it", fn ->
  MyApp.Fluent.ftl("Hello world")
end
#=> "Ciao mondo"
MyApp.Fluent.ftl("Hello world")
#=> "Bonjour monde"
Link to this function

with_locale(assembly, locale, fun)

with_locale(assembly(), locale(), (() -> result)) :: result when result: var

Runs fun with the Fluent.Assembly locale set to locale for the given assembly. This function just sets the Fluent.Assembly locale for assembly to locale before running fun and sets it back to its previous value afterwards. Note that put_locale/2 is used to set the locale, which is thus set only for the current process (keep this in mind if you plan on spawning processes inside fun). The value returned by this function is the return value of fun.

Examples

Fluent.put_locale(MyApp.Fluent, "fr")
MyApp.Fluent.ftl("Hello world")
#=> "Bonjour monde"
Fluent.with_locale MyApp.Fluent, "it", fn ->
  MyApp.Fluent.ftl("Hello world")
end
#=> "Ciao mondo"
MyApp.Fluent.ftl("Hello world")
#=> "Bonjour monde"