Skip to content

Commit

Permalink
Improved PHP handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Oct 22, 2022
1 parent 6caa56e commit ef7c7ef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Binary file modified lib/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {

public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "2.9.0";
public static final String BUILD = "20221022_0824";
public static final String VERSION = "2.9.1";
public static final String BUILD = "20221022_0917";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
34 changes: 17 additions & 17 deletions src/com/maxprograms/converters/php/Php2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,21 @@ public static List<String> run(Map<String, String> params) {
}
}
String text = sb.toString();

char finishMark = ')';
String start = "";
int index = text.indexOf("array(");
if (index == -1) {
throw new IOException("Selected file lacks \"array(\" declaration");
if (index != -1) {
start = text.substring(0, index + "array(".length());
} else if ((index = text.indexOf("return")) != -1) {
index = text.indexOf("[", index + "return".length());
if (index != -1) {
start = text.substring(0, index + "[".length());
finishMark = ']';
}
}
if (start.isEmpty()) {
throw new IOException("Initial array delimiter not found");
}
String start = text.substring(0, index + "array(".length());
writeSkeleton(skeleton, start);
text = text.substring(index + "array(".length());

Expand All @@ -129,7 +138,7 @@ public static List<String> run(Map<String, String> params) {
char delimiter = '\'';
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == ')') {
if (c == finishMark) {
finished = true;
break;
}
Expand Down Expand Up @@ -205,18 +214,9 @@ private static void writeSkeleton(FileOutputStream skeleton, String string)

private static void writeSegment(FileOutputStream output, FileOutputStream skeleton, String source)
throws IOException {
if (source.startsWith("'")) {
source = source.replaceAll("\\\\'", "'");
source = source.replaceAll("\\\\\\\\", "\\\\");
}
if (source.startsWith("\"")) {
source = source.replace("\\\\'", "'");
source = source.replace("\\\"", "\"");
source = source.replace("\\\\\\\\", "\\\\");
source = source.replace("\\\\n", "\n");
source = source.replace("\\\\r", "\r");
source = source.replace("\\\\$", "$");
}
source = source.replace("\\'", "'");
source = source.replace("\\\"", "\"");
source = source.replace("\\\\", "\\");
String delimiter = source.substring(0, 1);
source = source.substring(1);
source = source.substring(0, source.length() - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/com/maxprograms/converters/php/Xliff2Php.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ private static String extractText(Element target) {
result = result + ((TextNode) n).getText();
}
}
result = result.replace("\\\\", "\\\\\\\\");
result = result.replace("\\\'", "\\\\\'");
result = result.replace("'", "\\'");
result = result.replace("\"", "\\\"");
return result;
}

Expand Down

0 comments on commit ef7c7ef

Please sign in to comment.