April 9, 2020
Estimated Post Reading Time ~

i18n Sling Models Injector

Purpose
Allows for Sling Models classes and interfaces to be injected with I18n objects and/or values.

Injections are available when adapting either a Resource or SlingHttpServletRequest object. Note: Out of performance reasons, only the I18n can be injected using the generic @Inject. The String values need to be annotated with @I18N.

Example
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {

@I18N
private I18n i18n;

@I18N("com.adobe.i18n.backButtonText")
private String backButtonText

@PostConstruct
public void init(){
String text = i18n.get("com.adobe.i18n.backButtonText");
//do something
}

public String getBackButtonText() {
return backButtonText;
}
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.