Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.18.1
# Mod Properties
mod_version=0.0.10
mod_version=0.1.0
maven_group=io.github.pixelstudios-dev
archives_base_name=PixelStudiosCore
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.pixelstudios.pixelstudioscore.api.lang;

import java.util.HashMap;
import java.util.Map;

public class LanguageFactory {

private final String key;

private final Map<String, String> translations = new HashMap<>();

private LanguageFactory(String key) {

this.key = key;

}

public static LanguageFactory create(String key) {

return new LanguageFactory(key);

}

public LanguageFactory spanish(String text) {

return custom(LanguageManager.Languages.SPANISH.getLang(), text);

}

public LanguageFactory english(String text) {

return custom(LanguageManager.Languages.ENGLISH.getLang(), text);

}

/**
* Sirve para agregar una clave personalizada compatible con cualquier idioma.
* Ejemplo:
* <pre>{@code
* LanguageFactory.create("item.sword.name")
* .spanish("Espada")
* .english("Sword")
* .custom("fr_fr", "Épée") // Francés
* .custom("pt_br", "Espada") // Portugués
* .custom("ru_ru", "Меч") // Ruso
* .build();
* }</pre>
*
* @param langCode El código del idioma (ej. "fr_fr").
* @param text El texto traducido.
* @return Esta instancia de LanguageFactory.
*/
public LanguageFactory custom(String langCode, String text) {

if (text != null)
this.translations.put(langCode, text);

return this;

}

public void build() {

translations.forEach((langCode, text) -> LanguageManager.addRawTranslation(key, text, langCode));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ public static void addTranslation(String category, String id, String translation

}

public static void addTranslation(String category, String id, String translation, String langCode) {

translationMap.put(langCode + "#" + category + "." + MOD_ID + "." + id, translation);

}

public static void addRawTranslation(String fullKey, String translation, Languages language) {

translationMap.put(language.getLang() + "#" + fullKey, translation);

}

public static void addRawTranslation(String fullKey, String translation, String langCode) {

translationMap.put(langCode + "#" + fullKey, translation);

}

public static HashMap<String, String> getTranslationMap() {
return translationMap;
}
Expand Down