Skip to main content
added 346 characters in body
Source Link
KaareZ
  • 1.9k
  • 1
  • 19
  • 31

I would create a directory containing language text files. The directory could look like this:

en.txt

0 "Start game"
1 "Load game"
2 "Enable cannons"
3 "Join server"
4 "Kill the enemy"

fr.txt

 0 "Démarrer le jeu"
 1 "Load game"
 2 "Activer canons"
 3 "Rejoignez serveur"
 4 "Tuer l'ennemi"

de.txt

 0 "Spiel starten"
 1 "Spiel laden"
 2 "Enable Kanonen"
 3 "Join-Server"
 4 "Töte den Feind"

ch.txt

0 "開始遊戲"
1 "載入遊戲"
2 "啟用炮"
3 "加入服務器"
4 "殺死敵人"

Now make hashmap, with the language names as keys, and a String array as object. In each string array you load up the values and they are now ready to use.

A method to get the values. (Pseudo code)

public String getText(String languageCode, int messageId) {
    return languages.get(languageCode).get(messageId);
}

Initialization method (Pseudo code)

HashMap<String, HashMap<Integer, String>> languages;

public init(String directory) {
    for(file; each file in directory) {
        HashMap<Integer, String> languageArray = load file contents and add to array;
        languages.get(languageCode).add(languageArray);
}

This can of course both be implemented on the client side(for less bandwidth) or server side for more customize ability.

I would create a directory containing language text files. The directory could look like this:

en.txt

0 "Start game"
1 "Load game"
2 "Enable cannons"
3 "Join server"
4 "Kill the enemy"

fr.txt

 0 "Démarrer le jeu"
 1 "Load game"
 2 "Activer canons"
 3 "Rejoignez serveur"
 4 "Tuer l'ennemi"

de.txt

 0 "Spiel starten"
 1 "Spiel laden"
 2 "Enable Kanonen"
 3 "Join-Server"
 4 "Töte den Feind"

ch.txt

0 "開始遊戲"
1 "載入遊戲"
2 "啟用炮"
3 "加入服務器"
4 "殺死敵人"

Now make hashmap, with the language names as keys, and a String array as object. In each string array you load up the values and they are now ready to use.

A method to get the values. (Pseudo code)

public String getText(String languageCode, int messageId) {
    return languages.get(languageCode).get(messageId);
}

I would create a directory containing language text files. The directory could look like this:

en.txt

0 "Start game"
1 "Load game"
2 "Enable cannons"
3 "Join server"
4 "Kill the enemy"

fr.txt

 0 "Démarrer le jeu"
 1 "Load game"
 2 "Activer canons"
 3 "Rejoignez serveur"
 4 "Tuer l'ennemi"

de.txt

 0 "Spiel starten"
 1 "Spiel laden"
 2 "Enable Kanonen"
 3 "Join-Server"
 4 "Töte den Feind"

ch.txt

0 "開始遊戲"
1 "載入遊戲"
2 "啟用炮"
3 "加入服務器"
4 "殺死敵人"

Now make hashmap, with the language names as keys, and a String array as object. In each string array you load up the values and they are now ready to use.

A method to get the values. (Pseudo code)

public String getText(String languageCode, int messageId) {
    return languages.get(languageCode).get(messageId);
}

Initialization method (Pseudo code)

HashMap<String, HashMap<Integer, String>> languages;

public init(String directory) {
    for(file; each file in directory) {
        HashMap<Integer, String> languageArray = load file contents and add to array;
        languages.get(languageCode).add(languageArray);
}

This can of course both be implemented on the client side(for less bandwidth) or server side for more customize ability.

Source Link
KaareZ
  • 1.9k
  • 1
  • 19
  • 31

I would create a directory containing language text files. The directory could look like this:

en.txt

0 "Start game"
1 "Load game"
2 "Enable cannons"
3 "Join server"
4 "Kill the enemy"

fr.txt

 0 "Démarrer le jeu"
 1 "Load game"
 2 "Activer canons"
 3 "Rejoignez serveur"
 4 "Tuer l'ennemi"

de.txt

 0 "Spiel starten"
 1 "Spiel laden"
 2 "Enable Kanonen"
 3 "Join-Server"
 4 "Töte den Feind"

ch.txt

0 "開始遊戲"
1 "載入遊戲"
2 "啟用炮"
3 "加入服務器"
4 "殺死敵人"

Now make hashmap, with the language names as keys, and a String array as object. In each string array you load up the values and they are now ready to use.

A method to get the values. (Pseudo code)

public String getText(String languageCode, int messageId) {
    return languages.get(languageCode).get(messageId);
}