Skip to content
Permalink
Browse files

Continue work on localization

Still several tasks to be done before this can be crossed off, but the
matching is pretty good now on the front page. Remaining tasks detailed
in src/main/java/com/ls/tools/docgen/l10n/TODO.md. Also fixed a bunch of
examples that were throwing compiler warnings due to bare strings.
  • Loading branch information...
LadyCailin committed Sep 11, 2019
1 parent aace269 commit 1fe82b46bb99d471410f3833e7507b246ff32112
@@ -3228,13 +3228,13 @@ public Version since() {
new ExampleScript("Usage with normal arrays. The default comparison method is HASH",
"array_intersect(array(1, 2, 3), array(2, 3, 4))"),
new ExampleScript("Demonstrates that STRICT_EQUALS does not consider different types to be equal",
"array_intersect(array('1', '2', '3'), array(1, 2, 3), STRICT_EQUALS)"),
"array_intersect(array('1', '2', '3'), array(1, 2, 3), 'STRICT_EQUALS')"),
new ExampleScript("Note that the results of this method are the same as the previous example,"
+ " but this version would be faster, and is preferred in all but the most exceptional cases.",
"array_intersect(array('1', '2', '3'), array(1, 2, 3), HASH)"),
"array_intersect(array('1', '2', '3'), array(1, 2, 3), 'HASH')"),
new ExampleScript("Demonstrates usage with equals. Note that '1' == 1 (but does not === 1) but since"
+ " the comparison method uses equals, not sequals, these arrays are considered equivalent.",
"array_intersect(array('1', '2', '3'), array(1, 2, 3), EQUALS)"),
"array_intersect(array('1', '2', '3'), array(1, 2, 3), 'EQUALS')"),
new ExampleScript("Usage with a custom closure", "array_intersect(\n"
+ "\tarray(array(id: 1, qty: 2), array(id: 2, qty: 5)),\n"
+ "\tarray(array(id: 1, qty: 2), array(id: 5, qty: 10)),\n"
@@ -3324,12 +3324,12 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
+ "@arrayB = array(0, 2, 5, 9)\n"
+ "array_subset_of(@arrayA, @arrayB)"),
new ExampleScript("Mix array",
"@arrayA = array(a: 1, b: array(one, two))\n"
+ "@arrayB = array(a: 1, b: array(one, two, three), c: 3)\n"
"@arrayA = array(a: 1, b: array('one', 'two'))\n"
+ "@arrayB = array(a: 1, b: array('one', 'two', 'three'), c: 3)\n"
+ "array_subset_of(@arrayA, @arrayB)"),
new ExampleScript("Mix array",
"@arrayA = array(a: 1, b: array(one, two))\n"
+ "@arrayB = array(a: 1, b: array(two, one, three), c: 3)\n"
"@arrayA = array(a: 1, b: array('one', 'two'))\n"
+ "@arrayB = array(a: 1, b: array('two', 'one', 'three'), c: 3)\n"
+ "array_subset_of(@arrayA, @arrayB)")
};
}
@@ -1793,7 +1793,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
+ "@array[0] = 4;\n"
+ "@array2 = import('array');\n"
+ "msg(@array2);"),
new ExampleScript("Array key usage", "@key = array(custom, name);\n"
new ExampleScript("Array key usage", "@key = array('custom', 'name');\n"
+ "export(@key, 'value');\n"
+ "@value = import(@key);\n"
+ "msg(@value);"),
@@ -3002,11 +3002,11 @@ public Version since() {
+ "msg('@val + 5: ' . (@val + 5)); // Works as if it were a primitive with most functions\n"
+ "(++@val); // As a special exception to how assignments work, increment/decrement works as well\n"
+ "msg(@val); // 1\n"),
new ExampleScript("Basic usage with procs", "proc(_testWithMutable, @a){\n"
new ExampleScript("Basic usage with procs", "proc _testWithMutable(@a){\n"
+ "\t@a[] = 5;\n"
+ "}\n\n"
+ ""
+ "proc(_testWithoutMutable, @a){\n"
+ "proc _testWithoutMutable(@a){\n"
+ "\t@a = 10;\n"
+ "}\n\n"
+ ""
@@ -23,7 +23,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URISyntaxException;
@@ -56,9 +55,10 @@
*
* @param description
* @param script
* @throws com.laytonsmith.core.exceptions.ConfigCompileException
*/
public ExampleScript(String description, String script) throws ConfigCompileException {
this(description, script, null, false);
this(StackTraceUtils.getCallingClass(), description, script, null, false);
}

/**
@@ -71,8 +71,9 @@ public ExampleScript(String description, String script) throws ConfigCompileExce
* @param intentionalCompileError
* @throws ConfigCompileException
*/
public ExampleScript(String description, String script, boolean intentionalCompileError) throws ConfigCompileException {
this(description, script, null, intentionalCompileError);
public ExampleScript(String description, String script, boolean intentionalCompileError)
throws ConfigCompileException {
this(StackTraceUtils.getCallingClass(), description, script, null, intentionalCompileError);
}

/**
@@ -84,7 +85,7 @@ public ExampleScript(String description, String script, boolean intentionalCompi
* @throws ConfigCompileException
*/
public ExampleScript(String description, String script, String output) throws ConfigCompileException {
this(description, script, output, false);
this(StackTraceUtils.getCallingClass(), description, script, output, false);
}

/**
@@ -98,20 +99,24 @@ public ExampleScript(String description, String script, String output) throws Co
* @throws ConfigCompileException
*/
@SuppressWarnings("unchecked")
private ExampleScript(String description, String script, String output, boolean intentionalCompileError) throws ConfigCompileException {
Class<?> c = StackTraceUtils.getCallingClass();
private ExampleScript(Class source, String description, String script, String output,
boolean intentionalCompileError)
throws ConfigCompileException {
Class<?> c = source;
if(Function.class.isAssignableFrom(c)) {
functionName = ReflectionUtils.instantiateUnsafe((Class<? extends Function>) c).getName();
}
this.description = description;
this.originalScript = script;
String errorOutput = "Oops, something went wrong with this example.";
String consoleErrorOutput = Static.MCToANSIColors(MCChatColor.RED.toString() + "Unintentional compile error in "
+ c.getEnclosingClass().getSimpleName() + ":" + functionName + "(): \"" + description + "\"\n" + MCChatColor.PLAIN_WHITE);
+ c.getEnclosingClass().getSimpleName() + ":" + functionName + "(): \"" + description + "\"\n"
+ MCChatColor.PLAIN_WHITE);
try {
Environment env = Static.GenerateStandaloneEnvironment();
this.script = MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, null,
new File((OSUtils.GetOS() == OSUtils.OS.WINDOWS ? "C:\\" : "/") + "Examples.ms"), true), env,
new File((OSUtils.GetOS() == OSUtils.OS.WINDOWS ? "C:\\" : "/") + "Examples/" + functionName
+ ".ms"), true), env,
// We can't send null here, or it errors out, but we really do want to bypass the linking in
// this instance. Therefore, we just return a list of all environments. We can't run the examples
// that require non-default environments, but we can at least ensure that the script will generally
@@ -215,20 +220,18 @@ public String getOutput() throws IOException, DataSourceException, URISyntaxExce
Class[] interfaces = new Class[]{
MCPlayer.class
};
MCPlayer p = (MCPlayer) Proxy.newProxyInstance(ExampleScript.class.getClassLoader(), interfaces, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if(method.getName().equals("getName") || method.getName().equals("getDisplayName")) {
return "Player";
}
if(method.getName().equals("sendMessage")) {
playerOutput.append(args[0].toString()).append("\n");
}
if(method.getName().equals("isOnline")) {
return true;
}
return genericReturn(method.getReturnType());
MCPlayer p = (MCPlayer) Proxy.newProxyInstance(ExampleScript.class.getClassLoader(), interfaces,
(Object proxy, Method method, Object[] args) -> {
if(method.getName().equals("getName") || method.getName().equals("getDisplayName")) {
return "Player";
}
if(method.getName().equals("sendMessage")) {
playerOutput.append(args[0].toString()).append("\n");
}
if(method.getName().equals("isOnline")) {
return true;
}
return genericReturn(method.getReturnType());
});
// TODO: Remove this dependency. Make MCPlayer implement a generic "User" and make that
// part of the GlobalEnv.
@@ -258,7 +261,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
String playerOut = playerOutput.toString().trim();
String finalOut = finalOutput.toString().trim();

String out = (playerOut.isEmpty() ? "" : playerOut) + (finalOut.isEmpty() || !playerOut.trim().isEmpty() ? "" : ":" + finalOut);
String out = (playerOut.isEmpty() ? "" : playerOut) + (finalOut.isEmpty() || !playerOut.trim().isEmpty()
? "" : ":" + finalOut);
if(thrown != null) {
out += thrown;
}
@@ -239,12 +239,12 @@ public MSVersion since() {
"set_itemmeta(5, array(potions: array(array(id: 8, strength: 4, seconds: 90, ambient: true))))",
"Turns the potion in slot 5 into a Potion of Leaping V"),
new ExampleScript("Demonstrates hiding a potion effect",
"set_itemmeta(4, array(flags: array(HIDE_POTION_EFFECTS)))",
"set_itemmeta(4, array(flags: array('HIDE_POTION_EFFECTS')))",
"Hides the text indicating meta information for the item in slot 4."
+ " The flag HIDE_POTION_EFFECTS hides specific item meta like book meta, potion effects,"
+ " a music disc's author and name, firework meta, map meta, and stored enchantments."),
new ExampleScript("Demonstrates making a custom banner",
"set_itemmeta(0, array(basecolor: SILVER, patterns: array(array(color: BLACK, shape: SKULL))))",
"set_itemmeta(0, array(basecolor: 'SILVER', patterns: array(array(color: 'BLACK', shape: 'SKULL'))))",
"This banner will be silver with a black skull."),
new ExampleScript("Demonstrates making a custom firework",
"set_itemmeta(null, array('firework': array('strength': 1, 'effects': array(array("
@@ -949,7 +949,7 @@ public String docs() {
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Basic usage",
"set_mob_equipment(spawn_mob('SKELETON')[0], array(WEAPON: array(name: BOW)))",
"set_mob_equipment(spawn_mob('SKELETON')[0], array(WEAPON: array(name: 'BOW')))",
"Gives a bow to a skeleton")
};
}
@@ -2652,8 +2652,8 @@ public Version since() {
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Typical usage", "uuid()", "46fa3d0e-0178-4384-8a9c-2f0df1cada2b"),
new ExampleScript("Explicit RANDOM uuid", "uuid(RANDOM)", "fb9f9a7b-76c2-40e3-ba20-8ab23553b9d6"),
new ExampleScript("NIL uuid", "uuid(NIL)")
new ExampleScript("Explicit RANDOM uuid", "uuid('RANDOM')", "fb9f9a7b-76c2-40e3-ba20-8ab23553b9d6"),
new ExampleScript("NIL uuid", "uuid('NIL')")
};
}
}
@@ -0,0 +1,14 @@
Still to do before localization is complete:

#### Site
- Need to figure out why square bracket links are wrong only when translated.
- Need to translate a few more pages manually to ensure everything is applying correctly.

#### l10n-ui
- Pull Requests aren't implemented.
- Find Segment menu isn't implemented.
- Ensure Help file is complete and correct.

#### Segments
- Learning trail isn't translated at all yet.
- Some <%templates%> that could be translated aren't added to the segments list yet.
@@ -443,9 +443,17 @@ public TranslationMemory generateNewTranslation(Locale locale, String englishKey
"NOTE"
));

/**
* These are segments that are in the frame, and therefore in all pages. They are outside of the normal
* parsing system, so need to be added manually.
*/
private static final Set<String> FRAME_SEGMENTS = new HashSet<>(Arrays.asList(
"Home", "Docs", "Help", "%s Team. All rights reserved.", "About", "Privacy Policy", "Sponsors"
));


/**
* Splits an input string intos segments, which can be used to create smaller individual memories, increasing
* Splits an input string into segments, which can be used to create smaller individual memories, increasing
* the chance of collisions, as well as reducing the chance of retranslation needed when just parts of a page
* change. This is a best effort attempt, and isn't perfect.
* @param inputString
@@ -458,6 +466,10 @@ public TranslationMemory generateNewTranslation(Locale locale, String englishKey
inputString = inputString.replaceAll("\\\\\n", "");
inputString = inputString.replaceAll("(?s)<script.*?</script>", "");
{
// Some templates are immune to this, because it breaks the segments otherwise. So we need to first %s a few
// special templates.
inputString = inputString.replaceAll("%%CURRENT_VERSION%%", "%s");
inputString = inputString.replaceAll("<%CURRENT_VERSION%>", "%s");
inputString = inputString.replaceAll("(?s)%%.*?%%", "");
// Template removal. We can't use regex here, because <% %> templates can be nested. Eventually, we want
// to use the whitelist, but for now, just remove all templates.
@@ -492,6 +504,7 @@ public TranslationMemory generateNewTranslation(Locale locale, String englishKey
inputString = inputString.replaceAll("\\{\\{.*?\\}\\}", "%s");
inputString = inputString.replaceAll("\\[\\[.*?\\|(.*?)\\]\\]", "[[%s|$1]]");
inputString = inputString.replaceAll("\\[\\[File:.*?\\]\\]", "");
inputString = inputString.replaceAll("\\[\\[Image:.*?\\]\\]", "");
inputString = inputString.replaceAll("\\[" + URL_PATTERN + "( .*?)\\]", "[%s$1]");
inputString = inputString.replaceAll(URL_PATTERN, "%s");
inputString = inputString.replaceAll("(?s)<.*?>", "%s");
@@ -523,6 +536,7 @@ public TranslationMemory generateNewTranslation(Locale locale, String englishKey
inputString = inputString.replaceAll(TABLE_PATTERN_STRING, "");

segments.addAll(Arrays.asList(SPLIT_PATTERN.split(inputString)));
segments.addAll(FRAME_SEGMENTS);

return segments.stream()
.filter(string -> string != null)
@@ -103,7 +103,7 @@
private static final String INSTALL_PUB_KEYS = "install-pub-keys";

private static final String PRODUCTION_TRANSLATIONS_URL
= "https://github.com/LadyCailin/MethodScriptTranslationDB/blob/master/";
= "https://raw.githubusercontent.com/LadyCailin/MethodScriptTranslationDB/master/";

@SuppressWarnings("ResultOfObjectAllocationIgnored")
public static void run(boolean generatePrefs, boolean useLocalCache, File sitedeploy, String password,
@@ -17,6 +17,7 @@
</script>
<!--[if lte IE 8]><script src="%%cacheBuster|css/ie/html5shiv.js%%"></script><![endif]-->
<script src="%%cacheBuster|js/jquery.min.js%%" type="text/javascript"></script>
<script src="%%cacheBuster|js/js.cookie.js%%" type="text/javascript"></script>
<script type="text/javascript">
// There is a second, javascript step to render the wiki markup. When that wiki markup is
// completed, this promise will be called, and any javascript within the page can be run
@@ -61,12 +62,12 @@
<!-- Header -->
<header id="header">
<img src="%%cacheBuster|images/CommandHelper_Icon.png%%" alt=""/>
<h1><a href="%%siteRoot%%">%%branding%%</a></h1>
<h1><a id="mainBranding" href="%%siteRoot%%">%%branding%%</a></h1>
<nav id="nav">
<ul>
<li><a href="%%siteRoot%%">Home</a></li>
<li><a href="%%siteRoot%%docs/">Docs</a></li>
<li><a href="%%docsBase%%Help.html">Help</a></li>
<li><a href="%%siteRoot%%" data-l10n>Home</a></li>
<li><a href="%%siteRoot%%docs/" data-l10n>Docs</a></li>
<li><a href="%%docsBase%%Help.html" data-l10n>Help</a></li>
</ul>
</nav>
</header>
@@ -93,11 +94,11 @@ <h1><a href="%%siteRoot%%">%%branding%%</a></h1>
<div id="learningTrail"></div>
</div>
<ul class="copyright">
<li>&copy; 2016 - %%CURRENTYEAR%% %%branding%% Team. All rights reserved.</li>
<li><a href="%%docsBase%%About.html">About</a></li>
<li data-l10n>&copy; 2016 - %%CURRENTYEAR%% %%branding%% Team. All rights reserved.</li>
<li><a href="%%docsBase%%About.html" data-l10n>About</a></li>
<li style="%%showTemplateCredit%%">Design: <a href="http://templated.co">TEMPLATED</a></li>
<li><a href="%%docsBase%%privacy_policy.html">Privacy Policy</a></li>
<li><a href="/sponsors.html">Sponsors</a></li>
<li><a href="%%docsBase%%privacy_policy.html" data-l10n>Privacy Policy</a></li>
<li><a href="/sponsors.html" data-l10n>Sponsors</a></li>
</ul>
</div>
</footer>

0 comments on commit 1fe82b4

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