Skip to main content

Elixir

Learn how to integrate your Elixir app with Lokalise.

Written by Ilya Krukowski
Updated today

We offer a dedicated integration for Elixir apps that enables you to easily exchange translation files.

Prerequisites


Installation

Install the package:

def deps do
[
{:ex_lokalise_transfer, "~> 0.1.0"}
]
end


Configuration

Find more information in the repo.

The following config is required globally.

Configure the Lokalise API token:

config :elixir_lokalise_api,
api_token: {:system, "LOKALISE_API_TOKEN"}

Configure the Lokalise project ID:

config :ex_lokalise_transfer,
project_id: {:system, "LOKALISE_PROJECT_ID"}


Downloading translation files

Sync download

Downloads a bundle directly and extracts it locally.

# You can also use ExLokaliseTransfer.download_sync()
ExLokaliseTransfer.download(
body: [
format: "json",
original_filenames: false
],
extra: [
extract_to: "./priv/locales"
]
)

Async download

Enqueues a bundle build in Lokalise, waits for completion, then downloads and extracts it.

ExLokaliseTransfer.download_async(
body: [
format: "json"
],
poll: [
max_attempts: 15,
min_sleep_ms: 3_000,
max_sleep_ms: 60_000,
jitter: :centered
],
extra: [
extract_to: "./priv/locales"
]
)


Uploading translation files

Uploads multiple locale files and processes them asynchronously.

{:ok, summary} =
ExLokaliseTransfer.upload(
body: [
format: "json"
],
extra: [
locales_path: "./priv/locales",
include_patterns: ["*.json"],
exclude_patterns: [],
lang_resolver: :basename
],
poll: [
max_attempts: 10,
min_sleep_ms: 3_000,
max_sleep_ms: 60_000,
jitter: :centered
]
)
Did this answer your question?