@@ -66,11 +66,18 @@ public class ContentGenerator implements SubscriptionGenerator<IndexableObject>
6666 @ Autowired
6767 private ItemService itemService ;
6868
69- private static final String NEW_ITEMS_LABEL = "New Items" ;
70- private static final String MODIFIED_ITEMS_LABEL = "Modified Items" ;
7169 private static final int MAX_METADATA_VALUES = 3 ;
72- private static final String COMMUNITY_NOTE_PREFIX = " (via community subscription to \" " ;
73- private static final String COMMUNITY_NOTE_SUFFIX = "\" )" ;
70+ private static final String NEW_ITEMS_LABEL_KEY = "org.dspace.subscriptions.ContentGenerator.new-items-label" ;
71+ private static final String MODIFIED_ITEMS_LABEL_KEY =
72+ "org.dspace.subscriptions.ContentGenerator.modified-items-label" ;
73+ private static final String INTRO_NEW_AND_MODIFIED_KEY =
74+ "org.dspace.subscriptions.ContentGenerator.intro.new-and-modified" ;
75+ private static final String INTRO_NEW_KEY = "org.dspace.subscriptions.ContentGenerator.intro.new" ;
76+ private static final String INTRO_MODIFIED_KEY = "org.dspace.subscriptions.ContentGenerator.intro.modified" ;
77+ private static final String COMMUNITY_NOTE_PREFIX_KEY =
78+ "org.dspace.subscriptions.ContentGenerator.community-note-prefix" ;
79+ private static final String COMMUNITY_NOTE_SUFFIX_KEY =
80+ "org.dspace.subscriptions.ContentGenerator.community-note-suffix" ;
7481 private static final String LINE_SEPARATOR = System .lineSeparator ();
7582
7683 private static <T > Predicate <T > distinctByKey (Function <? super T , ?> keyExtractor ) {
@@ -109,9 +116,9 @@ public void notifyForSubscriptions(Context context, EPerson ePerson,
109116 Map <Collection , List <IndexableObject >> modifiedItemsByCollection = partitionedItems .get (false ).stream ()
110117 .collect (groupingBy (obj -> ((Item ) obj .getIndexedObject ()).getOwningCollection ()));
111118
112- String intro = buildIntro (newItemsByCollection , modifiedItemsByCollection );
119+ String intro = buildIntro (newItemsByCollection , modifiedItemsByCollection , supportedLocale );
113120 String combinedSection = buildCombinedSection (newItemsByCollection , modifiedItemsByCollection ,
114- collectionToCommunityNameMap );
121+ collectionToCommunityNameMap , supportedLocale );
115122
116123 if (combinedSection .equals (EMPTY )) {
117124 log .debug ("subscription(s) of eperson {} do(es) not match any new or modified items: " +
@@ -158,21 +165,23 @@ private boolean isNewItem(Item item) {
158165 }
159166
160167 private String buildIntro (Map <Collection , List <IndexableObject >> newItems ,
161- Map <Collection , List <IndexableObject >> modifiedItems ) {
168+ Map <Collection , List <IndexableObject >> modifiedItems ,
169+ Locale locale ) {
162170 if (!newItems .isEmpty () && !modifiedItems .isEmpty ()) {
163- return "New and modified items are available in the collections you have subscribed to:" ;
171+ return I18nUtil . getMessage ( INTRO_NEW_AND_MODIFIED_KEY , locale ) ;
164172 } else if (!newItems .isEmpty ()) {
165- return "New items are available in the collections you have subscribed to:" ;
173+ return I18nUtil . getMessage ( INTRO_NEW_KEY , locale ) ;
166174 } else if (!modifiedItems .isEmpty ()) {
167- return "Modified items are available in the collections you have subscribed to:" ;
175+ return I18nUtil . getMessage ( INTRO_MODIFIED_KEY , locale ) ;
168176 } else {
169177 return "" ;
170178 }
171179 }
172180
173181 private String buildCombinedSection (Map <Collection , List <IndexableObject >> newItemsByCollection ,
174182 Map <Collection , List <IndexableObject >> modifiedItemsByCollection ,
175- Map <Collection , String > collectionToCommunity ) {
183+ Map <Collection , String > collectionToCommunity ,
184+ Locale locale ) {
176185 if (newItemsByCollection .isEmpty () && modifiedItemsByCollection .isEmpty ()) {
177186 return EMPTY ;
178187 }
@@ -183,29 +192,33 @@ private String buildCombinedSection(Map<Collection, List<IndexableObject>> newIt
183192 allCollections .addAll (modifiedItemsByCollection .keySet ());
184193
185194 for (Collection collection : allCollections ) {
186- String header = buildCollectionHeader (collection , collectionToCommunity );
195+ String header = buildCollectionHeader (collection , collectionToCommunity , locale );
187196 sb .append (header );
188197
189198 List <IndexableObject > newItems = newItemsByCollection .get (collection );
190199 List <IndexableObject > modifiedItems = modifiedItemsByCollection .get (collection );
191200 if (newItems != null && !newItems .isEmpty ()) {
192- sb .append (buildSectionHeader (NEW_ITEMS_LABEL , newItems .size ()));
201+ sb .append (buildSectionHeader (I18nUtil . getMessage ( NEW_ITEMS_LABEL_KEY , locale ) , newItems .size ()));
193202 sb .append (buildItemsBlock (newItems ));
194203 }
195204 if (modifiedItems != null && !modifiedItems .isEmpty ()) {
196- sb .append (buildSectionHeader (MODIFIED_ITEMS_LABEL , modifiedItems .size ()));
205+ sb .append (buildSectionHeader (I18nUtil .getMessage (MODIFIED_ITEMS_LABEL_KEY , locale ),
206+ modifiedItems .size ()));
197207 sb .append (buildItemsBlock (modifiedItems ));
198208 }
199209 sb .append (LINE_SEPARATOR );
200210 }
201211 return sb .toString ();
202212 }
203213
204- private String buildCollectionHeader (Collection collection , Map <Collection , String > collectionToCommunity ) {
214+ private String buildCollectionHeader (Collection collection , Map <Collection , String > collectionToCommunity ,
215+ Locale locale ) {
205216 String name = collection .getName ();
206217 String communityNote = "" ;
207218 if (collectionToCommunity != null && collectionToCommunity .containsKey (collection )) {
208- communityNote = COMMUNITY_NOTE_PREFIX + collectionToCommunity .get (collection ) + COMMUNITY_NOTE_SUFFIX ;
219+ communityNote = I18nUtil .getMessage (COMMUNITY_NOTE_PREFIX_KEY , locale )
220+ + collectionToCommunity .get (collection )
221+ + I18nUtil .getMessage (COMMUNITY_NOTE_SUFFIX_KEY , locale );
209222 }
210223 String fullHeader = name + communityNote + ":" + LINE_SEPARATOR ;
211224 String underline = "-" .repeat (Math .max (0 , name .length () + communityNote .length ())) + LINE_SEPARATOR ;
0 commit comments