Post

SAP DDIC translation with Weblate - Part 2

SAP DDIC translation with Weblate - Part 2

SAP provides a built-in mechanism to manage translations, including the ability to import/export translations via XLIFF files. This is facilitated through the LXE_MASTER transaction, where you can create Object Lists (using the Evaluations tab). These lists hold all the relevant reports and DDIC objects for a translation project, making it easier to manage translations at scale.

In this post, I’ll walk through how we leveraged SAP’s translation infrastructure to integrate it with Weblate and automate our translation management process. The goal was to:

  1. Generate a list of objects to translate (Object Lists)
  2. Use the available functionality to import and export SAP translations to a widely recognized format (XLIFF)

🗂 Step 1: Create Object Lists in LXE_MASTER

The first step in our process was to make use of the existing SAP functionality, which allows you to create Object Lists in the LXE_MASTER transaction. These lists contain all the objects that need translation, such as reports and DDIC objects.

In our case, we wrote an ABAP report to fetch all the relevant objects from the Object List and export the translations to a Git repository. Here’s how we retrieved the objects from the list:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
" 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.

This SQL query pulls the objects related to the translation project, filtering by object types and excluding technical texts (since we only need user-facing content).


📤 Step 2: Export SAP Translations to XLIFF

After fetching the relevant objects, the next step was to transform the extracted data into an XLIFF file format. Here’s how we achieved that using SAP’s transformation tools:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 languages 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 the XML into a nicely formatted XLIFF file
TRY.
    " 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 ).

    " Write the formatted XML back
    rv_result = CAST cl_sxml_string_writer( lo_writer )->get_output( ).

  CATCH cx_root INTO DATA(e_txt).

ENDTRY.

" Validate the created XLIFF
cl_lxe_textext_aux=>validate_xliff(
  EXPORTING
    xliff   = rv_result
  EXCEPTIONS
    invalid = 1 ).
IF sy-subrc NE 0.
  RAISE EXCEPTION TYPE cx_lxe_textext
    EXPORTING
      textid = cx_lxe_textext=>xml_transform.
ENDIF.

This ABAP code snippet transforms the extracted texts into a valid XLIFF file format. After generating the XLIFF files, we used the GitLab API to send them to a Git repository. From there, Weblate could easily read and handle the translations.


🔗 Step 3: Integrating with GitLab and Weblate

Once we had the XLIFF files for each object list in every language, the next step was to send those files to a Git repository. By using the GitLab API, we were able to automate the process of committing the XLIFF files into a Git repository.

This integration enabled Weblate to access the translation files directly from the Git repository, facilitating the translation process with a user-friendly interface.


🧠 Final Thoughts

By combining SAP’s native translation management tools with the flexibility of Weblate and GitLab, we were able to streamline our translation workflows. This integration not only allowed us to efficiently manage our translations but also provided an automated pipeline for exporting and importing translations in a standardized format (XLIFF).

If you are working with SAP translations and want to integrate with a modern translation management system like Weblate, this approach can save you a lot of time and manual effort. I hope this post helps you get started with similar integrations in your own projects!

This post is licensed under CC BY 4.0 by the author.