libfluent v0.1.0 Fluent.Assembly

Link to this section Summary

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 PO 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 global Fluent locale for the current process. The locale is stored in the process dictionary. locale must be a string; if it's not, an ArgumentError exception is raised.

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.Assembly locale set to locale. This function just sets the global Fluent.Assembly 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()
Link to this type

locale()

locale() :: binary()

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 PO 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.Assembly do
  use Fluent.Assembly, otp_app: :my_app
end

and the following translations directory:

my_app/priv/Fluent.Assembly
 en
 it
 pt_BR

then:

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

put_locale(locale)

put_locale(locale()) :: nil

Sets the global Fluent locale for the current process. 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("pt_BR")
#=> nil
Fluent.get_locale()
#=> "pt_BR"
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.Assembly locale set to locale. This function just sets the global Fluent.Assembly 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.Assembly.put_locale("fr")
MyApp.Fluent.Assembly.Fluent.Assembly("Hello world")
#=> "Bonjour monde"
Fluent.Assembly.with_locale "it", fn ->
  MyApp.Fluent.Assembly.Fluent.Assembly("Hello world")
end
#=> "Ciao mondo"
MyApp.Fluent.Assembly.Fluent.Assembly("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.Assembly.put_locale(MyApp.Fluent.Assembly, "fr")
MyApp.Fluent.Assembly.Fluent.Assembly("Hello world")
#=> "Bonjour monde"
Fluent.Assembly.with_locale MyApp.Fluent.Assembly, "it", fn ->
  MyApp.Fluent.Assembly.Fluent.Assembly("Hello world")
end
#=> "Ciao mondo"
MyApp.Fluent.Assembly.Fluent.Assembly("Hello world")
#=> "Bonjour monde"