2828import com .yanglb .codegen .utils .Infos ;
2929import com .yanglb .codegen .utils .Resources ;
3030import com .yanglb .codegen .utils .StringUtil ;
31- import org .yaml . snakeyaml . reader . StreamReader ;
31+ import org .apache . commons . text . StringEscapeUtils ;
3232import org .yaml .snakeyaml .reader .UnicodeReader ;
3333
3434public class MsgCSTranslatorImpl extends BaseMsgTranslator {
@@ -71,8 +71,7 @@ protected void onTranslate() throws CodeGenException {
7171 sb .append (readResource ("msg/resx/schema.txt" ));
7272 }
7373
74- // 添加 resheader
75- // sb.append(this.settingMap.get("resheader"));
74+ // 添加 resheader
7675 sb .append (readResource ("msg/resx/resheader.txt" ));
7776
7877 // 替换标记
@@ -93,7 +92,8 @@ protected void onTranslate() throws CodeGenException {
9392 keys .put (id , true );
9493
9594 // 对字符串进行转换
96- String value = this .convert2CSCode (itm .get (this .msgLang ));
95+ id = escape (id );
96+ String value = this .escape (itm .get (this .msgLang ));
9797 sb .append (String .format (" <data name=\" %s\" >\r \n " , id ));
9898 sb .append (String .format (" <value>%s</value>\r \n " , value ));
9999 sb .append (String .format (" </data>\r \n " ));
@@ -108,14 +108,11 @@ protected void onTranslate() throws CodeGenException {
108108
109109 this .writableModel .setData (sb );
110110 }
111-
112- private String convert2CSCode (String value ) {
111+
112+ private String escape (String value ) {
113113 if (value == null ) return null ;
114-
115- // 先替换\r\n,防止有文档只有\r或\n 后面再替换一次
116- // value = value.replaceAll("\r\n", "\\\\r\\\\n");
117- // value = value.replaceAll("\r", "\\\\r\\\\n");
118- // value = value.replaceAll("\n", "\\\\r\\\\n");
114+
115+ value = StringEscapeUtils .escapeXml10 (value );
119116 return value ;
120117 }
121118}
0 commit comments