def export_translation_message(trans, only_used=False): #FIXME: this is only needed as long as we keep both `plurals` and `translated_text`+`plural_texts` if not trans.plurals: return _icu_encode(trans.translated_text) lookup_fun = get_rules_for_language(trans.language_code) if not trans.master.plural_text: singular_form = lookup_fun(1) return _icu_encode(trans.plurals[singular_form]) if only_used: plurals = dict((form, t) for (form, t) in trans.plurals.iteritems() if form in lookup_fun.plurals_used) else: plurals = dict(trans.plurals) if len(plurals) == 1: # if there's only one plural form it has to be the singular translation return _icu_encode(plurals.values()[0]) return _export_plurals(plurals)
def test_returns_plural_function_for_language_code(self): result = rules.get_rules_for_language('en') self.assertIn('en', rules.LANGUAGE_LOOKUPS) self.assertEqual(result, rules.l_one_or_many_or_fraction)
def test_handles_upper_case_language_code(self): result = rules.get_rules_for_language('EN') self.assertNotIn('EN', rules.LANGUAGE_LOOKUPS) self.assertEqual(result, rules.l_one_or_many_or_fraction)
def test_handles_language_code_with_region(self): result = rules.get_rules_for_language('en-us') self.assertNotIn('en-us', rules.LANGUAGE_LOOKUPS) self.assertEqual(result, rules.l_one_or_many_or_fraction)
def test_returns_default_for_unknown_language_code(self): result = rules.get_rules_for_language('foo') self.assertNotIn('foo', rules.LANGUAGE_LOOKUPS) self.assertEqual(result, rules._default)