def get_babel_catalog(self, solid=False): """ Return a babel catalog suitable for a PO file ``solid`` argument is a boolean to define if the catalog also store empty and fuzzy translation items (True) or drop them (False, the default) """ # Forge babel catalog forged_catalog = BabelCatalog( locale=self.locale, header_comment=self.header_comment, project=self.project_version.project.name, domain=self.project_version.project.domain, version=str(self.project_version.version)) queryset = self.translationmsg_set.all() # Exclude empty and fuzzy from queryset if solid: queryset = queryset.exclude(message="").exclude(fuzzy=True) # Add messages to the catalog using template message as "msgid" and # translation message as "msgstr" with supporting plural for both of them for entry in queryset.order_by('id'): msgid = join_message_strings( entry.template.message, plural=entry.template.plural_message, pluralized=entry.template.pluralizable) # Use template "pluralizable" attribute because it's the reference msgstr = join_message_strings( entry.message, plural=entry.plural_message, pluralized=entry.template.pluralizable) # Decompile JSON value from template to get item locations locations = [ tuple(item) for item in json.loads(entry.template.locations) ] # Push the item into catalog forged_catalog.add(msgid, string=msgstr, locations=locations, flags=entry.get_flags()) return forged_catalog
def get_babel_catalog(self, solid=False): """ Return a babel catalog suitable for a PO file ``solid`` argument is a boolean to define if the catalog also store empty and fuzzy translation items (True) or drop them (False, the default) """ # Forge babel catalog forged_catalog = BabelCatalog( locale=self.locale, header_comment=self.header_comment, project=self.project_version.project.name, domain=self.project_version.project.domain, version=str(self.project_version.version) ) queryset = self.translationmsg_set.all() # Exclude empty and fuzzy from queryset if solid: queryset = queryset.exclude(message="").exclude(fuzzy=True) # Add messages to the catalog using template message as "msgid" and # translation message as "msgstr" with supporting plural for both of them for entry in queryset.order_by('id'): msgid = join_message_strings(entry.template.message, plural=entry.template.plural_message, pluralized=entry.template.pluralizable) # Use template "pluralizable" attribute because it's the reference msgstr = join_message_strings(entry.message, plural=entry.plural_message, pluralized=entry.template.pluralizable) # Decompile JSON value from template to get item locations locations = [tuple(item) for item in json.loads(entry.template.locations)] # Push the item into catalog forged_catalog.add( msgid, string=msgstr, locations=locations, flags=entry.get_flags() ) return forged_catalog
def get_babel_template(self): """ Return a babel template catalog suitable for a POT file """ # Forge babel catalog without locale (because it's a POT) forged_catalog = BabelCatalog( header_comment=self.header_comment, project=self.project.name, domain=self.project.domain, version=str(self.version) ) # Add messages to the catalog with an empty string (because it's a POT) for entry in self.templatemsg_set.all().order_by('id'): msgid = join_message_strings(entry.message, plural=entry.plural_message, pluralized=entry.pluralizable) forged_catalog.add(msgid, string=None, locations=entry.get_locations_set(), flags=entry.get_flags_set()) return forged_catalog
def get_babel_template(self): """ Return a babel template catalog suitable for a POT file """ # Forge babel catalog without locale (because it's a POT) forged_catalog = BabelCatalog(header_comment=self.header_comment, project=self.project.name, domain=self.project.domain, version=str(self.version)) # Add messages to the catalog with an empty string (because it's a POT) for entry in self.templatemsg_set.all().order_by('id'): msgid = join_message_strings(entry.message, plural=entry.plural_message, pluralized=entry.pluralizable) forged_catalog.add(msgid, string=None, locations=entry.get_locations_set(), flags=entry.get_flags_set()) return forged_catalog