v0.3.4: improved the consistency of title case

This commit is contained in:
Evan Debenham 2016-02-07 18:19:34 -05:00 committed by Evan Debenham
parent aed5e994b3
commit f5a5390d61
2 changed files with 25 additions and 19 deletions

View File

@ -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"});

View File

@ -153,23 +153,25 @@ public class Messages {
private static final HashSet<String> 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 ){
//These languages don't do capitalization
if (lang == Languages.CHINESE || lang == Languages.KOREAN){
return str;
}
//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())){
if (noCaps.contains(word.trim().toLowerCase().replaceAll(":", ""))){
result += word;
} else {
result += capitalize(word);
@ -178,4 +180,8 @@ public class Messages {
//first character is always capitalized.
return capitalize(result);
}
//Otherwise, the language uses sentence case
return capitalize(str);
}
}