GettextTranslator (gettext_translator v0.2.0)

View Source

A module for translating gettext files.

This module provides functionality to scan directories for gettext files, process translation folders, and summarize the results. It leverages helper functions and processors defined in other modules.

Overview

The main entry point of this module is the translate/2 function which:

  1. Scans the specified root directory for gettext files using Parser.scan/1.
  2. Processes each folder corresponding to a language.
  3. Summarizes the total number of translations made.

Languages that are defined in the provider's ignored_languages list will be skipped, and a log message is generated.

Example Usage

iex> provider = %{ignored_languages: ["fr", "de"]}
iex> root_path = "path/to/gettext"
iex> GettextTranslator.translate(provider, root_path)
{:ok, total_translations}

Summary

Functions

Translates the gettext files located at the given root path.

Functions

translate(provider, root_gettext_path)

Translates the gettext files located at the given root path.

This function performs the following steps:

  1. Scans the root_gettext_path for gettext files using Parser.scan/1.
  2. Processes each language folder found by filtering out languages that are ignored (as specified in the provider map's ignored_languages key) and running the translation process on the rest using Processor.run/2.
  3. Summarizes the total number of translations performed across all folders.

Parameters

  • provider: A map or struct that configures the translation process. It must include an ignored_languages key which is a list of language codes to be skipped.
  • root_gettext_path: The root directory path where gettext files are stored.

Return Value

Returns {:ok, total} where total is the sum of translations performed. If the scan fails, the function will return the corresponding error tuple.

Examples

iex> provider = %{ignored_languages: ["fr", "de"]}
iex> root_gettext_path = "path/to/gettext"
iex> GettextTranslator.translate(provider, root_gettext_path)
{:ok, total_translations}