univention.l10n package

Contents

univention.l10n package#

exception univention.l10n.Error[source]#

Bases: SystemExit

class univention.l10n.MIMEChecker[source]#

Bases: object

get(file_path)[source]#
suffixes = {'.html': 'text/html', '.js': 'application/javascript', '.py': 'text/x-python', '.sh': 'text/x-shellscript', '.ts': 'application/javascript', '.vue': 'application/javascript'}#
exception univention.l10n.NoMatchingFiles[source]#

Bases: Error

exception univention.l10n.NoSpecialCaseDefintionsFound[source]#

Bases: Error

class univention.l10n.SpecialCase(special_case_definition: dict[str, str], source_dir: str, path_to_definition: str, target_language: str)[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$')#
create_po_template(output_path: str = '.') str[source]#
get_source_file_sets() list[SourceFileSet][source]#
class univention.l10n.UMCModuleTranslation(attrs: dict[str, Any], target_language: str)[source]#

Bases: UMC_Module

classmethod from_source_package(module_in_source_tree: BaseModule, target_language: str) UMCModuleTranslation[source]#
property js_po_files: Iterator[str]#

Iterate over all JavaScript UMC message catalogs.

json_targets() Iterator[tuple[str, str]][source]#
python_mo_destinations() Iterator[tuple[str, str]][source]#
property python_po_files: Iterator[str]#

Iterate over all Python UMC message catalogs.

xml_mo_destinations() Iterator[tuple[str, str]][source]#
property xml_po_files: Iterator[tuple[str, str]]#

Iterate over all XML UMC message catalogs.

univention.l10n.create_new_package(new_package_dir: str, target_language: str, target_locale: str, language_name: str, startdir: str) None[source]#
univention.l10n.find_base_translation_modules(source_dir: str) list[BaseModule][source]#
univention.l10n.get_special_cases_from_checkout(source_tree_path: str, target_language: str) list[SpecialCase][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.get_special_cases_from_srcpkg(source_tree_path: str, target_language: str) list[SpecialCase][source]#
univention.l10n.read_special_case_definition(definition_path: str, source_tree_path: str, target_language: str) Iterator[SpecialCase][source]#
univention.l10n.template_file(dst: str, fn: str, values: dict[str, str]) None[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.translate_special_case(special_case: SpecialCase, source_dir: str, output_dir: str) None[source]#
univention.l10n.update_package_translation_files(module: UMCModuleTranslation, output_dir: str, template: bool = False) None[source]#
univention.l10n.write_makefile(all_modules: list[UMCModuleTranslation], special_cases: list[SpecialCase], new_package_dir: str, target_language: str) None[source]#

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() None[source]#
univention.l10n.cmd.main_build() None[source]#
univention.l10n.cmd.main_install() None[source]#
univention.l10n.cmd.parse_args(cmd: str) None[source]#
univention.l10n.cmd.build(args: Namespace) None[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: Namespace) None[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: str) None[source]#

Create parent directories for file.

Parameters:

path – Path for a file.

univention.l10n.helper.call(*argv: str, **kwargs: Any) int[source]#

Execute argv and wait.

Parameters:
>>> call('true')
0

univention.l10n.l10n module#

class univention.l10n.l10n.BaseModule[source]#

Bases: TypedDict

module_name: str#
package: str#
abs_path_to_src_pkg: str#
relative_path_src_pkg: str#
exception univention.l10n.l10n.NoSpecialCaseDefintionsFound[source]#

Bases: Error

exception univention.l10n.l10n.NoMatchingFiles[source]#

Bases: Error

class univention.l10n.l10n.UMCModuleTranslation(attrs: dict[str, Any], target_language: str)[source]#

Bases: UMC_Module

property python_po_files: Iterator[str]#

Iterate over all Python UMC message catalogs.

property js_po_files: Iterator[str]#

Iterate over all JavaScript UMC message catalogs.

property xml_po_files: Iterator[tuple[str, str]]#

Iterate over all XML UMC message catalogs.

python_mo_destinations() Iterator[tuple[str, str]][source]#
json_targets() Iterator[tuple[str, str]][source]#
xml_mo_destinations() Iterator[tuple[str, str]][source]#
classmethod from_source_package(module_in_source_tree: BaseModule, target_language: str) UMCModuleTranslation[source]#
class univention.l10n.l10n.SpecialCase(special_case_definition: dict[str, str], source_dir: str, path_to_definition: str, target_language: str)[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$')#
package_dir: str#
po_subdir: str#
destination: str#
get_source_file_sets() list[SourceFileSet][source]#
create_po_template(output_path: str = '.') str[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: UMCModuleTranslation, output_dir: str, template: bool = False) None[source]#
univention.l10n.l10n.write_makefile(all_modules: list[UMCModuleTranslation], special_cases: list[SpecialCase], new_package_dir: str, target_language: str) None[source]#
univention.l10n.l10n.translate_special_case(special_case: SpecialCase, source_dir: str, output_dir: str) None[source]#
univention.l10n.l10n.read_special_case_definition(definition_path: str, source_tree_path: str, target_language: str) Iterator[SpecialCase][source]#
univention.l10n.l10n.get_special_cases_from_srcpkg(source_tree_path: str, target_language: str) list[SpecialCase][source]#
univention.l10n.l10n.get_special_cases_from_checkout(source_tree_path: str, target_language: str) list[SpecialCase][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: str) list[BaseModule][source]#
univention.l10n.l10n.template_file(dst: str, fn: str, values: dict[str, str]) None[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: str, target_language: str, target_locale: str, language_name: str, startdir: str) None[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: str, dest_po_path: str) None[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: str, new_po_path: str) None[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: str, translation: str) None[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: str, output_file: str, input_files: str | list[str], cwd: str = '/builds/univention/dev/docs/ucsapidoc') None[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: str, abs_path_source_pkg: str) None[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: str, binary_pkg_name: str, files: Iterable[str])[source]#

Bases: object

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

Bases: SourceFileSet

class univention.l10n.sourcefileprocessing.SourceFilesShell(src_pkg_path: str, binary_pkg_name: str, files: Iterable[str])[source]#

Bases: SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesPython(src_pkg_path: str, binary_pkg_name: str, files: Iterable[str])[source]#

Bases: SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesJavaScript(src_pkg_path: str, binary_pkg_name: str, files: Iterable[str])[source]#

Bases: SourceFilesXgettext

class univention.l10n.sourcefileprocessing.SourceFilesHTML(src_pkg_path: str, binary_pkg_name: str, files: Iterable[str])[source]#

Bases: 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: str, binary_pkg_name: str, mimetype: str, files: Iterable[str]) SourceFileSet[source]#
univention.l10n.sourcefileprocessing.from_mimetype(src_pkg_path: str, binary_pkg_name: str, mimetype: str, files: Iterable[str]) SourceFileSet[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: str#

Return the name of the Debian binary package.

property python_path: str | None#

Return path to Python UMC directory.

property js_path: str | None#

Return path to JavaScript UMC directory.

property js_module_file: str | None#

Return path to main JavaScript file.

property js_files: Iterator[str]#

Iterate over all JavaScript UMC files.

property html_files: Iterator[str]#

Iterate over all JavaScript HTML files.

property css_files: Iterator[str]#

Iterate over all Javascript CSS files.

property module_name: str | None#

Return the name of the UMC module.

property xml_definition: str | None#

Return the path to the XML UMC definition.

property xml_categories: str | None#

Return the path to the XML file defining categories.

property python_files: Iterator[str]#

Iterate over all Python UMC files.

property python_po_files: Iterator[str]#

Iterate over all Python UMC message catalogs.

property js_po_files: Iterator[str]#

Iterate over all JavaScript UMC message catalogs.

property xml_po_files: Iterator[tuple[str, str]]#

Iterate over all XML UMC message catalogs.

property icons: str | None#

Return path to UMC icon directory.

univention.l10n.umc.read_modules(package: str, core: bool = False) list[UMC_Module][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: UMC_Module, po_file: str, language: str, template: bool = False) None[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: str, package: str, files: str | Iterable[str], language: str = 'python', template: bool = False) None[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: str, pot_file: str) None[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: str, mo_file: str = '') None[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: str) None[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: str, json_output_path: str) None[source]#

Convert translation file to JSON file.

Parameters:
  • po_path – Translation file name.

  • json_output_path – Output file name.