Magnolia 6.0 reached end of life on June 26, 2019. This branch is no longer supported, see End-of-life policy.
Do NOT instantiate SimpleTranslator
but inject it in the constructor.
import info.magnolia.i18nsystem.SimpleTranslator; import com.vaadin.ui.Button; import javax.inject.Inject; public class MyClass { private final SimpleTranslator i18n; @Inject public MyClass(SimpleTranslator i18n){ this.i18n = i18n; } public void someMethod(){ // more code here ... Button sendMessageButton = new Button(i18n.translate("messages-app.app.button.sendMessage")); // more code here ... } }
Then pass the key in the #translate(String key).
The key messages-app.app.button.sendMessage
must be in a message file with a value:
messages-app.app.button.sendMessage=Send message