Introducing babel-plugin-django-gettext.

Review Request #10993 — Created April 8, 2020 and submitted

chipx86
babel-plugin-django-gettext
master
4d3926e...
beanbag-misc

This is a plugin for Babel designed to make it easier to perform
localization in a Django-backed JavaScript codebase.

When working with localization, Django provides a handful of
gettext-compatible functions and a version of the current message
dictionary for the locale, which JavaScript can use to perform
on-the-fly translation of strings. While fantastic to have, it suffers
from a lot of noise, caused by long strings that can't easily be
word-wrapped and wordy interpolate() calls for format strings.

This plugin fixes all this by introducing the following:

  • Automatic whitespace condensing/trimming (by default -- callers can
    also opt to preserve all whitespace by calling _raw() versions of
    the functions).

  • Automatic interpolation for template literals that reference variables
    or expressions, avoiding all the interpolate() calls.

  • Support for either calling gettext functions or using them as a
    tagged template literal.

  • A _ alias that maps to gettext when used as a tagged template
    literal (but not a function call, to avoid breaking usage of
    underscore.js).

  • A N_ aliases that maps to ngettext.

These calls/template literals will be transpiled cleanly to code
compatible with the xgettext message scanner, resulting in cleaner
codebases, more readable strings, and fewer errors.

Unit tests passed.

Tested this with Djblets and Review Board, and verified the resulting
output.

Description From Last Updated

Col: 27 Missing semicolon.

reviewbotreviewbot

Col: 21 Missing semicolon.

reviewbotreviewbot

Col: 14 'transformTextNode' was used before it was defined.

reviewbotreviewbot

Col: 14 'transformGettextCall' was used before it was defined.

reviewbotreviewbot

Col: 14 'transformPGettextCall' was used before it was defined.

reviewbotreviewbot

Col: 14 'transformNGettextCall' was used before it was defined.

reviewbotreviewbot

Col: 14 'transformNPGettextCall' was used before it was defined.

reviewbotreviewbot

Col: 14 'transformGettextTemplate' was used before it was defined.

reviewbotreviewbot

Col: 2 Unnecessary semicolon.

reviewbotreviewbot

Col: 11 'allGettextOptions' was used before it was defined.

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 passed.
JSHint failed.

JSHint

chipx86
Review request changed

Change Summary:

  • Fixed Review Bot warnings.
  • Fixed some bad documentation.
  • Added eslint as a development dependency.

Commit:

-549c310da09a01a64c55c835ed6a77f55df6d0cf
+4d3926e16c4a81476347da76396af853009c89ad

Diff:

Revision 2 (+1801)

Show changes

Checks run (1 failed, 1 succeeded)

flake8 passed.
JSHint failed.

JSHint

chipx86
david
  1. So cool.

  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...