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
- A list ob objects to translate (Objects Lists)
- 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:
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.
and afterwards we morphed the entries from the object list into a XLIFF
file:
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 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
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 ).
" 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).
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.
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.