Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #2391 - Add the option to use i18n labels for content fragment element titles #2493

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

import javax.annotation.PostConstruct;

import com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
Expand Down Expand Up @@ -106,6 +109,10 @@ public class ContentFragmentImpl extends AbstractComponentImpl implements Conten
@Nullable
private String displayMode;

@ValueMapValue(name = ContentFragment.PN_USE_I18N_FOR_ELEMENT_TITLE, injectionStrategy = InjectionStrategy.OPTIONAL)
@Default(booleanValues = false)
private Boolean useI18nForElementTitle;

private DAMContentFragment damContentFragment = new EmptyContentFragment();

@PostConstruct
Expand Down Expand Up @@ -243,6 +250,11 @@ protected ComponentData getComponentData() {
.build();
}

@Override
public boolean useI18nForElementTitle() {
return BooleanUtils.isTrue(useI18nForElementTitle);
}

/**
* Empty placeholder content fragment.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.annotation.PostConstruct;
import javax.jcr.Session;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
Expand Down Expand Up @@ -110,6 +111,10 @@ public class ContentFragmentListImpl extends AbstractComponentImpl implements Co
@Default(values = Predicate.SORT_ASCENDING)
private String sortOrder;

@ValueMapValue(name = ContentFragmentList.PN_USE_I18N_FOR_ELEMENT_TITLE, injectionStrategy = InjectionStrategy.OPTIONAL)
@Default(booleanValues = false)
private Boolean useI18nForElementTitle;

private final List<DAMContentFragment> items = new ArrayList<>();

@PostConstruct
Expand Down Expand Up @@ -209,4 +214,9 @@ public Collection<DAMContentFragment> getListItems() {
public String getExportedType() {
return slingHttpServletRequest.getResource().getResourceType();
}

@Override
public boolean useI18nForElementTitle() {
return BooleanUtils.isTrue(useI18nForElementTitle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public interface ContentFragment extends DAMContentFragment, ContainerExporter,
*/
String PN_DISPLAY_MODE = "displayMode";

/**
* Name of the optional resource property that gives the option to translate the element titles with i18n
*
* @since com.adobe.cq.wcm.core.components.models.contentfragment 1.6.0
*/
String PN_USE_I18N_FOR_ELEMENT_TITLE = "useI18nForElementTitle";

/**
* Returns resource type that is used for the internal responsive grid.
*
Expand Down Expand Up @@ -118,4 +125,15 @@ default String getExportedType() {
default String[] getParagraphs() {
return null;
}

/**
* Use i18n to translate the content fragment title
*
* @return true if i18n can be used to translate the content fragment title
* @since com.adobe.cq.wcm.core.components.models.contentfragment 1.6.0
*/
default boolean useI18nForElementTitle() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public interface ContentFragmentList extends Component {
*/
String PN_SORT_ORDER = "sortOrder";

/**
* Name of the optional resource property that gives the option to translate the element titles with i18n
*
* @since com.adobe.cq.wcm.core.components.models.contentfragment 1.6.0
*/
String PN_USE_I18N_FOR_ELEMENT_TITLE = "useI18nForElementTitle";

/**
* Returns a list of {@link DAMContentFragment content fragments}.
*
Expand All @@ -111,4 +118,14 @@ default Collection<DAMContentFragment> getListItems() {
default String getExportedType() {
return "";
}

/**
* Use i18n to translate the content fragment title
*
* @return true if i18n can be used to translate the content fragment title
* @since com.adobe.cq.wcm.core.components.models.contentfragment 1.6.0
*/
default boolean useI18nForElementTitle() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@Version("1.5.1")
@Version("1.6.0")
package com.adobe.cq.wcm.core.components.models.contentfragment;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
jcr:primaryType="nt:unstructured"
field-path="${requestPathInfo.resourcePath}"/>
</variationName>
<useI18nForElementTitle
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Use i18n labels to translate the content fragment element titles"
name="./useI18nForElementTitle"
value="true"/>
<id
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<sly data-sly-use.fragment="com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment"
data-sly-test="${properties.fragmentPath}" data-sly-use.cfTemplates="templates.html">
<sly data-sly-call="${cfTemplates.contentFragment @ fragment=fragment, fragmentPath=properties.fragmentPath, wcmmode=wcmmode}"></sly>
<sly data-sly-call="${cfTemplates.contentFragment @ fragment=fragment, fragmentPath=properties.fragmentPath, wcmmode=wcmmode, useI18nForElementTitle = fragment.useI18nForElementTitle}"></sly>
</sly>

<sly data-sly-use.template="core/wcm/components/commons/v1/templates.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<template data-sly-template.element="${@ element='The content fragment element'}">
<template data-sly-template.element="${@ element='The content fragment element', useI18nForElementTitle='Use i18n to translate the element titles'}">
<div class="cmp-contentfragment__element cmp-contentfragment__element--${element.name}" data-cmp-contentfragment-element-type="${element.dataType}">
<dt class="cmp-contentfragment__element-title">${element.title}</dt>
<dt class="cmp-contentfragment__element-title" data-sly-test="${!useI18nForElementTitle}">${element.title}</dt>
<dt class="cmp-contentfragment__element-title" data-sly-test="${useI18nForElementTitle}">${element.title @ i18n}</dt>
<dd class="cmp-contentfragment__element-value">
<sly data-sly-test="${element.dataType == 'calendar'}" data-sly-use.tpl="core/wcm/components/contentfragment/v1/contentfragment/calendar.html"
data-sly-call="${tpl.element @ date = element.value}"></sly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->

<template data-sly-template.contentFragment="${@ fragment='The content fragment', fragmentPath='', wcmmode='WCM mode'}">
<template data-sly-template.contentFragment="${@ fragment='The content fragment', fragmentPath='', wcmmode='WCM mode', useI18nForElementTitle='Use i18n to translate the element titles'}">
<article id="${fragment.id}"
class="cmp-contentfragment cmp-contentfragment--${fragment.name}"
data-cmp-contentfragment-model="${fragment.type}"
Expand All @@ -30,7 +30,7 @@ <h3 class="cmp-contentfragment__title">${fragment.title}</h3>
<sly data-sly-call="${paragraphs @ fragment=fragment}"></sly>
</sly>
<sly data-sly-test="${!isParagraphMode}">
<sly data-sly-call="${elements @ fragment=fragment, wcmmode=wcmmode}"></sly>
<sly data-sly-call="${elements @ fragment=fragment, wcmmode=wcmmode, useI18nForElementTitle=useI18nForElementTitle}"></sly>
</sly>
</article>
</template>
Expand All @@ -46,10 +46,10 @@ <h3 class="cmp-contentfragment__title">${fragment.title}</h3>
</div>
</template>

<template data-sly-template.elements="${@ fragment='The content fragment', wcmmode='WCM mode'}">
<template data-sly-template.elements="${@ fragment='The content fragment', wcmmode='WCM mode', useI18nForElementTitle='Use i18n to translate the element title'}">
<dl class="cmp-contentfragment__elements${!wcmmode.disabled ? ' cq-dd-contentfragment' : ''}"
data-sly-list.element="${fragment.elements}"
data-sly-use.elementTemplate="core/wcm/components/contentfragment/v1/contentfragment/element.html">
<sly data-sly-call="${elementTemplate.element @ element=element}"></sly>
<sly data-sly-call="${elementTemplate.element @ element=element, useI18nForElementTitle=useI18nForElementTitle}"></sly>
</dl>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
jcr:primaryType="nt:unstructured"
cmp-field-path="${requestPathInfo.resourcePath}"/>
</elementNames>
<useI18nForElementTitle
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Use i18n labels to translate the content fragment element titles"
name="./useI18nForElementTitle"
value="true"/>
</items>
</column>
</items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<section data-sly-list.fragment="${list.listItems}"
id="${list.id}"
class="cmp-contentfragmentlist">
<sly data-sly-call="${fragmentTemplate.contentFragment @ fragment=fragment, wcmmode=wcmmode}"></sly>
<sly data-sly-call="${fragmentTemplate.contentFragment @ fragment=fragment, wcmmode=wcmmode, useI18nForElementTitle=list.useI18nForElementTitle}"></sly>
</section>
</sly>

Expand Down