Skip to content
Permalink
Browse files

Launch l10n-ui in new process

  • Loading branch information...
LadyCailin committed Aug 10, 2019
1 parent 3b14bed commit dde3854bec33ba1d29fc0e0af172f530f74e3bd9
@@ -668,6 +668,11 @@ private ValidationException(String string) {

List<Argument> arguments = new ArrayList<>();
List<String> unclassified = new ArrayList<>();
List<String> rawArgs;

private ArgumentParserResults(List<String> rawArgs) {
this.rawArgs = new ArrayList<>(rawArgs);
}

private void updateArgument(Argument a) {
if(a == null) {
@@ -961,6 +966,14 @@ public String toString() {
}
return b.toString();
}

/**
* Returns a list of the raw, unprocessed arguments. This includes all arguments as is, with no processing.
* @return
*/
public List<String> getRawArguments() {
return new ArrayList<>(rawArgs);
}
}

public static ArgumentParser GetParser() {
@@ -1361,7 +1374,7 @@ public ArgumentParserResults match(String[] args) throws ValidationException {
}

private ArgumentParserResults parse(List<String> args) throws ValidationException {
ArgumentParserResults results = new ArgumentParserResults();
ArgumentParserResults results = new ArgumentParserResults(args);
//Fill in results with all the defaults
for(Argument arg : argumentModel) {
if(arg.defaultVal != null) {
@@ -1,16 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.laytonsmith.tools.docgen.localization;

import com.laytonsmith.PureUtilities.ArgumentParser;
import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery;
import com.laytonsmith.PureUtilities.CommandExecutor;
import com.laytonsmith.PureUtilities.Common.OSUtils;
import com.laytonsmith.PureUtilities.Common.StringUtils;
import com.laytonsmith.core.AbstractCommandLineTool;
import com.laytonsmith.core.tool;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
@@ -82,13 +83,38 @@ public ArgumentParser getArgumentParser() {
.setUsageName("path to database")
.setOptional()
.setName(DATABASE)
.setArgType(ArgumentParser.ArgumentBuilder.BuilderTypeNonFlag.STRING));
.setArgType(ArgumentParser.ArgumentBuilder.BuilderTypeNonFlag.STRING))
.addArgument(new ArgumentParser.ArgumentBuilder()
.setDescription("Runs the UI in the same shell process. By default, it creates a new"
+ " process and causes the initial shell to return.")
.asFlag()
.setName("in-shell"));
}

@Override
public void execute(ArgumentParser.ArgumentParserResults parsedArgs) throws Exception {
String database = parsedArgs.getStringArgument(DATABASE);
LocalizationUI.launch(database);
if(parsedArgs.isFlagSet("in-shell")) {
// Actually launch the GUI
LocalizationUI.launch(database);
} else {
// Relaunch the jar in a new process with the --run flag set,
// so that the process will be in its own subshell
List<String> largs = new ArrayList<>();
largs.add("java");
largs.add("-jar");
String jarPath = ClassDiscovery.GetClassContainer(LocalizationTools.class).getPath();
if(OSUtils.GetOS().isWindows() && jarPath.startsWith("/")) {
jarPath = jarPath.substring(1);
}
largs.add(jarPath);
largs.add("l10n-ui");
largs.addAll(parsedArgs.getRawArguments());
largs.add("--in-shell");
CommandExecutor ce = new CommandExecutor(largs.toArray(new String[largs.size()]));
ce.start();
System.exit(0);
}
}

@Override
@@ -365,7 +365,7 @@ public TranslationMemory generateNewTranslation(String locale, String englishKey

/**
* Unique segments are values that are very often repeated, and deserve being removed from other
* segments, and being their own segment. This are literals, not regex.
* segments, and being their own segment. These are literals, not regex.
*/
private static final String[] UNIQUE_SEGMENTS = new String[] {
"%s([[%s|Examples...]])",
@@ -382,7 +382,7 @@ public TranslationMemory generateNewTranslation(String locale, String englishKey
* it is filtered out.
*/
private static final Set<String> USELESS_SEGMENTS = new HashSet<>(Arrays.asList(new String[]{
",",
",", "%%", "<%", "%>"
}));


@@ -404,6 +404,10 @@ public TranslationMemory generateNewTranslation(String locale, String englishKey
inputString = inputString.replaceAll("(?s)%%ALIAS.*?%%", "");
inputString = inputString.replaceAll("(?s)<%PRE.*?%>", "");
inputString = inputString.replaceAll("(?s)%%PRE.*?%%", "");
inputString = inputString.replaceAll("(?s)<%SYNTAX.*?%>", "");
inputString = inputString.replaceAll("(?s)%%SYNTAX.*?%%", "");
inputString = inputString.replaceAll("%%[a-zA-Z_]+%%", "");
inputString = inputString.replaceAll("<%[a-zA-Z_]+%>", "");
inputString = inputString.replaceAll("(?s)<pre.*?</pre>", "");
inputString = inputString.replaceAll("\\{\\{.*?\\}\\}", "%s");
inputString = inputString.replaceAll("\\[\\[.*?\\|(.*?)\\]\\]", "[[%s|$1]]");
@@ -465,8 +469,13 @@ public TranslationMemory generateNewTranslation(String locale, String englishKey
}
return true;
})
// Strings that are just numbers in their entirety can be removed. We may consider
// relocalizing them automatically later, but we do have to be careful about version
// numbers and such.
.filter((string) -> !string.matches("^[0-9\\.]+$"))
// Segments that are entirely just a function name are removed.
.filter((string) -> !FUNCTION_NAMES.contains(string))
// TODO Also add object names
.filter((string) -> !USELESS_SEGMENTS.contains(string))
.collect(Collectors.toSet());
}

0 comments on commit dde3854

Please sign in to comment.
You can’t perform that action at this time.