通常我们需要进入程序的text element在tab页selection texts进行字段标签的更改以及翻译,如下:
下面介绍一个能翻译选择画面上的文本(selection text)的工具,是一段小程序。程序选择画面如下:
通过此程序翻译的内容需要手工通过tcode slxt手动包到传输请求(TR)中-->参照使用SLXT传输翻译文本
完整代码:
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
REPORT z_report_translation. * Thanks a lot for Dylan's effort! TABLES: t002. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 . PARAMETERS: p_prog TYPE sy-cprog OBLIGATORY, p_key TYPE textpool-key OBLIGATORY. SELECT-OPTIONS: s_langu FOR sy-langu. SELECTION-SCREEN END OF BLOCK b1. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 . PARAMETERS: p_rb1 RADIOBUTTON GROUP gp1, p_rb2 RADIOBUTTON GROUP gp1. PARAMETERS: p_type TYPE typename. PARAMETERS: p_text TYPE z_char255_low. SELECTION-SCREEN END OF BLOCK b2. DATA: lit_text TYPE SORTED TABLE OF textpool WITH UNIQUE KEY id key, l_char255 TYPE char255, l_entry TYPE char255. START-OF-SELECTION. IF p_rb1 = abap_true. IF p_type IS INITIAL. RETURN. ENDIF. ENDIF. IF p_rb2 = abap_true. IF p_text IS INITIAL. RETURN. ENDIF. ENDIF. * 判断程序是否存在 SELECT SINGLE * FROM trdir INTO @DATA(lwa_prog) WHERE name = @p_prog. IF sy-subrc <> 0. RETURN. ENDIF. * 判断目标语言是否存在 SELECT * FROM t002 INTO TABLE @DATA(lit_t002) WHERE spras IN @s_langu. IF sy-subrc <> 0. RETURN. ENDIF. LOOP AT lit_t002 INTO DATA(lwa_t002). CLEAR l_char255. IF p_rb1 = abap_true. PERFORM frm_get_trans_text USING p_type "数据元素 'SCRTEXT_L' "Long Field Label lwa_t002-spras "语言 CHANGING l_char255. "文本 * 文本前加空格 l_entry = | { l_char255 }|. ENDIF. IF p_rb2 = abap_true. l_entry = | { p_text }|. ENDIF. IF l_entry IS INITIAL. CONTINUE. ENDIF. CLEAR lit_text. * 读取程序selection text READ TEXTPOOL p_prog INTO lit_text LANGUAGE lwa_t002-spras. DATA(l_len) = strlen( l_entry ). READ TABLE lit_text ASSIGNING FIELD-SYMBOL(<fs_text>) WITH KEY id = 'S' key = p_key BINARY SEARCH. IF sy-subrc = 0. * 存在选择文本,就替换 <fs_text>-entry = l_entry. <fs_text>-length = l_len. ELSE. * 不能存在就新插入 INSERT VALUE #( id = 'S' key = p_key entry = l_entry length = l_len ) INTO TABLE lit_text. ENDIF. * 替换程序选择文本selection text INSERT TEXTPOOL p_prog FROM lit_text LANGUAGE lwa_t002-spras. ENDLOOP. *&---------------------------------------------------------------------* *& Form FRM_GET_TRANS_TEXT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_TYPE text * -->P_LWA_T002_SPRAS text * <--P_L_CHAR255 text *----------------------------------------------------------------------* FORM frm_get_trans_text USING i_data_element i_fieldname i_spras CHANGING e_text. DATA: l_dd04t TYPE dd04t. FIELD-SYMBOLS: <lfs_text> TYPE clike. CLEAR:e_text. * 读取文本 SELECT SINGLE * FROM dd04t INTO l_dd04t WHERE rollname = i_data_element AND ddlanguage = i_spras. IF sy-subrc NE 0. * 目标语言文本不存在的场合下读取英语文本 SELECT SINGLE * FROM dd04t INTO l_dd04t WHERE rollname = i_data_element AND ddlanguage = 'E'. ENDIF. ASSIGN COMPONENT i_fieldname OF STRUCTURE l_dd04t TO <lfs_text>. IF sy-subrc = 0. e_text = <lfs_text>. ELSE. e_text = l_dd04t-ddtext. ENDIF. ENDFORM. |
运行测试,就选择上面这个翻译工具这个程序,现在要将选择画面上的‘Program’变成‘Program ID’,如下:
运行后,
其他翻译小工具-->消息类中文本翻译小工具
以上。
发表评论