Linguist.Vocabulary (Linguist v0.4.0) View Source

Defines lookup functions for given translation locales, binding interpolation.

Locales are defined with the locale/2 macro, accepting a locale name and either keyword list of translations or String path to evaluate for translations list.

For example, given the following translations:

locale "en", [
  flash: [
    notice: [
      hello: "hello %{first} %{last}",
    ]
  ],
  users: [
    title: "Users",
  ]
]

locale "fr", Path.join([__DIR__, "fr.exs"])

This module will compile this down to these functions:

def t("en", "flash.notice.hello", bindings \ []), do: # ...
def t("en", "users.title", bindings \ []), do: # ...
def t("fr", "flash.notice.hello", bindings \ []), do: # ...

Link to this section Summary

Functions

Compiles all the translations and inject the functions created in the current module.

Function used internally to load a yaml file.

Recursive function used internally for loading yaml files.

Embeds locales from provided source.

Link to this section Functions

Link to this macro

__using__(options)

View Source (macro)

Compiles all the translations and inject the functions created in the current module.

Function used internally to load a yaml file.

Please use the locale macro with a path to a yaml file - this function will not work as expected if called directly.

Recursive function used internally for loading yaml files.

Not intended for external use

Link to this macro

locale(name, source)

View Source (macro)

Embeds locales from provided source.

  • name - The String name of the locale, ie "en", "fr"
  • source -
    1. The String file path to eval that returns a keyword list of translations
    2. The Keyword List of translations

Examples

locale "en", [
  flash: [
    notice: [
      hello: "hello %{first} %{last}",
    ]
  ]
]

locale "fr", Path.join([__DIR__, "fr.exs"])