diff --git a/translate/convert/prop2po.py b/translate/convert/prop2po.py index 1a8ba283a6..74042975ba 100644 --- a/translate/convert/prop2po.py +++ b/translate/convert/prop2po.py @@ -33,15 +33,6 @@ logger = logging.getLogger(__name__) -def _collapse(store, units): - sources = [u.source for u in units] - targets = [u.target for u in units] - # TODO: only consider the right ones for sources and targets - plural_unit = store.addsourceunit(sources) - plural_unit.target = targets - return plural_unit - - class prop2po: """convert a .properties file to a .po file for handling the translation.""" @@ -165,6 +156,17 @@ def mergestore(self, origpropfile, translatedpropfile): def fold_gaia_plurals(self, postore): """Fold the multiple plural units of a gaia file into a gettext plural.""" + + def _append_plural_unit(store, plurals, plural): + units = plurals[plural] + sources = [u.source for u in units] + targets = [u.target for u in units] + # TODO: only consider the right ones for sources and targets + plural_unit = store.addsourceunit(sources) + plural_unit.target = targets + plural_unit.addlocation(plural) + del plurals[plural] + new_store = type(postore)() plurals = {} current_plural = u"" @@ -175,9 +177,7 @@ def fold_gaia_plurals(self, postore): if u"plural(n)" in unit.source: if current_plural: # End of a set of plural units - new_unit = _collapse(new_store, plurals[current_plural]) - new_unit.addlocation(current_plural) - del plurals[current_plural] + _append_plural_unit(new_store, plurals, current_plural) current_plural = u"" # start of a set of plural units location = unit.getlocations()[0] @@ -194,18 +194,14 @@ def fold_gaia_plurals(self, postore): continue elif current_plural: # End of a set of plural units - new_unit = _collapse(new_store, plurals[current_plural]) - new_unit.addlocation(current_plural) - del plurals[current_plural] + _append_plural_unit(new_store, plurals, current_plural) current_plural = u"" new_store.addunit(unit) if current_plural: # The file ended with a set of plural units - new_unit = _collapse(new_store, plurals[current_plural]) - new_unit.addlocation(current_plural) - del plurals[current_plural] + _append_plural_unit(new_store, plurals, current_plural) current_plural = u"" # if everything went well, there should be nothing left in plurals