1

Currently I'm using an interface for all the needed Strings in my application. I access the interface (called StringConstants) from anywhere in my application. The interface sets all the Strings in Dutch, but know I also want to add a language switching option (to English). What's the trick to change the interface I'm using, or should I just make an interface for each language I'd like to use?

Here's the interface code I currently use:

package constants;

public interface StringConstants {
    //LabyrintUI//
    public String APP_TITLE = "Labyrint";
    public String APP_VERSION = "Versie 1.0";
    public String MENU_TITLE = "Labyrint - Menu";
    public String MOEILIJKHEID1 = "Gemakkelijk";
    public String MOEILIJKHEID2 = "Normaal";
    public String MOEILIJKHEID3 = "Moeilijk";
    public String BTN_SPEEL_TITLE = "Speel";
    public String BTN_OPTIES_TITLE = "Opties";
    public String BTN_STOP_TITLE = "Stop";
    public String BTN_RESET_SCORES_TITLE = "Verwijder de highscores";
    public String BTN_SPELREGELS_TITLE = "Spelregels";
    public String BTN_OVER_TITLE = "Over";
    public String BTN_DEFAULT_SETTINGS_TERUG_ZETTEN_TITLE = "Standaardinstellingen terugzetten";
    public String BTN_OPSLAAN_TITLE = "Opslaan";
    public String LBL_MOEILIJKHEIDSGRAAD_TITLE = "Moeilijkheidsgraad";
    public String LBL_GELUID_TITLE = "Geluid";
    public String LBL_SCORES_TITLE = "Highscores";
    public String LBL_LAST_SCORE_TITLE = "Laatste score";
    public String MI_NIEUWSPEL_TITLE = "Nieuw spel";
    public String MI_NIEUWSPEL_TOOLTIP_TEXT = "Nieuw spel starten";
    public String MI_SPEEL_OF_PAUZE_TITLE_PAUSE = "Pauzeer";
    public String MI_SPEEL_OF_PAUZE_TOOLTIP_TEXT_PAUSE = "Pauzeer het huidig spel";
    public String MI_SPEEL_OF_PAUZE_TITLE_PLAY = "Speel";
    public String MI_SPEEL_OF_PAUZE_TOOLTIP_TEXT_PLAY = "Hervat het huidig spel";
    public String MI_STOPSPEL_TITLE = "Stop";
    public String MI_STOPSPEL_TOOLTIP_TEXT = "Stop het huidig spel";
    public String MI_GELUID_TITLE_OFF = "Geluid uit";
    public String MI_GELUID_TOOLTIP_TEXT_OFF = "Zet geluid uit";
    public String MI_GELUID_TITLE_ON = "Geluid aan";
    public String MI_GELUID_TOOLTIP_TEXT_ON = "Zet geluid aan";

    //BORD//
    public String VAK_BEGIN_VALUE = "BEGIN";
    public String VAK_LEEG_VALUE = "LEEG";
    public String VAK_MUUR_VALUE = "MUUR";
    public String VAK_LAVA_VALUE = "LAVA";
    public String VAK_DOORGANG_VALUE = "DOORGANG";
    public String VAK_EINDE_VALUE = "EINDE";

    //LINKERPANEEL//
    public String HIGHSCORE_NOT_FOUND_TEXT = "Nog geen highscore gevonden...";

    //DIALOGS//
    public String ABOUT_DIALOG_CONTENT = APP_TITLE + " is een app gemaakt door Vincent Devaux en Thibault Helsmoortel.";
    public String NIEUW_SPEL_DIALOG_TITLE = APP_TITLE + " - Nieuw spel";
    public String NIEUW_SPEL_DIALOG_CONTENT = "Weet u zeker dat u uw huidig spel wilt stoppen om een nieuw spel te beginnen?";
    public String STOP_SPEL_DIALOG_TITLE = APP_TITLE + " - Spel stoppen";
    public String STOP_DPEL_DIALOG_CONTENT = "Weet u zeker dat u uw huidig spel wilt stoppen?";
    public String SLUIT_APP_DIALOG_TITLE = APP_TITLE + " - Labyrint sluiten";
    public String SLUIT_APP_DIALOG_CONTENT = "Weet u zeker dat u het spel wilt verlaten?";
    public String SPELREGELS_DIALOG_TITLE = APP_TITLE + " - Spelregels";
    public String SPELREGELS_DIALOG_CONTENT = "Spelregels:" + "\n";
    public String SPELREGELS = "Doel van het spel: geraak met je speler zo snel mogelijk aan het einde." +
            "\n-Gebruik de doorgangen om je sneller door het labyrint te verplaatsen." +
            "\n-Zorg ervoor dat het spook je niet vangt." +
            "\n-Daag een vriend uit en verbeter zijn tijd.";
    public String BTN_JA_TITLE = "Ja";
    public String BTN_ANNULEREN_TITLE = "Annuleren";
    public String BTN_OK_TITLE = "Ok";
    public String VRAAG_SPELERNAAM_TITLE = APP_TITLE + " - Naam invoeren";
    public String VRAAG_SPELERNAAM_TIJD = "Je eindigde in ";
    public String VRAAG_SPELERNAAM_NAAM = "\nVul je naam in:";
    public String FOUTMELDING_LEZEN_SCORES = "Er is een fout opgetreden bij het lezen van de scores. ";
    public String FOUTMELDING_SCHRIJVEN_SCORES = "Er is een fout opgetreden bij het schrijven van de scores. ";
    public String GAME_OVER_DIALOG = "Game over!";
    public String SCORES_VERWIJDEREN_DIALOG_TITLE = APP_TITLE + " - Scores verwijderen";
    public String SCORES_VERWIJDEREN_DIALOG_CONTENT = "Weet je zeker dat je alle scores wilt verwijderen?\nAlle scores zullen verwijdert worden!";

    //PROPERTIES//
    public String INITIAL_USER_NAME = System.getProperty("user.name");
    public String FILE_SEPARATOR = System.getProperty("file.separator");
    public String LINE_SEPARATOR = System.getProperty("line.separator");
    public String KEYBOARD_FORMAT = System.getProperty("user.country.format");
    public String CUSTOM_PROPS_HEADLINE = "Customsettings";
    public String PROP_MOEILIJKHEIDSGRAAD = "moeilijkheidsgraad";
    public String PROP_GELUID = "geluid";
    public String SCORES_MAKKELIJK_HEADLINE = "Scores Makkelijk";
    public String SCORES_NORMAAL_HEADLINE = "Scores Normaal";
    public String SCORES_MOEILIJK_HEADLINE = "Scores Moeilijk";

    //ANDERE//
    public String FILE_DEFAULT_SETTINGS_PATH = "src" + FILE_SEPARATOR + "bestanden" + FILE_SEPARATOR + "settings" + FILE_SEPARATOR + "default.ini";
    public String FILE_CUSTOM_SETTINGS_PATH = "src" + FILE_SEPARATOR + "bestanden" + FILE_SEPARATOR + "settings" + FILE_SEPARATOR + "custom.ini";
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Thibstars
  • 1,085
  • 1
  • 9
  • 30
  • 6
    Use a ResourceBundle. You're using the contant interface anti-pattern. These fields are public static final strings, i.e. constants. They can't be overridden. As for almost everything in Java, there is a tutorial about internationalization: http://docs.oracle.com/javase/tutorial/i18n/ – JB Nizet Mar 10 '14 at 18:38
  • Hmm, if you use a ResourceBundle you need a locale too if I got it right. Is it a problem that there is no standard locale for the Dutch language? – Thibstars Mar 10 '14 at 18:56
  • No, it's not. Just use `new Locale("nl")` – JB Nizet Mar 10 '14 at 19:29

2 Answers2

3

Use ResourceBundle and *.properties files for each language.

DmitryKanunnikoff
  • 2,226
  • 2
  • 22
  • 35
0

Please check below post this might be useful for you.

Convert String to another locale in java

But better way to Use i18n is to use property files with ResourseBoundle class.

Thanks Satya

Community
  • 1
  • 1
satyam.kudikala
  • 101
  • 1
  • 1
  • 5