Export translations that were changed in Launchpad
As a translation maintainer for a project
I want to be able to download only those translation strings from a pofile
that were previously imported from the upstream project and then changed in Launchpad,
to commit those changed translations back to the upstream project.
Implementation of the blueprint export-changed-in-launchpad.
Requirements
- This type of export is only available for POFiles, not for templates or even a whole product series.
- The exported file should clearly state that it does not contain a full set of translation strings for this template.
- The exported file should not be importable back into Launchpad. This is achieved by removing the header completely.
User Interface
When the user selects "Download" within the POFile UI, he is presented with the choice of "MO" or "PO" formats. Only if he chooses "PO" will he have the choice of either "Full file" or "Changed in Launchpad". No other UI changes are needed
Analysis of existing code
There is already code to
- Export files in PO format
- Select only those files that where changed in Launchpad (for display)
Export of a PO file
Call Hierarchy
The cron script is doing this:
scripts.po_export_py.process_request:161 -> ITranslationExporter.getExporterProducingTargetFileFormat
pofile.zcml.subscriber:30 -> GettextPOExporter
scripts.po_export_py.process_request:183 -> generate_translatoinfiledata
scripts.po_export_py.generate_translatoinfiledata:149 -> ITranslationFileData(IPOFile)
pofile.zcml.adapter:23 -> POFileToTranslationFileDataAdapter
database.pofile.py.POFileToTranslationFileDataAdapter.init:1277 -> _getMessages
database.pofile.py.POFileToTranslationFileDataAdapter._getMessages:1359 -> get_pofile_rows
database.vpoexport.py.VPOExportSet.get_pofile_rows:117 -> _select
database.vpoexport.py.VPOExportSet.get_pofile_rows:94 -> cur.execute database.vpoexport.py.VPOExportSet.get_pofile_rows:97 -> yield VPOExport
scripts.po_export_py.process_request:182 -> exportTranslationFiles
- translationformat.gettext_po_exporter.exportTranslationFiles
Issues
- The export uses the POExport view and selects the relevant messages from in get_pofile_rows. This select could be adapted to retrieve only the changed rows.
- The ITranslationFormatExporter is selected using the file format but this has no influence on generate_translationfiledata. This information would have to be passed down to get_pofile_rows.
- A seperate ITranslationFormatExporter is needed for this because the file will ommit the header, and add a warning, too. This should share code with the existing POFormatExporter.
Selection of changed translations
POFile has a method getPOTMsgSetChangedInLaunchpad that returns a POTMsgSet with the relevant messages. This is used when all translations for a project are reverted back to the packaged translations. This is too broad and too different to be used for our pupose.
Instead, the above database view will be queried with the extra filters.
Steps in the implementation
Stage 1
This stage is reached when we are able to create exported files from the export queue that contain only the translation strings that were changed in Launchpad. The files still have the header, though, and the entry has to be hacked into the queue.
- Turn POFileToTranslationFileDataAdapter into a named adapter and create a second adapter for Changed-In-Launchpad. Use getAdapter to call the adpapter.
- Add a new translation file format PO_LPCHANGED and select the right adapter accourding to the file type.
- Add a filter parameter to VPOExportSet.get_pofile_rows and apply this filter in the query.
Stage 2
This stage is reached when the exported files fulfill the requirments mentioned above. No UI change yet.
- Create a new ITranslationFormatExporter implementation based on or related to GettextPOExporter which is registered for the new file format.
- more to follow ...
Stage 3
This stage is reached when the UI for selecting this type of export is available in a static form. All controls are always visible.
Stage 4
This stage is reached when the UI adapts dynamically to just show the filter choice when the applicable format is selected.
Planing code changes
List of files to touch (incomplete).
- templates/pofile-export.pt
- Add controls
- database/vpoexport.py
- extend where clause in get_pofile_rows
- add filter parameter to get_pofile_rows
- database/pofile.py
- use getPOTMsgSetChangedInLaunchpad
- remove XXX
- POFileToTranslationFileDataAdapter._getMessages
- interfaces/translationexporter.py
- remove XXX in ITranslationFormatExporter
- add filter parameter to ITranslationFormatExporter.exportTranslationFiles?
- interfaces/translationfileformat.py
- add Enum PO_LPCHANGED
- translationformat/gettext_po_exporter.py
- move tests from docstring to doctest?
- create a new exporter based on GettextPOExporter or create new base for both
- zcml/translationexport.zcml
- Register new exporter as subscriber