def translator_singleton(self, fixture): """Only one SystemwideTranslator is ever present per process.""" SystemWideTranslator.instance = None # To "reset" the singleton, else its __init__ will NEVER be called in this test with InitMonitor(SystemWideTranslator) as monitor: _ = Translator('reahl-component') _2 = Translator('reahl-component') _('test string') _.ngettext('thing', 'things', 1) _.ngettext('thing', 'things', 2) _2('test string') vassert(monitor.times_called == 1)
def basic_usage(self, fixture): """A Translator for a particular component can translate messages for that component into the interface_locale on its current ExecutionContext.""" _ = Translator( 'reahl-component' ) # Will find its translations in the compiled messages of reahl-component with LocaleContextStub() as context: context.test_locale = 'en_gb' vassert(_('test string') == 'test string') vassert(_.gettext('test string') == 'test string') vassert(_.ngettext('thing', 'things', 1) == 'thing') vassert(_.ngettext('thing', 'things', 3) == 'things') context.test_locale = 'af' vassert(_('test string') == 'toets string') vassert(_.gettext('test string') == 'toets string') vassert(_.ngettext('thing', 'things', 1) == 'ding') vassert(_.ngettext('thing', 'things', 3) == 'goeters')