From f5a5390d611e2dba8eca5efbfa40f97fd9094a23 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 7 Feb 2016 18:19:34 -0500 Subject: [PATCH] v0.3.4: improved the consistency of title case --- .../messages/Languages.java | 2 +- .../messages/Messages.java | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Languages.java b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Languages.java index 807dace09..5dae8bdd2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Languages.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Languages.java @@ -31,8 +31,8 @@ public enum Languages { CHINESE("中文", "zh", Status.UNREVIEWED, new String[]{"Jinkeloid"}, new String[]{"931451545", "HoofBumpBlurryface", "Lyn-0401", "ShatteredFlameBlast", "Tempest102"}), //Brazillian PORTUGUESE("português", "pt", Status.UNREVIEWED, new String[]{"Matheus208"}, new String[]{"JST", "Try31"}), + GERMAN("deutsch", "de", Status.UNREVIEWED, new String[]{"Davedude", "KrystalCroft"}, new String[]{"DarkPixel", "ErichME", "Sarius", "Zap0", "Oragothen"}), - GERMAN("deutsch", "de", Status.INCOMPLETE, new String[]{"Davedude", "KrystalCroft"}, new String[]{"DarkPixel", "ErichME", "Sarius", "Zap0", "Oragothen"}), POLISH("polski", "pl", Status.INCOMPLETE, null, new String[]{"Darden", "Deksippos", "Scharnvirk", "Wawrzyn"}), SPANISH("español", "es", Status.INCOMPLETE, null, new String[]{"CorvosUtopy", "LucasCamilo", "Luuciano96", "Prancer", "Talruin", "Ctrijueque", "Grayscales", "Jonismack1", "Pixeled4life"}), FRENCH("français", "fr", Status.INCOMPLETE, null, new String[]{"Kultissim", "Minikrob"}); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java index 16700df94..8291f6490 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java @@ -153,29 +153,35 @@ public class Messages { private static final HashSet noCaps = new HashSet<>( Arrays.asList(new String[]{ //English - "a", "of", - //French - "à", "avec", "de", "du", "des", - //Portugese - "a", "de", "des", "da", "das", "do", "dos", + "a", "of", "by", //German - "der", "des", - //Russian - "с", //Not an english c, looks just like it though. + "der", "des", "von", }) ); public static String titleCase( String str ){ - String result = ""; - //split by any unicode space character - for (String word : str.split("(?<=\\p{Zs})")){ - if (noCaps.contains(word.trim().toLowerCase())){ - result += word; - } else { - result += capitalize(word); - } + //These languages don't do capitalization + if (lang == Languages.CHINESE || lang == Languages.KOREAN){ + return str; } - //first character is always capitalized. - return capitalize(result); + + //These languages capitalize every word except for a few exceptions + //...Yes technically German is just every noun, but this should be close enough. + if (lang == Languages.ENGLISH || lang == Languages.GERMAN){ + String result = ""; + //split by any unicode space character + for (String word : str.split("(?<=\\p{Zs})")){ + if (noCaps.contains(word.trim().toLowerCase().replaceAll(":", ""))){ + result += word; + } else { + result += capitalize(word); + } + } + //first character is always capitalized. + return capitalize(result); + } + + //Otherwise, the language uses sentence case + return capitalize(str); } }