View Source GettextCheck (gettext_check v0.1.1)

GettextCheck module allows to check for missing translations in gettext po and pot files.

It is made to work with the elixir-gettext/gettext library.

Basic Overview

Using elixir-gettext/gettext on you elixir project will create a priv/gettext directory with the following structure:

priv/gettext
 en
    LC_MESSAGES
        default.po
 en_US
     LC_MESSAGES
         default.po

These files might be missing translations under msgstr (or msgstr[0] and msgstr[1] for plural translations). In a typical dev flow you would add the translations manually after extracting them from your code.

Runing GettextCheck before pushing your code to a CI/CD pipeline can help prevent pushing mising translations to production.

This library uses expo internally to parse the po/pot files.

Usage

Call mix gettext_check from the root of your project.

Any missing translations will be listed in the output with the respective line number

      Missing translations:

        text: 'Online'
        /app/priv/locales/ja/LC_MESSAGES/default.po:7364

Configuration

You need to specify the locale but the priv directory is optional (default to priv/gettext).

GettextCheck can be configured in two ways:

1. Command line options

  mix gettext_check --locale ja --priv priv/gettext

2. Mix config

  config :gettext_check,
    locale: "ja",
    priv: "priv/gettext"

Summary

Functions

Checks a file for missing translation and returns a list of formatted errors.

Gets any missing translation errors from a message.

Functions

@spec check(String.t()) :: [String.t()]

Checks a file for missing translation and returns a list of formatted errors.

Examples

iex> check("priv/locales/ja/LC_MESSAGES/default.po")
[
  "
    text: 'Online'
    /root/gettext_check/priv/locales/ja/LC_MESSAGES/default.po:7364
  ",
  "
    text: 'already assigned'
    /root/gettext_check/priv/locales/ja/LC_MESSAGES/errors.po:108
  "
]
Link to this function

get_errors(message, file_path)

View Source
@spec get_errors(Expo.Message.t(), String.t()) :: [String.t()] | nil

Gets any missing translation errors from a message.

Examples

iex> get_errors(%Message.Singular{msgid: ["foo"], msgstr: [""]}, "priv/locales/ja/LC_MESSAGES/default.po")
[
  "
    text: 'foo'
    /root/gettext_check/priv/locales/ja/LC_MESSAGES/default.po:2
  "
]

iex> get_errors(%Message.Singular{msgid: ["bar"], msgstr: ["bar"]}, "priv/locales/ja/LC_MESSAGES/default.po")
[]

iex> get_errors(%Message.Plural{msgid: ["bar"], msgid_plural: ["bars"], msgstr: %{0 => [""], 1 => [""]}}, "priv/locales/ja/LC_MESSAGES/default.po")
[
  "
    text: 'bar'
    /root/gettext_check/priv/locales/ja/LC_MESSAGES/default.po:2
  ",
  "
    text: 'bar'
    /root/gettext_check/priv/locales/ja/LC_MESSAGES/default.po:3
  "
]