Extract STERM translations
SAP offers a lot of texts/translations in their Terminology/Glossary database (also known as STERM). If you want to use the predefined translations from STERM in another tool (like the Weblate translation memory), you can simply create a CDS view and a report to export those translations.
CDS View
First off all you should create a CDS view which offers an easy access to the STERM data:
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
@AbapCatalog.sqlViewName: 'ZCA_STERM_V'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Translations from STERM'
define view ZCA_STERM_TRANSLATION
as select from sterm_ob_v as source
inner join sterm_ob_v as destination
on destination.concept = source.concept
and destination.object_typ = '' {
source.langu as langu_source,
source.text as text_source,
source.text_uc as text_uc_source,
destination.langu as langu_destination,
destination.text as text_destination,
count(*) as counter
}
where
source.object_typ = ''
and source.langu <> destination.langu
group by
source.langu,
source.text,
source.text_uc,
destination.langu,
destination.text
Report
After that you can create a simple report to extract all translations from a source language to a destination language and export it as JSON:
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
REPORT zexport_sterm.
PARAMETERS: p_slangu TYPE zca_sterm_v-langu_source OBLIGATORY DEFAULT 'EN',
p_tlangu TYPE zca_sterm_v-langu_destination OBLIGATORY.
START-OF-SELECTION.
PERFORM start.
FORM start.
TYPES: BEGIN OF t_translation_memory,
source TYPE string,
source_language TYPE string,
target TYPE string,
target_language TYPE string,
origin TYPE string,
category TYPE i,
END OF t_translation_memory.
DATA: lt_export TYPE HASHED TABLE OF t_translation_memory
WITH UNIQUE KEY source source_language.
" get all translations from the STERM tables
SELECT *
FROM zca_sterm_v
INTO TABLE @DATA(lt_data)
WHERE langu_source EQ @p_slangu
AND langu_destination EQ @p_tlangu
ORDER BY counter DESCENDING.
LOOP AT lt_data INTO DATA(ls_data)
GROUP BY ( langu_source = ls_data-langu_source
text_source = ls_data-text_source ).
DATA(ls_export) = VALUE t_translation_memory( ).
CHECK ls_data-text_source IS NOT INITIAL AND ls_data-text_destination IS NOT INITIAL.
ls_export-source_language = cl_i18n_languages=>sap1_to_sap2( ls_data-langu_source ).
ls_export-source = ls_data-text_source.
ls_export-target_language = cl_i18n_languages=>sap1_to_sap2( ls_data-langu_destination ).
ls_export-target = ls_data-text_destination.
ls_export-origin = space.
ls_export-category = 1.
INSERT ls_export
INTO TABLE lt_export.
ENDLOOP.
IF lt_export IS INITIAL.
RETURN.
ENDIF.
" transform data to JSON
DATA(lf_json) = /ui2/cl_json=>serialize(
data = lt_export
pretty_name = /ui2/cl_json=>pretty_mode-low_case ).
TRY.
DATA: lv_action TYPE i.
DATA: lv_filename TYPE string.
DATA: lv_fullpath TYPE string.
DATA: lv_path TYPE string.
DATA: lt_json TYPE TABLE OF string.
" call save dialoag
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
default_file_name = 'texts.json'
default_extension = 'json'
file_filter = |JSON (*.json)\|*.json\|{ cl_gui_frontend_services=>filetype_all }|
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
user_action = lv_action ).
IF lv_action EQ cl_gui_frontend_services=>action_ok.
APPEND lf_json
TO lt_json.
" export file to local storage
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = lv_fullpath
filetype = 'ASC'
CHANGING
data_tab = lt_json ).
ENDIF.
CATCH cx_root INTO DATA(lo_text).
MESSAGE lo_text->get_text( ) TYPE 'I'.
ENDTRY.
ENDFORM.
Using this report allows you to easily export the best translation pairs (source <-> destination) to a local JSON file which can be imported into another tool of your choice.
If you need another export format (like XML, properties), you can easily adopt the report to produce the needed format.