+ Added localization to 4 files. Revised format to use files as sections.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
[CommandBeansShow]
|
||||
Displays how many beans you have =
|
||||
You have %s beans! =
|
||||
|
||||
[CommandBetBeans]
|
||||
Please bet with at least 50 beans! =
|
||||
Allows you to bet your beans, set your amount after the command! Warning! House always wins!\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x =
|
||||
That's not a valid bet! =
|
||||
Sorry, you didn't win, try again! =
|
||||
You don't have enough beans! =
|
||||
You won %s beans! =
|
||||
|
||||
[CommandBoop]
|
||||
%s booped %s! =
|
||||
Kitty will react with a counter =
|
||||
Woah! %s booped me! That's %s total! =
|
||||
%s booped several others - %s! =
|
||||
|
||||
[CommandBlurry]
|
||||
Blurs your icon or the icon of a friend you mentioned =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package commands;
|
||||
|
||||
import core.Command;
|
||||
import core.Localizer;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandBeansShow extends Command
|
||||
@@ -8,12 +9,11 @@ public class CommandBeansShow extends Command
|
||||
public CommandBeansShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return "Displays how many beans you have"; };
|
||||
public String HelpText() { return Localizer.Stub("Displays how many beans you have"); };
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String beans = "You have " + user.GetBeans() + " beans!";
|
||||
res.Call(beans);
|
||||
res.Call(String.format(Localizer.Stub("You have %s beans!"), user.GetBeans()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package commands;
|
||||
|
||||
import core.Command;
|
||||
import core.Localizer;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandBetBeans extends Command
|
||||
@@ -8,8 +9,7 @@ public class CommandBetBeans extends Command
|
||||
public CommandBetBeans(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return "Allows you to bet your beans, set your amount after the command! Warning: House always wins!"
|
||||
+ "\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x"; }
|
||||
public String HelpText() { return Localizer.Stub("Allows you to bet your beans, set your amount after the command! Warning! House always wins!\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x"); }
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -22,19 +22,19 @@ public class CommandBetBeans extends Command
|
||||
bet = Integer.parseInt(input.args);
|
||||
if(bet < 50)
|
||||
{
|
||||
res.Call("Please bet with at least 50 beans!");
|
||||
res.Call(Localizer.Stub("Please bet with at least 50 beans!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
res.Call("That's not a valid bet!");
|
||||
res.Call(Localizer.Stub("That's not a valid bet!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.GetBeans() < bet)
|
||||
{
|
||||
res.Call("You don't have enough beans!");
|
||||
res.Call(Localizer.Stub("You don't have enough beans!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ public class CommandBetBeans extends Command
|
||||
|
||||
if(win == 0)
|
||||
{
|
||||
res.Call("Sorry, you didn't win, try again!");
|
||||
res.Call(Localizer.Stub("Sorry, you didn't win, try again!"));
|
||||
return;
|
||||
}
|
||||
|
||||
user.ChangeBeans(bet*win);
|
||||
res.Call("You won " + (bet*win) + " beans!");
|
||||
res.Call(String.format(Localizer.Stub("You won %s beans!"), "" + (bet*win)));
|
||||
}
|
||||
|
||||
private int getWinning(int [] slots)
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import core.Command;
|
||||
import core.Localizer;
|
||||
import dataStructures.*;
|
||||
import utils.ImageUtils;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class CommandBlurry extends Command
|
||||
public CommandBlurry(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return "Blurs your icon or the icon of a friend you mentioned"; };
|
||||
public String HelpText() { return Localizer.Stub("Blurs your icon or the icon of a friend you mentioned"); };
|
||||
|
||||
private static Long num = 0l;
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CommandBoop extends Command
|
||||
}
|
||||
|
||||
@Override
|
||||
public String HelpText() { return "Kitty will react with a counter"; }
|
||||
public String HelpText() { return Localizer.Stub("Kitty will react with a counter"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
@@ -69,16 +69,17 @@ public class CommandBoop extends Command
|
||||
if(input.mentions == null)
|
||||
{
|
||||
boopTracker.ApplyBoop();
|
||||
res.Call("Woah! " + user.name + " booped me! That's " + boopTracker.HowMany() + " total!");
|
||||
res.Call(String.format(Localizer.Stub("Woah! %s booped me! That's %s total!"), user.name, boopTracker.HowMany()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.mentions.length == 1)
|
||||
{
|
||||
boopTracker.ApplyBoop();
|
||||
res.Call(user.name + " booped " + input.mentions[0].name + "!");
|
||||
res.Call(String.format(Localizer.Stub("%s booped %s!"), user.name, input.mentions[0].name));
|
||||
return;
|
||||
}
|
||||
|
||||
String booped = "";
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
@@ -88,7 +89,8 @@ public class CommandBoop extends Command
|
||||
else
|
||||
booped += "and " + input.mentions[i].name;
|
||||
}
|
||||
res.Call(user.name + " booped " + booped + "!");
|
||||
|
||||
res.Call(String.format(Localizer.Stub("%s booped several others - %s!"), user.name, booped));
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
-14
@@ -2,6 +2,7 @@ package core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -21,10 +22,9 @@ public class Localizer
|
||||
// Filename
|
||||
public final static String filename = "phrases.config";
|
||||
public final static String functionName = "Localizer.Stub";
|
||||
public final static String section = "phrases";
|
||||
|
||||
// Local translation
|
||||
private static HashMap<String, String> translated = new HashMap<String, String>();
|
||||
private static HashMap<String, LocPair> translated = new HashMap<String, LocPair>();
|
||||
|
||||
// Logging
|
||||
private static void Log(String str) { System.out.println("[Log] " + str); }
|
||||
@@ -68,10 +68,23 @@ public class Localizer
|
||||
return items;
|
||||
}
|
||||
|
||||
// Do processing on each path in the scraped directory here, assuming it's .java
|
||||
public static void StripForContents(Path path, ArrayList<String> strings)
|
||||
public static class LocPair
|
||||
{
|
||||
if(path.getFileName().toString().contains(".java"))
|
||||
public String file;
|
||||
public String phrase;
|
||||
|
||||
public LocPair(String f, String p)
|
||||
{
|
||||
this.file = f;
|
||||
this.phrase = p;
|
||||
}
|
||||
}
|
||||
|
||||
// Do processing on each path in the scraped directory here, assuming it's .java
|
||||
public static void StripForContents(Path path, ArrayList<LocPair> strings)
|
||||
{
|
||||
String filename = path.getFileName().toString();
|
||||
if(filename.contains(".java"))
|
||||
{
|
||||
String contents = ReadContent(path);
|
||||
String[] split = contents.split(functionName);
|
||||
@@ -91,7 +104,8 @@ public class Localizer
|
||||
{
|
||||
String toLocalize = split[i].substring(2, loc - 1);
|
||||
|
||||
strings.add(toLocalize);
|
||||
strings.add(new LocPair(filename.substring(0, filename.lastIndexOf('.')), toLocalize));
|
||||
|
||||
Log("Found stubbed phrase in " + path + " : " + toLocalize);
|
||||
}
|
||||
catch(IndexOutOfBoundsException e)
|
||||
@@ -110,7 +124,7 @@ public class Localizer
|
||||
{
|
||||
if(translated.containsKey(input))
|
||||
{
|
||||
String value = translated.get(input);
|
||||
String value = translated.get(input).phrase;
|
||||
if(value.trim().length() > 0)
|
||||
return value;
|
||||
}
|
||||
@@ -136,7 +150,7 @@ public class Localizer
|
||||
for(String s : sec.keySet())
|
||||
{
|
||||
if(!translated.containsKey(s))
|
||||
translated.put(s, sec.get(s, String.class));
|
||||
translated.put(s, new LocPair(sec.getName(), sec.get(s, String.class)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,13 +171,19 @@ public class Localizer
|
||||
Log("Attempting to write updated localization file");
|
||||
try
|
||||
{
|
||||
PrintWriter pw = new PrintWriter(filename);
|
||||
pw.close();
|
||||
|
||||
File file = new File(filename);
|
||||
file.createNewFile();
|
||||
|
||||
Wini ini = new Wini(file);
|
||||
|
||||
for(String s : translated.keySet())
|
||||
ini.put(section, s, translated.get(s));
|
||||
{
|
||||
LocPair toWrite = translated.get(s);
|
||||
ini.put(toWrite.file, s, toWrite.phrase);
|
||||
}
|
||||
|
||||
ini.store();
|
||||
}
|
||||
@@ -181,15 +201,15 @@ public class Localizer
|
||||
// This stubs out phrases to be localized.
|
||||
public static void ScrapeAll()
|
||||
{
|
||||
ArrayList<String> localizeList = new ArrayList<String>();
|
||||
ArrayList<LocPair> localizeList = new ArrayList<LocPair>();
|
||||
AcquireAllFiles(".\\src").forEach((path) -> StripForContents(path, localizeList));
|
||||
|
||||
for(String toStub : localizeList)
|
||||
for(LocPair toStub : localizeList)
|
||||
{
|
||||
if(!translated.containsKey(toStub))
|
||||
if(!translated.containsKey(toStub.phrase))
|
||||
{
|
||||
translated.put(toStub, "");
|
||||
Log(" Found new stubbed phrase '" + toStub + "'");
|
||||
translated.put(toStub.phrase, new LocPair(toStub.file, ""));
|
||||
Log("Found new stubbed phrase '" + toStub.phrase + "' in " + toStub.file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -14,6 +14,7 @@ import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.guild.*;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import offline.*;
|
||||
import core.Localizer;
|
||||
import utils.GlobalLog;
|
||||
import net.dv8tion.jda.core.*;
|
||||
|
||||
@@ -26,15 +27,23 @@ public class Main extends ListenerAdapter
|
||||
private static CommandManager commandManager;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static Stats stats;
|
||||
private static RPManager rpManager;
|
||||
|
||||
// Main test location
|
||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||
{
|
||||
// Facotry startup.
|
||||
databaseManager = ObjectBuilderFactory.ConstructDatabaseManager();
|
||||
commandManager = ObjectBuilderFactory.ConstructCommandManager();
|
||||
ObjectBuilderFactory.ConstructRPManager();
|
||||
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
||||
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
||||
|
||||
// Localizer startup - Potentially integrate with the factory.
|
||||
Localizer.UpdateLocFromDisk();
|
||||
Localizer.ScrapeAll();
|
||||
Localizer.SaveLocToDisk();
|
||||
|
||||
// Bot startup
|
||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||
kitty.getPresence().setGame(Game.playing("with a new build"));
|
||||
kitty.addEventListener(new Main());
|
||||
|
||||
Reference in New Issue
Block a user