Gettext Pseudolocalize

A Mix task for pseudolocalizing Gettext translations in Elixir applications. Pseudolocalization is a software testing method used to verify internationalization aspects of software by replacing ordinary characters with accented or modified versions while maintaining readability.

Features

Installation

Add gettext_pseudolocalize to your list of dependencies in mix.exs:

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

Usage

  1. First, extract your gettext strings:
mix gettext.extract
  1. Merge them into the xx locale - this is done automatically by the gettext_pseudolocalize task:
mix gettext.merge priv/gettext --locale=xx
  1. Run the pseudolocalization:
mix gettext.pseudolocalize

This will process all .po files in your xx locale directory (priv/gettext/xx/LC_MESSAGES/).

Configuring the pluralizer for xx

Starting with gettext ~> 1.0, the default Gettext.Plural raises Gettext.Plural.UnknownLocaleError for unknown locales such as xx. The mix gettext.pseudolocalize task handles this transparently for itself by temporarily swapping in GettextPseudolocalize.Plural while running gettext.merge.

However, once your Gettext backend compiles against priv/gettext/xx/, it will also call your configured pluralizer for xx. If you use the backend in your app you should make the pluralizer permanent in config/config.exs:

config :gettext, :plural_forms, GettextPseudolocalize.Plural

GettextPseudolocalize.Plural declares nplurals/1 = 2 for "xx" and delegates every other locale to Gettext.Plural, so it is safe as a global default. If you already have a custom pluralizer, add the "xx" clauses to it instead and keep delegating the rest to Gettext.Plural.

Example

Original string in .pot file:

msgid "Hello %{name}"
msgstr ""

After pseudolocalization in xx locale:

msgid "Hello %{name}"
msgstr "⟦Ȟêĺĺø %{name}~~~~~~⟧"

Benefits

Pseudolocalization helps identify:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create new Pull Request

License

This project is licensed under the Apache-2.0 License.