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
-
Preserves Gettext interpolation variables (e.g.,
%{name}) - Converts ASCII characters to accented Unicode equivalents
- Wraps strings in brackets (⟦...⟧) for easy identification
- Maintains all PO file headers and metadata
- Preserves existing translations
Installation
Add gettext_pseudolocalize to your list of dependencies in mix.exs:
def deps do
[
{:gettext_pseudolocalize, "~> 0.1.0"}
]
endUsage
- First, extract your gettext strings:
mix gettext.extract- Merge them into the xx locale - this is done automatically by the gettext_pseudolocalize task:
mix gettext.merge priv/gettext --locale=xx- 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.PluralGettextPseudolocalize.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:
- Hardcoded strings that should be localized
- Character encoding issues
- UI issues with different character lengths
- String concatenation issues
- Unicode/font support problems
Contributing
- Fork it
-
Create your feature branch (
git checkout -b feature/my-new-feature) -
Commit your changes (
git commit -am 'Add some feature') -
Push to the branch (
git push origin feature/my-new-feature) - Create new Pull Request
License
This project is licensed under the Apache-2.0 License.