SAP DDIC translation with Weblate - Part 2

5 minute read

SAP itself has a report (and function modules) to import/export translations via XLIFF files. The transaction for the translation administration is LXE_MASTER. In this transaction you are able to create Object Lists (via tab Evaluations) which hold all relevant reports/DDIC objects for a translation project.

Our idea was to use this infrastructure since integrating Weblate into the SAP translation process needs

  1. A list ob objects to translate (Objects Lists)
  2. Some functionality to import/export the SAP translations into a well known format (XLIFF)

Using the given infrastructure, we simply created an object list in LXE_MASTER and wrote a report which exported the existing translations into our Gitlab instance.

We fetched all (relevant) objects from the object list in this way:

" allow all types of short text
SELECT obj_type
  FROM lxe_attob
  INTO TABLE @data(lt_objtypes)
  WHERE typeatt EQ @cl_lxe_constants=>c_typeatt_short "#EC CI_NOFIELD
    AND objgrp NE 'G5'.                                                 " no need for technical texts

" select all objects from the object lists
SELECT custmnr objtype objname orig_lang collnam domanam
  FROM lxe_colob
  INTO TABLE @data(t_colob_st)
  FOR ALL ENTRIES IN @lt_objtypes
  WHERE objlist EQ @iv_objlist
    AND objtype EQ @lt_objtypes-table_line.

and afterwards we morphed the entries from the object list into a XLIFF file:

DATA: lv_source_lang      TYPE lxestring,
      lv_destination_lang TYPE lxestring,
      lv_reference_lang   TYPE lxestring,
      lv_tstamp_str       TYPE lxestring.

DATA: lt_objects TYPE cl_lxe_textext_aux=>tt_lxe_object_full.

" prepare the texts
lt_objects = prepare_short_texts( iv_lang ).

" convert langs to xml
lv_source_lang = cl_lxe_textext_aux=>convert_lang_sap_to_xml( gv_source_lang ).
lv_destination_lang = cl_lxe_textext_aux=>convert_lang_sap_to_xml( iv_lang ).
lv_tstamp_str = create_xliff_date( ).

CALL TRANSFORMATION lxe_shorttext_to_xliff
  SOURCE objects      = lt_objects
          src_lang     = lv_source_lang
          tgt_lang     = lv_destination_lang
          ref_lang     = lv_reference_lang
          timestamp    = lv_tstamp_str
  RESULT XML rv_result.

" Transform it to a nicely intended XML
    " read the XML file
    DATA(lo_reader) = cl_sxml_string_reader=>create( rv_result ).

    " set up the writer
    DATA(lo_writer) = CAST if_sxml_writer( cl_sxml_string_writer=>create( type     = if_sxml=>co_xt_xml10
                                                                          encoding = 'UTF-8' ) ).
    lo_writer->set_option( if_sxml_writer=>co_opt_linebreaks ).
    lo_writer->set_option( if_sxml_writer=>co_opt_indent ).

    lo_reader->next_node( ).
    lo_reader->skip_node( lo_writer ).

    " and write it back to the xstring
    rv_result = CAST cl_sxml_string_writer( lo_writer )->get_output( ).

  CATCH cx_root INTO DATA(e_txt).


" validate the created xliff
    xliff   = rv_result
    invalid = 1 ).
IF sy-subrc NE 0.
  RAISE EXCEPTION TYPE cx_lxe_textext
      textid = cx_lxe_textext=>xml_transform.

Now we had a XLIFF file for every object list in every language - by using the Gitlab API we managed to send those files into a Git repository which can be read by Weblate.

Manuel Laggner

Manuel Laggner

technic freak, linux user and developer (Java/ABAP)

Follow Manuel: