#7586 Add format() method to translation objects
Closed: fixed 5 years ago Opened 5 years ago 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:

  • f4716b6 Add support for format method to translation objects
  • 854597c Use intended format() method of translation object
  • 65414d1 Fix formatted translations in domainlevel plugin
  • 229f160 Fix translation of idrange_* commands description
  • 6f245db Fix formatted translations in trust plugin
  • 1dfdbfd Fix formatted translations of error messages in serverroles plugin
  • 4b3bc49 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)

5 years ago

Login to comment on this ticket.

Metadata