#7586 Add format() method to translation objects
Closed: fixed Opened by cheimes.

The format() method is the new, preferred syntax for string formatting in Python 3. The old style % operation has been deprecated. As of now, FreeIPA's gettext helpers only support % and not format.

The improvement is required to fix some bad translation, see https://github.com/freeipa/freeipa/pull/1997

Add format()

Add format method to ipalib.text (untested example):

class Gettext:
     ...
    def format(self, *args, **kwargs):
        return unicode(self).format(*args, **kwargs)
class NGettext:
     ...
    def format(self, **kwargs):
        count = kwargs['count']
        return self(count).format(**kwargs)
class ConcatenatedLazyText:
     ...
    def format(self, *args, **kwargs):
        return unicode(self).format(*args, **kwargs)

Add tests

Add tests for format to ipatests.test_ipalib.test_text. You can just copy and modify the test_mod tests for all three classes.


master:

  • f4716b69910f082a2fe039338f4268d941792258 Add support for format method to translation objects
  • 854597c411764b603ebbe15d97dbcadac321548d Use intended format() method of translation object
  • 65414d1471fde54f41129d9641c0fec7160f0896 Fix formatted translations in domainlevel plugin
  • 229f1608db868ced234e84e0bc7e949decd3e75e Fix translation of idrange_* commands description
  • 6f245db8eacb9bdc1e248b4f6f25e5eb785478c4 Fix formatted translations in trust plugin
  • 1dfdbfd8bf9657e4066a3ba5f847dbcb35228f0c Fix formatted translations of error messages in serverroles plugin
  • 4b3bc490d3be109ea048f165a1929438760d8a54 Fix formatted translations of error messages in topology plugin

Metadata Update from @cheimes:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

Metadata