Skip to main content

Provides Babel extractors and translation methods for standards like OCDS or BODS

Project description

PyPI Version Build Status Coverage Status Python Version

This Python package provides Babel extractors and translation methods for standards like the Open Contracting Data Standard (OCDS) or Beneficial Ownership Data Standard (BODS).

Examples

Babel extractors

Babel extractors can be specified in configuration files.

For OCDS, you can specify:

[ocds_codelist: schema/*/codelists/*.csv]
headers = Title,Description,Extension
ignore = currency.csv

in babel_ocds_codelist.cfg, and:

[ocds_schema: schema/*/*-schema.json]

in babel_ocds_schema.cfg.

For BODS, you can specify:

[ocds_codelist: schema/codelists/*.csv]
headers = title,description,technical note

in babel_bods_codelist.cfg, and:

[ocds_schema: schema/*.json]

in babel_bods_schema.cfg.

Translation methods

In the Sphinx build configuration file (conf.py), you can use translate to translate codelist CSV files and JSON Schema files:

import os
from glob import glob
from pathlib import Path

from ocds_babel.translate import translate


def setup(app):
    basedir = Path(os.path.realpath(__file__)).parents[1]
    localedir = basedir / 'locale'
    language = app.config.overrides.get('language', 'en')
    headers = ['Title', 'Description', 'Extension']

    translate([
        (glob(str(basedir / 'schema' / '*-schema.json')), basedir / 'build' / language, 'schema'),
        (glob(str(basedir / 'schema' / 'codelists')), basedir / 'build' / language, 'codelists'),
    ], localedir, language, headers)

translate automatically determines the translation method to used based on filenames. The arguments to translate are:

  1. A list of tuples. Each tuple has three values:
    1. Input files (a list of paths of files to translate)
    2. Output directory (the path of the directory in which to write translated files)
    3. Gettext domain (the filename without extension of the message catalog to use)
  2. Locale directory (the path of the directory containing message catalog files)
  3. Target language (the code of the language to translate to)
  4. Optional keyword arguments to replace {{marker}} markers with values, e.g. version='1.1'

Methods are also available for translating extension.json and for translating Markdown-to-Markdown. If the latter, you must install Sphinx 1.5.1, with either:

pip install ocds-babel[markdown]

or:

pip install 'Sphinx==1.5.1'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ocds-babel, version 0.1.0
Назва файлу, розмір File type Версія Python Дата завантаження Hashes
Назва файлу, розмір ocds-babel-0.1.0.tar.gz (11.7 kB) File type Source Версія Python Нема Дата завантаження Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page