|
24 | 24 | import com.yanglb.codegen.utils.Infos; |
25 | 25 | import com.yanglb.codegen.utils.Resources; |
26 | 26 | import com.yanglb.codegen.utils.StringUtil; |
| 27 | +import org.apache.commons.text.StringEscapeUtils; |
27 | 28 |
|
28 | 29 | public class MsgIOSTranslatorImpl extends BaseMsgTranslator { |
29 | 30 | @Override |
@@ -60,21 +61,23 @@ protected void onTranslate() throws CodeGenException { |
60 | 61 | keys.put(id, true); |
61 | 62 |
|
62 | 63 | // 对字符串进行转换 |
63 | | - String value = this.convert2CSCode(itm.get(this.msgLang)); |
| 64 | + id = escape(id); |
| 65 | + String value = this.escape(itm.get(this.msgLang)); |
64 | 66 | sb.append(String.format("\"%s\" = \"%s\";\r\n", id, value)); |
65 | 67 | } |
66 | 68 | } |
67 | 69 |
|
68 | 70 | this.writableModel.setData(sb); |
69 | 71 | } |
70 | 72 |
|
71 | | - private String convert2CSCode(String value) { |
| 73 | + private String escape(String value) { |
72 | 74 | if(value == null) return null; |
73 | | - |
74 | | - // 先替换\r\n,防止有文档只有\r或\n 后面再替换一次 |
75 | | - value = value.replaceAll("\r\n", "\\\\r\\\\n"); |
76 | | - value = value.replaceAll("\r", "\\\\r\\\\n"); |
77 | | - value = value.replaceAll("\n", "\\\\r\\\\n"); |
| 75 | + |
| 76 | + value = value.replaceAll("\\\\", "\\\\\\\\"); |
| 77 | + value = value.replaceAll("\"", "\\\\\""); |
| 78 | + |
| 79 | + value = value.replaceAll("\r", ""); |
| 80 | + value = value.replaceAll("\n", "\\\\n"); |
78 | 81 | return value; |
79 | 82 | } |
80 | 83 | } |
0 commit comments