Coder Social home page Coder Social logo

notyetgames / po-excel-translate Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 3.0 162 KB

Use excel files to update translations from po (portable object) files

License: BSD 3-Clause "New" or "Revised" License

Python 98.22% Shell 1.78%
excel portable-object translation xlsx xls gnutext

po-excel-translate's Introduction

Translating via spreadsheets

Not all translators are comfortable with using PO-editors such as Poedit or translation tools like Transifex. For them this package provides simple tools to convert PO-files to xlsx-files and back again. This also has another benefit: it is possible to include multiple languages in a single spreadsheet, which can be helpful when translating to multiple similar languages at the same time (for example simplified and traditional chinese).

The format for spreadsheets is simple:

  • If any message use a message context the first column will specify the context. If message contexts are not used this column will be skipped.
  • The next (or first) column contains the message id. This is generally the canonical text.
  • A set of columns for any requested comment types (message occurrences, source comments or translator comments).
  • A column with the translated text for each locale. Fuzzy translations are marked in italic.

IMPORTANT: The first row contains the column headers. xls2po uses these to locale information in the file, so make sure never to change these!

Comparison

NOTE: Original code of this was taken from https://github.com/wichert/po-xls

Advantages of this implementation:

  • sane defaults
  • the first row and first columns are freezed so that you can always see the source string you want to translate
  • customizable options like width/wrap/protected ranges/fonts
  • can use the exporter/importer from another python project, you just import the library after installing it:
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")
)

Install

From repository

pip install .

From pypi

pip install po-excel-translate

Portable Object (.po) to spreadshseet (.xlsx)

Converting one or more PO-files to an xls file is done with the po2xls command:

po2xls nl.po

This will create a new file messages.xlsx with the Dutch translations. Multiple PO files can be specified:

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

This will generate a texts.xlsx file with all simplified Chinese, traditional Chinese and Dutch translations.

po2xls will guess the locale for a PO file by looking at the Language key in the file metadata, falling back to the filename if no language information is specified. You can override this by explicitly specifying the locale on the command line. For example:

po2xls nl:locales/nl/LC_MESSAGES/mydomain.po

This will read locales/nl/LC_MESSAGES/mydomain.po and treat it as Dutch (nl locale).

You can also use the -c or --comments option with one of those choices: translator, extracted, reference, all to add more column in the output.

Spreadshseet (.xlsx) to Portable Object (.po)

Translations can be converted back from a spreadsheet into a PO-file using the xls2po command:

xls2po nl texts.xlsx nl.po

This will take the Dutch (nl) translations from texts.xls, and (re)create an nl.po file using those. You can merge those into an existing po-file using a tool like gettext's msgmerge.

po-excel-translate's People

Contributors

annegilles avatar asmund1 avatar dokai avatar felixslager avatar jensmertelmeyer avatar kiorky avatar matthewwilkes avatar teixas avatar trigu avatar trondwh avatar vampy avatar wichert avatar x0ken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

po-excel-translate's Issues

VERSION file not found on Python 3.6 after install

Error on Python 3.6
I used pip install po-excel-translate to install.

xls2po fr-FR ./messages.xlsx ./fr-FR.po

Traceback (most recent call last):
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\XX\AppData\Local\Programs\Python\Python38-32\Scripts\xls2po.exe\__main__.py", line 7, in <module>
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\xls2po.py", line 19, in main
    XLSXToPortableObjectFile(locale=locale, input_file_path=Path(str(input_file)), output_file_path=Path(output_file))
  File "c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\po_excel_translate.py", line 419, in __init__
    with open(os.path.join(root_dir, "VERSION")) as version_file:
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\users\\XX\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\VERSION'

After check file c:\users\XX\appdata\local\programs\python\python38-32\lib\site-packages\VERSION does not exist.
Commented line 419 of "po_excel_translate.py". Works like a charm.

Note : po2xls works without this fix.

Thank you for your work !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.