Fluent (libfluent v0.2.4)
Module
Summary
Types
Name for Fluent's assembly. Should be valid module, that uses Fluent.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
.
Types
assembly()
@type assembly() :: module()
Name for Fluent's assembly. Should be valid module, that uses Fluent.Assembly
bundle()
@type bundle() :: reference()
Native container, that is firstly identified and then used for translations
locale()
@type locale() :: String.t()
Represents locale. Basically it's a string, that has valid locale identifier
Functions
get_locale(assembly)
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"
known_locales(assembly)
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"]
put_locale(locale)
@spec put_locale(locale()) :: nil
put_locale(assembly, locale)
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"
with_locale(locale, fun)
@spec 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"
with_locale(assembly, locale, 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
.
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"