v0.3.4: improvements to languages handling

This commit is contained in:
Evan Debenham 2016-02-06 05:30:24 -05:00 committed by Evan Debenham
parent 34f6e8540f
commit 2746c0f220
4 changed files with 125 additions and 102 deletions

View File

@ -26,10 +26,10 @@ import android.os.Bundle;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
@ -340,20 +340,20 @@ public class ShatteredPixelDungeon extends Game {
return Preferences.INSTANCE.getInt( Preferences.KEY_BRIGHTNESS, 0 ); return Preferences.INSTANCE.getInt( Preferences.KEY_BRIGHTNESS, 0 );
} }
public static void language(Messages.Languages lang) { public static void language(Languages lang) {
Preferences.INSTANCE.put( Preferences.KEY_LANG, lang.code()); Preferences.INSTANCE.put( Preferences.KEY_LANG, lang.code());
} }
public static Messages.Languages language() { public static Languages language() {
String code = Preferences.INSTANCE.getString(Preferences.KEY_LANG, null); String code = Preferences.INSTANCE.getString(Preferences.KEY_LANG, null);
if (code == null){ if (code == null){
Messages.Languages lang = Messages.Languages.matchLocale(Locale.getDefault()); Languages lang = Languages.matchLocale(Locale.getDefault());
if (lang.status() == Messages.Languages.Status.REVIEWED) if (lang.status() == Languages.Status.REVIEWED)
return lang; return lang;
else else
return Messages.Languages.ENGLISH; return Languages.ENGLISH;
} }
else return Messages.Languages.matchCode(code); else return Languages.matchCode(code);
} }
public static void lastClass( int value ) { public static void lastClass( int value ) {

View File

@ -0,0 +1,83 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2015 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.messages;
import java.util.Locale;
public enum Languages {
ENGLISH("english", "", Status.REVIEWED, null, null),
RUSSIAN("русский", "ru", Status.REVIEWED, new String[]{"ConsideredHamster", "Inevielle", "Yarikonline"}, new String[]{"HerrGotlieb", "Shamahan"}),
KOREAN("한국어", "ko", Status.REVIEWED, new String[]{"Flameblast12"}, new String[]{"Ddojin0115", "Eeeei", "lsiebnie", "WondarRabb1t"}),
CHINESE("中文", "zh", Status.UNREVIEWED, null, null), //Simplified
PORTUGUESE("português", "pt", Status.UNREVIEWED, null, null), //Brazillian
GERMAN("deutsch", "de", Status.INCOMPLETE, null, null),
POLISH("polski", "pl", Status.INCOMPLETE, null, null),
SPANISH("español", "es", Status.INCOMPLETE, null, null),
FRENCH("français", "fr", Status.INCOMPLETE, null, null);
public enum Status{
//below 60% complete languages are not added.
INCOMPLETE, //60-99% complete
UNREVIEWED, //100% complete
REVIEWED //100% reviewed
}
private String name;
private String code;
private Status status;
private String[] reviewers;
private String[] translators;
Languages(String name, String code, Status status, String[] reviewers, String[] translators){
this.name = name;
this.code = code;
this.status = status;
this.reviewers = reviewers;
this.translators = translators;
}
public String nativeName(){
return name;
}
public String code(){
return code;
}
public Status status(){
return status;
}
public static Languages matchLocale(Locale locale){
return matchCode(locale.getLanguage());
}
public static Languages matchCode(String code){
for (Languages lang : Languages.values()){
if (lang.code().equals(code))
return lang;
}
return ENGLISH;
}
}

View File

@ -38,63 +38,6 @@ import java.util.ResourceBundle;
*/ */
public class Messages { public class Messages {
public enum Languages {
ENGLISH("english", "", Status.REVIEWED),
RUSSIAN("русский", "ru", Status.REVIEWED),
KOREAN("한국어", "ko", Status.REVIEWED),
CHINESE("中文", "zh", Status.UNREVIEWED), //Simplified
PORTUGUESE("português", "pt", Status.UNREVIEWED), //Brazillian
GERMAN("deutsch", "de", Status.INCOMPLETE),
POLISH("polski", "pl", Status.INCOMPLETE),
SPANISH("español", "es", Status.INCOMPLETE),
FRENCH("français", "fr", Status.INCOMPLETE);
private String name;
private String code;
private Status status;
Languages(String name, String code, Status status){
this.name = name;
this.code = code;
this.status = status;
}
public String nativeName(){
return name;
}
public String code(){
return code;
}
public Status status(){
return status;
}
public static Languages matchLocale(Locale locale){
return matchCode(locale.getLanguage());
}
public static Languages matchCode(String code){
for (Languages lang : Languages.values()){
if (lang.code().equals(code))
return lang;
}
return ENGLISH;
}
public enum Status{
//below 60% complete languages are not added.
INCOMPLETE, //60-99% complete
UNREVIEWED, //100% complete
REVIEWED //100% reviewed
}
}
/* /*
use hashmap for two reasons. Firstly because android 2.2 doesn't support resourcebundle.containskey(), use hashmap for two reasons. Firstly because android 2.2 doesn't support resourcebundle.containskey(),
secondly so I can read in and combine multiple properties files, secondly so I can read in and combine multiple properties files,

View File

@ -20,20 +20,16 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.windows; package com.shatteredpixel.shatteredpixeldungeon.windows;
import android.content.Intent;
import android.net.Uri;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.input.Touchscreen;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline; import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.TouchArea;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -51,9 +47,9 @@ public class WndLangs extends Window {
public WndLangs(){ public WndLangs(){
super(); super();
final ArrayList<Messages.Languages> langs = new ArrayList<>(Arrays.asList(Messages.Languages.values())); final ArrayList<Languages> langs = new ArrayList<>(Arrays.asList(Languages.values()));
Messages.Languages nativeLang = Messages.Languages.matchLocale(Locale.getDefault()); Languages nativeLang = Languages.matchLocale(Locale.getDefault());
langs.remove(nativeLang); langs.remove(nativeLang);
//move the native language to the top. //move the native language to the top.
langs.add(0, nativeLang); langs.add(0, nativeLang);
@ -104,40 +100,41 @@ public class WndLangs extends Window {
title.hardlight(TITLE_COLOR); title.hardlight(TITLE_COLOR);
add(title); add(title);
RenderedTextMultiline info = PixelScene.renderMultiline( 6 ); if (Messages.lang() == Languages.ENGLISH){
switch(Messages.lang().status()){
case REVIEWED:
info.text(Messages.get(this, "completed"), WIDTH-TEXT_LEFT);
break;
case UNREVIEWED:
info.text(Messages.get(this, "unreviewed"), WIDTH-TEXT_LEFT);
break;
case INCOMPLETE:
info.text(Messages.get(this, "unfinished"), WIDTH-TEXT_LEFT);
break;
}
info.setPos(TEXT_LEFT, title.height() + 2);
add(info);
RedButton creditsBtn = new RedButton(Messages.titleCase(Messages.get(this, "credits"))); RenderedTextMultiline info = PixelScene.renderMultiline(6);
creditsBtn.setSize(creditsBtn.reqWidth()+2, 16); info.text("This is the source language, written by the developer.", WIDTH - TEXT_LEFT);
creditsBtn.setPos(TEXT_LEFT + (TEXT_WIDTH - creditsBtn.width())/2f, y - 18); info.setPos(TEXT_LEFT, title.height() + 2);
add(creditsBtn); add(info);
RenderedTextMultiline transifex_text = PixelScene.renderMultiline(6); } else {
transifex_text.text(Messages.get(this, "transifex"), WIDTH-TEXT_LEFT);
transifex_text.setPos(TEXT_LEFT, creditsBtn.top() - 2 - transifex_text.height());
add(transifex_text);
TouchArea transifex_link = new TouchArea(transifex_text.left(), transifex_text.top(), RenderedTextMultiline info = PixelScene.renderMultiline(6);
transifex_text.width(), transifex_text.height()){ switch (Messages.lang().status()) {
@Override case REVIEWED:
protected void onClick(Touchscreen.Touch touch) { info.text(Messages.get(this, "completed"), WIDTH - TEXT_LEFT);
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "http://www.transifex.com/shattered-pixel/shattered-pixel-dungeon/" ) ); break;
Game.instance.startActivity( intent ); case UNREVIEWED:
info.text(Messages.get(this, "unreviewed"), WIDTH - TEXT_LEFT);
break;
case INCOMPLETE:
info.text(Messages.get(this, "unfinished"), WIDTH - TEXT_LEFT);
break;
} }
}; info.setPos(TEXT_LEFT, title.height() + 2);
add(transifex_link); add(info);
RedButton creditsBtn = new RedButton(Messages.titleCase(Messages.get(this, "credits")));
creditsBtn.setSize(creditsBtn.reqWidth() + 2, 16);
creditsBtn.setPos(TEXT_LEFT + (TEXT_WIDTH - creditsBtn.width()) / 2f, y - 18);
add(creditsBtn);
RenderedTextMultiline transifex_text = PixelScene.renderMultiline(6);
transifex_text.text(Messages.get(this, "transifex"), WIDTH - TEXT_LEFT);
transifex_text.setPos(TEXT_LEFT, creditsBtn.top() - 2 - transifex_text.height());
add(transifex_text);
}
} }