Exporting PO Files From Rosetta =============================== Last Review: 26 Aug 2004 13:50 CEST This document describes the process we should follow to export a .po file from Rosetta. The process here is not optimized. Perhaps there is a faster way to do it with less queries and less steps, but that's outside the scope of this document. We need a temporary store for a list of POMsgSet.id that are already exported. Comments -------- - What happens if we have a msgset in a POFile that is not available in the POFile anymore and we see it again? Should we reuse it? For example, it happens if we import a pofile with an obsolete msgset and when we import it again, someone has deleted it. Also it could be interesting add as fuzzy other translations from other modules (perhaps for Phase 2). The Procedure ------------- To be able to export a POFile we need to know the POFile object we want to get. 1. We get the POTemplate associated to this POFile "po" (POFile.potemplate). This is the easy bit. 2. We get all POMsgSets for this POTemplate "pot" that have POMsgIDSighting that were in the pot file last time we imported it:: SELECT POMsgSet.* FROM POMsgSet WHERE POMsgSet.potemplate = pot.id AND POMsgSet.pofile IS NULL AND POMsgSet.sequence > 0 EXISTS (SELECT * FROM POMsgIDSighting WHERE POMsgSet.id = POMsgIDSighting.pomsgset AND POMsgIDSighting.inlastrevision = TRUE) ORDER BY POMsgSet.sequence 3. For every POMsgSet "potSet" we got in #2 we look for its equivalent POMsgSet "poSet" inside the POFile:: SELECT POMsgSet.* FROM POMsgSet WHERE POMsgSet.potemplate = pot.id AND POMsgSet.pofile = po.id AND POMsgSet.primemsgid = potSet.primemsgid If we don't find a POMsgSet, we dump potSet and continue to the next messasge set. If we get a POMsgSet, we add its id (POMsgSet.id) into a temporary list, and look for an active translation sighting ("translationSighting") for the message set:: SELECT * FROM POTranslationSighting WHERE POTranslationSighting.pomsgset = poSet.id AND POTranslationSighting.active = TRUE) If we don't get any POTranslationSighting, we dump potSet along with poSet.commenttext and go on to the next message. XXX: Should we look on older translations? (Read comment #1) If we have an active translation we need to check if it's a plural form and if it's the same as the POTemplate one:: SELECT POMsgIDSighting.id FROM POMsgIDSighting WHERE POMsgIDSighting.pomsgset = potSet.id AND POMSgIDSighting.pluralform > 0 AND POMsgIDSighting.inlastrevision = TRUE If this query returns a result (and it should only ever return one), we call it "templatePluralSighting". If this query returns no results, it's not a plural form in the template. We now check whether it's a plural form in the PO file:: SELECT POMsgIDSighting.id FROM POMsgIDSighting WHERE POMsgIDSighting.pomsgset = poSet.id AND POMSgIDSighting.pluralform > 0 AND POMsgIDSighting.inlastrevision = TRUE If this query also returns no results, (it's non-plural in the PO file too) we dump potSet, with poSet.commenttext, poSet.fuzzy, translationSighting.potranslation.translation, and go on to the next message set. If this query does return results (it's non-plural in the template but plural in the PO file), we dump potSet with poSet.commenttext, translationSighting.potranslation.translation and a fuzzy flag, then go on to the next message set. Now, the case when the message set is plural in the template. We look to see if the same plural form exists in the PO file:: SELECT POMsgIDSighting.id FROM POMsgIDSighting WHERE POMsgIDSighting.pomsgid = templatePluralSighting.pomsgid AND POMsgIDSighting.inlastrevision = TRUE If the plural forms are equal, we dump potSet with poSet.commenttext, poSet.fuzzy (although if poSet.iscomplete is false, the fuzzy flag is set), translationSighting.potranslation.translation and go on to the next message set. If the plural forms are not equal, we dump potSet with poSet.commenttext, translationSighting.potranslation.translation and set the fuzzy flag. And then go to the next message set. 4. At this point we have dumped all current messag sets from the template, now it's time to export the remaining message sets from the PO file. We get the list of POMsgSets that are active:: SELECT POMsgSet.* FROM POMsgSet WHERE POMsgSet.potemplate = pot.id AND POMsgSet.pofile = po.id AND POMsgSet.sequence > 0 EXISTS (SELECT * FROM POMsgIDSighting WHERE POMsgSet.id = POMsgIDSighting.pomsgset AND POMsgIDSighting.inlastrevision = TRUE) ORDER BY POMsgSet.sequence And, for every POMsgSet we get, we check whether it's in our list of message sets that we've looked at already. If it is, we ignore it. If it isn't, we dump the message set with all its translations but without the file references and source comment, and set the obsolete flag.