Converting PO Files to Spreadsheets

Blake Bradford Avatar

·

Simplifying Translation Workflow: Converting PO Files to Spreadsheets

If you are a translator who prefers working with spreadsheets rather than PO-editors or translation tools, the po-excel-translate package provides a simple solution for converting PO-files to xlsx-files and vice versa. By leveraging this package, you can enjoy the benefits of including multiple languages in a single spreadsheet, making it easier to translate to similar languages concurrently.

The Format for Spreadsheets

The format for spreadsheets generated by the po-excel-translate package is straightforward. The columns in the spreadsheet are organized as follows:

  1. If a message uses a message context, the first column indicates the context. If message contexts are not used, this column is skipped.
  2. The next (or first) column contains the message id, which generally represents the canonical text.
  3. Additional columns can be used for various types of comments, such as message occurrences, source comments, or translator comments.
  4. Each locale has a column for the translated text. Fuzzy translations are marked in italic.

It is crucial to note that the first row in the spreadsheet contains the column headers, which are used by the xls2po tool to identify locale information. Therefore, preserving these headers is essential to ensure accurate conversion.

Advantages of the po-excel-translate Implementation

The implementation of the po-excel-translate package offers several advantages that enhance the translation workflow:

  1. Sane defaults: The package comes with sensible default settings, eliminating the need for extensive configuration.
  2. Freeze panes: The first row and first columns in the spreadsheet are frozen, allowing translators to always see the source string being translated.
  3. Customizable options: The package provides options for adjusting width, wrap, protected ranges, and fonts, enabling translators to personalize their workspace.
  4. Reusability: The package’s exporter and importer can be used in other Python projects by simply importing the library after installation.

To illustrate, here’s an example of how to use the po-excel-translate library for converting PO files to XLSX format:

“`python
from pathlib import Path
import po_excel_translate as poet

po2xls

po_files_to_convert = [
poet.PortableObjectFile(“ro-example.po”)
]

poet.PortableObjectFileToXLSX(
po_files=po_files_to_convert,
comment_types=[poet.CommentType.SOURCE],
output_file_path=Path(“ro-example.xlsx”)
)

xls2po

poet.XLSXToPortableObjectFile(
locale=”ro”,
input_file_path=Path(“ro-example.xlsx”),
output_file_path=Path(“ro-example.po”)
)
“`

Installation

You can install the po-excel-translate package either from the repository or via PyPI.

From Repository

shell
pip install .

From PyPI

shell
pip install po-excel-translate

Converting PO Files to Spreadsheet (.xlsx) Format

To convert one or more PO files to an XLS file, you can use the po2xls command. Here are some examples:

shell
po2xls nl.po

This will create a new file named messages.xlsx with the Dutch translations. You can specify multiple PO files to generate a single spreadsheet:

shell
po2xls -o texts.xlsx zh_CN.po zh_TW.po nl.po

The above command will generate a texts.xlsx file containing the translations for simplified Chinese, traditional Chinese, and Dutch.

The po2xls command automatically determines the locale for a PO file by examining the Language key in the file metadata. If no language information is specified, it falls back to the filename. However, you can override this behavior by explicitly specifying the locale on the command line.

Additionally, you have the option to include additional columns for comments by using the -c or --comments option followed by one of the following choices: translator, extracted, reference, or all.

Converting Spreadsheet (.xlsx) to PO Files

Reversing the process and converting translations from a spreadsheet back to a PO-file is also possible. Use the xls2po command as follows:

shell
xls2po nl texts.xlsx nl.po

The above command will extract the Dutch translations from texts.xlsx and recreate the nl.po file using those translations. You can merge these translations into an existing PO-file by utilizing tools like gettext’s msgmerge.

By utilizing the po-excel-translate package, you’ll have a streamlined workflow for managing translations, making it easier and more efficient to localize your software.

Please feel free to ask any questions you may have!


References:
po-excel-translate GitHub Repository
po-excel-translate PyPI Package

Leave a Reply

Your email address will not be published. Required fields are marked *