TranslationAPI
1.1Powerfull inline text translator for multilingual java projects. (With editor)
This TranslatorAPI is inspired by the QtLinguist. Write your translation once inside your code, and translate it on the fly.
Features:
- Text-to-text translation
- Use the player local (from the client) as language key
- MadLinguist translator editor (used to scan your source and generate a dictionary.xml)
- One plugin for all messages from several plugins using this API
- Messages can be configured by the user by placing dictionary.xml files in the plugin directory.
- Can be used for GUI, messages and any other String
- Open source + maven repository
Overview, Wiki and other stuff
Important Hint (look at the "Hint" section)
Commands:
- /translator local - no permission needed
- Prints your current selected language in Minecraft.
- /translator info - (translator.info)
- Lists information about the current dictionary
- /translator languages - (translator.info)
- Prints all present languages
- /translator getlang - (translator.info)
- Gets the Languge name for a language key
For every command an help page is available. Just use " -h" behind the desired command.
How to use:
Some examples
Dictionary
- The Dictionary can be accessed within the Translation class
- Usually the Translator class is used for everything
Dictionary dict = Translator.getDictionary();
//Register translations and languages stored in a xml file
dict.registerDictionaryFile(new DictionaryFile(fileInStream) );
//Bukkit Hint: Use .getResource("dictionary.xml") inside your JavaPlugin class to get the input stream! (assuming you have dictionary.xml in your resources)Translation
- "##" is used as a placeholder for arguments.
- ArgumentConverter can be added to translate a object into a string
- All Translations are stored within a OriginalText object that also contains the used text in your sources.
- The MadLinguist editor scans selected files for all tr(..) method calls
- Use LanguageResolver.lang(Player) to get the language key of a player
static import de.maddevs.translator.api.Translator.tr;
Language lang = Translator.getLanguage("en"); //"en" is registered as default
Player player = Bukkit.getPlayerExact("Drayke"); //A Bukkit example, we assume player is != null
String s1 = tr(lang,"Test translation for player ##",player);
//Because of some problems with overloading you need to parse the language parameter as null if you want to use the default language and arguments
String s2 = tr(null,"Test translation for ##","this");
//And now one example with the selected client language of the player
String s3 = tr(LanguageResolver.lang(player),"The language of the minecraft client from the player");ArgumentConverter
- IArgumentConverter interfaces are used to convert objects to a string
- They need to be registered with the Translator
public class PersonConverter implements IArgumentConverter<Person>
{
@Override
public String convert(Person person)
{
return person.getName(); //Assuming Person to be a class with a "String name" field
}
@Override
public Person getType()
{
return Person.class;
}
}
//Converter for a certain type can just be added once
Translator.registerConverter(Person.class,new PersonConverter());
//Using the argument converter
Person person = new Person("Peter");
Translator.tr(lang,"Person: ##!",person);
//Would now return: "Person: Peter!"Dependencies:
- Used to create commands just with Java Annotations
ToDo:
- any ideas?
Please feel free to ask for improvements! I would be glad to help! Also message me when some of your plugins starts using my API, I will make a list :)
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta