Created internationalization helper class and began i18n process

This commit is contained in:
Tim Ziankoski 2015-03-07 20:50:47 -05:00
parent e0ba667613
commit ac4b495301
8 changed files with 134 additions and 8 deletions

View File

@ -17,7 +17,7 @@
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jedis-2.4.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/gson-2.2.1.jar" path-in-jar="/" />
<element id="module-output" name="Mineplex.Database" />
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.4.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.5.2.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -3,6 +3,7 @@
<output-path>$PROJECT_DIR$/../Testing/Arcade/plugins</output-path>
<root id="root">
<element id="artifact" artifact-name="Nautilus.Game.Arcade:jar" />
<element id="library" level="project" name="NoCheatPlus" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

View File

@ -4,10 +4,10 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="craftbukkit" level="project" />
</component>
</module>
</module>

View File

@ -0,0 +1 @@
waiting.for.players=Warten auf Spieler

View File

@ -0,0 +1,4 @@
waiting.for.players=Waiting for Players
lobby=Lobby
starting.in.0.seconds=Starting in {0} Seconds
starting.in.0.seconds.singular=Starting in {0} Second

View File

@ -0,0 +1,115 @@
package mineplex.core.common.lang;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.WeakHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public final class Lang
{
private static final String RESOURCE_BUNDLE_PATH = "mineplex/core/common/lang/mineplex";
private static final Map<Player, Locale> _playerLocales = new WeakHashMap<>();
private static final ResourceBundle _defaultResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH);
private static final Map<Locale, ResourceBundle> _localeResourceBundles = Collections.synchronizedMap(new HashMap<Locale, ResourceBundle>());
private Lang()
{
}
public static void setPlayerLocale(Player player, Locale locale)
{
_playerLocales.put(player, locale);
}
public static ResourceBundle getDefaultResourceBundle()
{
return _defaultResourceBundle;
}
public static ResourceBundle getResourceBundle(Locale locale)
{
ResourceBundle bundle = getDefaultResourceBundle();
synchronized (_localeResourceBundles)
{
if (_localeResourceBundles.containsKey(locale))
{
ResourceBundle b = _localeResourceBundles.get(locale);
if (b != null)
bundle = b;
}
else
{
try
{
bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH, locale);
_localeResourceBundles.put(locale, bundle);
}
catch (MissingResourceException e)
{
_localeResourceBundles.put(locale, null);
Bukkit.getLogger().warning(e.getMessage());
}
}
}
return bundle;
}
public static String getString(String key, int count)
{
return getString(key, (Locale) null, count);
}
public static String getString(String key, Locale locale, int count)
{
if (key == null)
return null;
else
{
ResourceBundle bundle;
if (locale == null)
bundle = getDefaultResourceBundle();
else
bundle = getResourceBundle(locale);
if (count == 1)
{
String singularKey = key + ".singular";
if (bundle.containsKey(singularKey))
return bundle.getString(singularKey);
}
return bundle.getString(key);
}
}
public static String getString(String key, Player player, int count)
{
return getString(key, _playerLocales.get(player), count);
}
public static String getString(String key)
{
return getString(key, 0);
}
public static String getString(String key, Locale locale)
{
return getString(key, locale, 0);
}
public static String getString(String key, Player player)
{
return getString(key, player, 0);
}
}

View File

@ -1,10 +1,11 @@
package nautilus.game.arcade.managers;
import java.util.ArrayList;
import java.text.MessageFormat;import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
@ -41,6 +42,7 @@ import net.minecraft.server.v1_7_R4.WatchableObject;
import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank;
import mineplex.core.common.lang.Lang;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
@ -948,18 +950,18 @@ public class GameLobbyManager implements Listener, IPacketHandler
for (Entry<Player, Scoreboard> entry : _scoreboardMap.entrySet())
{
Objective objective = entry.getValue().getObjective("§l" + "Lobby");
Objective objective = entry.getValue().getObjective(C.Bold + Lang.getString("lobby", entry.getKey()));
if (Manager.GetGame() != null && Manager.GetGame().GetCountdown() >= 0)
{
if (Manager.GetGame().GetCountdown() > 0)
objective.setDisplayName(C.Bold + "§lStarting in " + C.cGreen + "§l" + Manager.GetGame().GetCountdown() + (Manager.GetGame().GetCountdown() == 1 ? " Second" : " Seconds"));
objective.setDisplayName(MessageFormat.format(C.Bold + Lang.getString("starting.in.0.seconds", entry.getKey(), Manager.GetGame().GetCountdown()), C.cGreen + C.Bold + Manager.GetGame().GetCountdown()));
else if (Manager.GetGame().GetCountdown() == 0)
objective.setDisplayName(ChatColor.WHITE + "§lIn Progress...");
}
else
{
objective.setDisplayName(ChatColor.GREEN + "§l" + "Waiting for Players");
objective.setDisplayName(C.cGreen + C.Bold + Lang.getString("waiting.for.players", entry.getKey()));
}
int line = 15;