univention.l10n package

Submodules

univention.l10n.cmd module

Univention Corporate Server localization tool to extract, update, and compile GNU gettext Portable Objects (PO files) to Message Objects (MO files).

univention.l10n.cmd.main()[source]
univention.l10n.cmd.main_build()[source]
univention.l10n.cmd.main_install()[source]
univention.l10n.cmd.parse_args(cmd)[source]
univention.l10n.cmd.build(args)[source]

Generate GNU gettext Portable Objects (PO files) from debian/*.univention-l10n files

This script reads debian/*.univention-l10n files inside the current working directory and creates gettext Portable Objects defined within. It intends to facilitate and homogenize the translation build process.

Add it to the build target inside debian/rules to build the POs for a certain language or use it manually inside source packages to update the translation catalog.

Example debian/rules override:

%:
    dh --with univention-l10n

or alternatively:

override_dh_auto_build:
    univention-l10n-build fr
    dh_auto_build
univention.l10n.cmd.install(args)[source]

Generate and install GNU gettext Message Objects (MO files) from debian/*.univention-l10n files.

This script reads debian/*univention-l10n files inside the current working directory. It builds the message catalogs and installs them to the path defined within.

The intended usage is to add it to the install target inside debian/rules to automate in-package translations.

Example file: debian/rules override:

%:
    dh --with univention-l10n

or alternatively:

override_dh_auto_install:
    univention-l10n-install fr
    dh_auto_install

univention.l10n.helper module

exception univention.l10n.helper.Error[source]

Bases: SystemExit

univention.l10n.helper.make_parent_dir(path)[source]

Create parent directories for file.

Parameters

path – Path for a file.

univention.l10n.helper.call(*argv, **kwargs)[source]

Execute argv and wait.

Parameters
>>> call('true')
0

univention.l10n.l10n module

exception univention.l10n.l10n.NoSpecialCaseDefintionsFound[source]

Bases: univention.l10n.helper.Error

exception univention.l10n.l10n.NoMatchingFiles[source]

Bases: univention.l10n.helper.Error

class univention.l10n.l10n.UMCModuleTranslation(attrs, target_language)[source]

Bases: univention.l10n.umc.UMC_Module

property python_po_files

Iterate over all Python UMC message catalogs.

property js_po_files

Iterate over all JavaScript UMC message catalogs.

property xml_po_files

Iterate over all XML UMC message catalogs.

python_mo_destinations()[source]
json_targets()[source]
xml_mo_destinations()[source]
classmethod from_source_package(module_in_source_tree, target_language)[source]
class univention.l10n.l10n.SpecialCase(special_case_definition, source_dir, path_to_definition, target_language)[source]

Bases: object

Consumes special case definition and determines matching sets of source files.

Parameters
  • special_case_definition – Mapping with special case definitions.

  • source_dir – Base directory.

  • path_to_definition – Path to definition file.

  • target_language – 2-letter language code.

RE_L10N = re.compile('(.+/)?debian/([^/]+).univention-l10n$')
get_source_file_sets()[source]
create_po_template(output_path='.')[source]
class univention.l10n.l10n.MIMEChecker[source]

Bases: object

suffixes = {'.html': 'text/html', '.js': 'application/javascript', '.py': 'text/x-python', '.sh': 'text/x-shellscript', '.ts': 'application/javascript', '.vue': 'application/javascript'}
get(file_path)[source]
univention.l10n.l10n.update_package_translation_files(module, output_dir, template=False)[source]
univention.l10n.l10n.write_makefile(all_modules, special_cases, new_package_dir, target_language)[source]
univention.l10n.l10n.translate_special_case(special_case, source_dir, output_dir)[source]
univention.l10n.l10n.read_special_case_definition(definition_path, source_tree_path, target_language)[source]
univention.l10n.l10n.get_special_cases_from_srcpkg(source_tree_path, target_language)[source]
univention.l10n.l10n.get_special_cases_from_checkout(source_tree_path, target_language)[source]

Process *.univention-l10n files in the whole branch. Currently they lay 3 (UCS@school) or 4(UCS) directory levels deep in the repository.

univention.l10n.l10n.find_base_translation_modules(source_dir)[source]
univention.l10n.l10n.template_file(dst, fn, values)[source]

Render file from template file by filling in values.

Parameters
  • dst – Destination path.

  • fn – File name for destination file and source template with .tmpl suffix.

  • values – A dictionary with the values.

univention.l10n.l10n.create_new_package(new_package_dir, target_language, target_locale, language_name, startdir)[source]

univention.l10n.message_catalogs module

This module collects utilities for installing and building message catalogs while applying Univention specific options.

univention.l10n.message_catalogs.concatenate_po(src_po_path, dest_po_path)[source]

Append first to second .po file.

Parameters
  • src_po_path – File to merge.

  • dest_po_path – File to merge into.

univention.l10n.message_catalogs.create_empty_po(binary_pkg_name, new_po_path)[source]

Create a new empty .po file.

Parameters
  • binary_pkg_name – Package name.

  • new_po_path – File name for new file.

univention.l10n.message_catalogs.merge_po(template, translation)[source]

Merge old translation with new template file.

Parameters
  • template – New template .pot file.

  • translation – Old translation .po file.

univention.l10n.message_catalogs.join_existing(language, output_file, input_files, cwd='/builds/univention/dist/ucsapidoc')[source]

Extract strings from source code and merge into existing translation file.

Parameters
  • language – Source code language, e.g. JavaScript, Python, Shell.

  • output_file – Template file name.

  • input_files – Sequence of input files.

  • cwd – Base directory used as new woring directory.

univention.l10n.message_catalogs.univention_location_lines(pot_path, abs_path_source_pkg)[source]

Convert absolute paths to relative paths.

Parameters
  • pot_path – Path to .pot file.

  • abs_path_source_pkg – Source package base path.

univention.l10n.sourcefileprocessing module

Generate gettext Portable Objects and message catalogs (gettext MO and a Univention specific JSON-based format) from multiple source files by file type.

exception univention.l10n.sourcefileprocessing.UnsupportedSourceType[source]

Bases: Exception

class univention.l10n.sourcefileprocessing.SourceFileSet(src_pkg_path, binary_pkg_name, files)[source]

Bases: object

process_po(pot_path)[source]
process_target(po_path, output_path)[source]
class univention.l10n.sourcefileprocessing.SourceFilesXgettext(src_pkg_path, binary_pkg_name, files)[source]

Bases: univention.l10n.sourcefileprocessing.SourceFileSet

class univention.l10n.sourcefileprocessing.SourceFilesShell(src_pkg_path, binary_pkg_name, files)[source]

Bases: univention.l10n.sourcefileprocessing.SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesPython(src_pkg_path, binary_pkg_name, files)[source]

Bases: univention.l10n.sourcefileprocessing.SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesJavaScript(src_pkg_path, binary_pkg_name, files)[source]

Bases: univention.l10n.sourcefileprocessing.SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesHTML(src_pkg_path, binary_pkg_name, files)[source]

Bases: univention.l10n.sourcefileprocessing.SourceFileSet

class univention.l10n.sourcefileprocessing.SourceFileSetCreator[source]

Bases: object

process_by_type = {'application/javascript': <class 'univention.l10n.sourcefileprocessing.SourceFilesJavaScript'>, 'text/html': <class 'univention.l10n.sourcefileprocessing.SourceFilesHTML'>, 'text/x-python': <class 'univention.l10n.sourcefileprocessing.SourceFilesPython'>, 'text/x-shellscript': <class 'univention.l10n.sourcefileprocessing.SourceFilesShell'>}
classmethod from_mimetype(src_pkg_path, binary_pkg_name, mimetype, files)[source]
univention.l10n.sourcefileprocessing.from_mimetype(src_pkg_path, binary_pkg_name, mimetype, files)[source]

univention.l10n.umc module

Each module definition contains the following entries:

  • Module: The internal name of the module

  • Python: A directory containing the Python module. There must be a subdirectory named like the internal name of the module.

  • Definition: The XML definition of the module

  • Javascript: The directory of the javascript code. In this directory must be a a file called <Module>.js

  • Category: The XML definition of additional categories

  • Icons: A directory containing the icons used by the module. The directory structure must follow the following pattern <weight>x<height>/<icon>.(png|svg).

The entries Module and Definition are required.

Example:

Module: ucr
Python: umc/module
Definition: umc/ucr.xml
Javascript: umc/js
Category: umc/categories/ucr.xml
Icons: umc/icons
class univention.l10n.umc.UMC_Module(*args)[source]

Bases: dict

property package

Return the name of the Debian binary package.

property python_path

Return path to Python UMC directory.

property python_versions
property js_path

Return path to JavaScript UMC directory.

property js_module_file

Return path to main JavaScript file.

property js_files

Iterate over all JavaScript UMC files.

property html_files

Iterate over all JavaScript HTML files.

property css_files

Iterate over all Javascript CSS files.

property module_name

Return the name of the UMC module.

property xml_definition

Return the path to the XML UMC definition.

property xml_categories

Return the path to the XML file defining categories.

property python_files

Iterate over all Python UMC files.

property python_po_files

Iterate over all Python UMC message catalogs.

property js_po_files

Iterate over all JavaScript UMC message catalogs.

property xml_po_files

Iterate over all XML UMC message catalogs.

property icons

Return path to UMC icon directory.

univention.l10n.umc.read_modules(package, core=False)[source]

Read UMC module definition from debian/<package>.umc-modules.

Parameters
  • package – Name of the package.

  • core – Import as core-module, e.g. the ones shipped with UDM itself.

Returns

List of UMC module definitions.

univention.l10n.umc.module_xml2po(module, po_file, language, template=False)[source]

Create a PO file the XML definition of an UMC module.

Parameters
  • moduleUMC module.

  • po_file – File name of the textual message catalog.

  • language – 2-letter language code.

  • template – Keep PO template file.

univention.l10n.umc.create_po_file(po_file, package, files, language='python', template=False)[source]

Create a PO file for a defined set of files.

Parameters
  • po_file – File name of the textual message catalog.

  • package – Name of the package.

  • files – A single file name or a list of file names.

  • language – Programming language name.

  • template – Keep PO template file.

univention.l10n.umc.merge_po_file(po_file, pot_file)[source]

Merge .po file with new .pot file.

Parameters
  • po_file – PO file containing translation.

  • pot_file – PO template file.

univention.l10n.umc.create_mo_file(po_file, mo_file='')[source]

Compile textual message catalog (.po) to binary message catalog (.mo).

Parameters
  • po_file – File name of the textual message catalog.

  • mo_file – File name of compiled message catalog.

univention.l10n.umc.create_json_file(po_file)[source]

Compile textual message catalog (.po) to JSON message catalog.

Parameters

po_file – File name of the textual message catalog.

univention.l10n.umc.po_to_json(po_path, json_output_path)[source]

Convert translation file to JSON file.

Parameters
  • po_path – Translation file name.

  • json_output_path – Output file name.