CircleCI

Yatapp

Welcome to Yata integration Hex package, this package will allow you to easy get your translations from http://yatapp.net service.

Installation

Add yatapp to your list of dependencies and to applications in mix.exs:

# mix.exs

def deps do
  [
    {:yatapp, "~> 0.1.2"}
  ]
end

def application do
  [applications: [
    :yatapp
end

Configuration

Package can be used in two ways:

  • integration through API
  • websocket integration

API Integration

Add configuration to your config/config.exs:

# config.exs

config :yatapp,
  api_key: System.get_env("YATA_API_KEY"),
  project_id: System.get_env("YATA_PROJECT_ID"),
  locales: ~w(en),
  translations_format: "yml",
  save_to_path: "priv/locales/",
  root: false,
  enable_websocket: false

API integration allows you to download all translation using mix task:

$ mix download_translations

Websocket Integration

Add configuration to your config/config.exs:

# config.exs

config :yatapp,
  api_key: System.get_env("YATA_API_KEY"),
  project_id: System.get_env("YATA_PROJECT_ID"),
  default_locale: "en",
  locales: ~w(en),
  fallback: false,
  enable_websocket: true,
  var_prefix: "%{",
  var_suffix: "}"

Websocket integration connects to Yata server and stays open. All changes in translations are auto-fetched to the app.

When app connects to the Yata server for the first time it fetches all translation and saves them to the ets table. Then all actions on translations like create, update and delete are broadcasting information and ets table is updated.

The values for given locale and key can be fetched using Yatappp.ExI18n module:

# Examples

# en
number: 1
hello_name: "Hello %{name}"

Yatapp.ExI18n.t("en", "number") #=> 1
Yatapp.ExI18n.t("en", "hello_name", %{name: "John"}) #=> "Hello John"

Configuration Parameters

OptionDescriptionDefaultWebsocketAPI
api_keyOrganization Settings > Security > API tokenrequiredrequired
project_idOrganization Settings > Security > Projects > Idrequiredrequired
default_localeDefault locale in your application."en"optional-
localesSupported locales.["en"]optionaloptional
fallbackFallback to default locale if translation empty.falseoptional-
translations_formatFormat you wish to get files in, available for now are (yml, js, json, properties, xml, strings, plist)"yml"-optional
save_to_pathA directory where translations will be saved."priv/locales/"-optional
rootDownload with language as a root element of the translationfalse-optional
enable_websocketEnable websocket integrationfalserequiredoptional
var_prefixPrefix to values in translations.%{optionaloptional
var_suffixSuffix for values in translations.}optionaloptional