Skip to content

Commit fbcf159

Browse files
committed
Simplify messages to improve the ability to translate
1 parent 6648972 commit fbcf159

File tree

10 files changed

+24
-134
lines changed

10 files changed

+24
-134
lines changed

common/src/main/resources/Operator.properties

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ WLSDO-0001=More than one item under ''spec.managedServers'' in the domain resour
168168
WLSDO-0002=More than one item under ''spec.clusters'' in the domain resource has DNS-1123 name ''{0}''
169169
WLSDO-0003=No volume mount contains path for log home ''{0}''
170170
WLSDO-0004=The mount path ''{0}'', in entry ''{1}'' of domain resource ''additionalVolumeMounts'', is not valid
171-
WLSDO-0005=Environment {0} {1}, specified under ''{2}'', {3} reserved for use by the operator
171+
WLSDO-0005=The following environment variables, specified under ''{0}'', are reserved for use by the operator: ``{1}''
172172
WLSDO-0006=Bad namespace for weblogicCredentialsSecret: ''{0}''. If specified, must be same as domain namespace.
173173
WLSDO-0007=Configuration overridesConfigMap ''{0}'' is not supported if ''domainHomeSourceType'' is configured as ''FromModel''.
174174
WLSDO-0008=ConfigMap ''{0}'' specified by ''{1}'' not found in namespace ''{2}''.
@@ -256,13 +256,6 @@ WLSDO-0065=The OPSS wallet password secret ''{0}'' is specified but the required
256256
WLSDO-0066=Pod ''{0}'' is Unschedulable, reason: ''{1}''
257257
WLSDO-0067=One or more Pods in the domain cannot be scheduled. Please check individual Pod status for details.
258258

259-
oneEnvVar=variable
260-
multipleEnvVars=variables
261-
singularToBe=is
262-
pluralToBe=are
263-
conjunction=and
264-
truncation=more
265-
266259
# Domain event messages
267260

268261
WLSEO-0001=Domain {0} is available: a sufficient number of its servers have reached the ready state.

operator/src/main/java/oracle/kubernetes/operator/DomainStatusUpdater.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator;
@@ -49,7 +49,6 @@
4949
import oracle.kubernetes.operator.wlsconfig.WlsServerConfig;
5050
import oracle.kubernetes.operator.work.Packet;
5151
import oracle.kubernetes.operator.work.Step;
52-
import oracle.kubernetes.utils.OperatorUtils;
5352
import oracle.kubernetes.utils.SystemClock;
5453
import oracle.kubernetes.weblogic.domain.model.ClusterCondition;
5554
import oracle.kubernetes.weblogic.domain.model.ClusterConditionType;
@@ -935,12 +934,15 @@ private DomainCondition createAvailableCondition() {
935934
}
936935

937936
private String formatServers(List<String> servers) {
938-
return OperatorUtils.joinListGrammaticallyWithLimit(SERVER_DISPLAY_LIMIT, servers);
937+
return servers.stream()
938+
.limit(SERVER_DISPLAY_LIMIT)
939+
.collect(Collectors.joining(", "));
939940
}
940941

941942
private String formatClusters(List<ClusterCheck> unavailableClusters) {
942-
return OperatorUtils.joinListGrammaticallyWithLimit(
943-
CLUSTER_MESSAGE_LIMIT, createUnavailableClustersMessage(unavailableClusters));
943+
return createUnavailableClustersMessage(unavailableClusters).stream()
944+
.limit(CLUSTER_MESSAGE_LIMIT)
945+
.collect(Collectors.joining(", "));
944946
}
945947

946948
@Nonnull

operator/src/main/java/oracle/kubernetes/utils/OperatorUtils.java

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.utils;
55

66
import java.io.IOException;
77
import java.io.Reader;
88
import java.lang.reflect.Array;
9-
import java.util.ArrayList;
109
import java.util.Collections;
1110
import java.util.Comparator;
1211
import java.util.LinkedHashMap;
13-
import java.util.List;
1412
import java.util.Map;
1513
import java.util.Map.Entry;
16-
import java.util.ResourceBundle;
1714
import java.util.stream.Collectors;
18-
import javax.annotation.Nonnull;
1915

2016
public class OperatorUtils {
2117

@@ -26,47 +22,6 @@ private OperatorUtils() {
2622
// 2K chars (4K bytes)
2723
private static final int DEFAULT_BUF_SIZE = 0x800;
2824

29-
/**
30-
* Converts a list of strings to a comma-separated list, using "and" for the last item.
31-
*
32-
* @param list the list to convert
33-
* @return the resultant string
34-
*/
35-
public static String joinListGrammatically(final List<String> list) {
36-
return list.size() > 1
37-
? String.join(", ", list.subList(0, list.size() - 1))
38-
.concat(getFinalSeparator(list) + " " + getBundleString("conjunction") + " ")
39-
.concat(list.get(list.size() - 1))
40-
: list.get(0);
41-
}
42-
43-
@Nonnull
44-
private static String getFinalSeparator(List<String> list) {
45-
return list.size() > 2 ? "," : "";
46-
}
47-
48-
private static String getBundleString(String key) {
49-
return ResourceBundle.getBundle("Operator").getString(key);
50-
}
51-
52-
/**
53-
* Converts a list of strings to a comma-separated list, using "and" for the last item. If the list
54-
* is longer than the specified limit, truncates the list and follows up with the number of remaining elements.
55-
*
56-
* @param list the list to convert
57-
* @return the resultant string
58-
*/
59-
public static String joinListGrammaticallyWithLimit(int limit, final List<String> list) {
60-
if (list.size() <= limit) {
61-
return joinListGrammatically(list);
62-
} else {
63-
final int excess = Math.min(2, list.size() - limit);
64-
final List<String> truncated = new ArrayList<>(list.subList(0, list.size() - excess));
65-
truncated.add(excess + " " + getBundleString("truncation"));
66-
return joinListGrammatically(truncated);
67-
}
68-
}
69-
7025
/**
7126
* Create a Map using the elements from the given map, with their keys sorted
7227
* using the sorted name as returned by {@link #getSortingString(String)}.

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/DomainValidationMessages.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.weblogic.domain.model;
55

6-
import java.text.ChoiceFormat;
7-
import java.text.Format;
86
import java.text.MessageFormat;
97
import java.util.Arrays;
108
import java.util.List;
@@ -14,7 +12,6 @@
1412
import io.kubernetes.client.openapi.models.V1VolumeMount;
1513
import oracle.kubernetes.common.logging.MessageKeys;
1614
import oracle.kubernetes.operator.helpers.SecretType;
17-
import oracle.kubernetes.utils.OperatorUtils;
1815

1916
import static oracle.kubernetes.operator.helpers.LegalNames.LEGAL_CONTAINER_PORT_NAME_MAX_LENGTH;
2017
import static oracle.kubernetes.weblogic.domain.model.Model.DEFAULT_AUXILIARY_IMAGE_MOUNT_PATH;
@@ -87,24 +84,8 @@ private static String getBundleString(String key) {
8784
}
8885

8986
static String reservedVariableNames(String prefix, List<String> reservedNames) {
90-
MessageFormat formatter = new MessageFormat("");
91-
formatter.applyPattern(getBundleString(MessageKeys.RESERVED_ENVIRONMENT_VARIABLES));
92-
formatter.setFormats(new Format[]{getEnvNoun(), null, null, getToBe()});
93-
return formatter.format(new Object[] {
94-
reservedNames.size(),
95-
OperatorUtils.joinListGrammatically(reservedNames),
96-
prefix + ".serverPod.env",
97-
reservedNames.size()});
98-
}
99-
100-
private static ChoiceFormat getEnvNoun() {
101-
return new ChoiceFormat(new double[] {1, 2},
102-
new String[] {getBundleString("oneEnvVar"), getBundleString("multipleEnvVars")});
103-
}
104-
105-
private static ChoiceFormat getToBe() {
106-
return new ChoiceFormat(new double[] {1, 2},
107-
new String[] {getBundleString("singularToBe"), getBundleString("pluralToBe")});
87+
return getMessage(MessageKeys.RESERVED_ENVIRONMENT_VARIABLES,
88+
prefix + ".serverPod.env", String.join(", ", reservedNames));
10889
}
10990

11091
public static String noSuchSecret(String secretName, String namespace, SecretType type) {

operator/src/test/java/oracle/kubernetes/operator/DomainStatusMatcher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import java.util.Arrays;
77
import java.util.Collections;
88
import java.util.List;
9+
import java.util.stream.Collectors;
910
import javax.annotation.Nonnull;
1011

1112
import oracle.kubernetes.weblogic.domain.model.DomainFailureReason;
1213
import oracle.kubernetes.weblogic.domain.model.DomainResource;
1314
import org.hamcrest.Description;
1415
import org.hamcrest.TypeSafeDiagnosingMatcher;
1516

16-
import static oracle.kubernetes.utils.OperatorUtils.joinListGrammatically;
1717
import static org.apache.commons.lang3.StringUtils.isEmpty;
1818

1919
@SuppressWarnings("unused")
@@ -113,7 +113,9 @@ public void describeTo(Description description) {
113113
}
114114

115115
private String joinListGrammaticallyWithQuotes(List<String> strings) {
116-
return joinListGrammatically(strings.stream().map(this::quote).toList());
116+
return strings.stream()
117+
.map(this::quote)
118+
.collect(Collectors.joining(", "));
117119
}
118120

119121
private String quote(String s) {

operator/src/test/java/oracle/kubernetes/operator/EventMatcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.hamcrest.TypeSafeDiagnosingMatcher;
1919

2020
import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.EVENT;
21-
import static oracle.kubernetes.utils.OperatorUtils.joinListGrammatically;
2221

2322
public class EventMatcher extends TypeSafeDiagnosingMatcher<KubernetesTestSupport> {
2423

@@ -80,7 +79,7 @@ private String toEventString(EventsV1Event event) {
8079
if (expectedCount != null) {
8180
descriptions.add("count <" + getCount(event) + '>');
8281
}
83-
return "with " + joinListGrammatically(descriptions);
82+
return "with " + String.join(", ", descriptions);
8483
}
8584

8685
private int getCount(EventsV1Event event) {

operator/src/test/java/oracle/kubernetes/weblogic/domain/model/DomainStatusConditionMatcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Optional;
1010
import javax.annotation.Nonnull;
1111

12-
import oracle.kubernetes.utils.OperatorUtils;
1312
import org.hamcrest.Description;
1413
import org.hamcrest.TypeSafeDiagnosingMatcher;
1514

@@ -121,7 +120,7 @@ void describeTo(Description description, String commentPrefix) {
121120
}
122121
description
123122
.appendText(commentPrefix)
124-
.appendText(OperatorUtils.joinListGrammatically(expectations));
123+
.appendText(String.join(", ", expectations));
125124
}
126125

127126
private String expectation(String description, String value) {

operator/src/test/java/oracle/kubernetes/weblogic/domain/model/DomainStatusNoConditionMatcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Optional;
99
import javax.annotation.Nonnull;
1010

11-
import oracle.kubernetes.utils.OperatorUtils;
1211
import org.hamcrest.Description;
1312
import org.hamcrest.TypeSafeDiagnosingMatcher;
1413

@@ -79,7 +78,7 @@ void describeTo(Description description, String commentPrefix) {
7978
}
8079
description
8180
.appendText(commentPrefix)
82-
.appendText(OperatorUtils.joinListGrammatically(expectations));
81+
.appendText(String.join(", ", expectations));
8382
}
8483

8584
private String expectation(String description, String value) {

operator/src/test/java/oracle/kubernetes/weblogic/domain/model/DomainValidationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ void whenReservedEnvironmentVariablesSpecifiedAtDomainLevel_reportError() {
477477
.withEnvironmentVariable("INTROSPECT_HOME", "/shared/home/introspection");
478478

479479
assertThat(domain.getValidationFailures(resourceLookup).failures(),
480-
contains(stringContainsInOrder("variables", "ADMIN_NAME", "INTROSPECT_HOME", "spec.serverPod.env", "are")));
480+
contains(stringContainsInOrder("spec.serverPod.env", "ADMIN_NAME", "INTROSPECT_HOME")));
481481
}
482482

483483
@Test
@@ -489,7 +489,7 @@ void whenReservedEnvironmentVariablesSpecifiedForAdminServer_reportError() {
489489

490490
assertThat(domain.getValidationFailures(resourceLookup).failures(),
491491
contains(
492-
stringContainsInOrder("variables", "LOG_HOME", "NAMESPACE", "spec.adminServer.serverPod.env", "are")));
492+
stringContainsInOrder("spec.adminServer.serverPod.env", "LOG_HOME", "NAMESPACE")));
493493
}
494494

495495
@Test
@@ -499,7 +499,7 @@ void whenReservedEnvironmentVariablesSpecifiedAtServerLevel_reportError() {
499499
.withEnvironmentVariable("SERVER_NAME", "testValue");
500500

501501
assertThat(domain.getValidationFailures(resourceLookup).failures(),
502-
contains(stringContainsInOrder("variable", "SERVER_NAME", "spec.managedServers[ms1].serverPod.env", "is")));
502+
contains(stringContainsInOrder("spec.managedServers[ms1].serverPod.env", "SERVER_NAME")));
503503
}
504504

505505
@Test
@@ -511,7 +511,7 @@ void whenReservedEnvironmentVariablesSpecifiedAtClusterLevel_reportError() {
511511
info.getReferencedClusters().forEach(resourceLookup::defineResource);
512512

513513
assertThat(domain.getValidationFailures(resourceLookup).failures(),
514-
contains(stringContainsInOrder("variable", "DOMAIN_HOME", "spec.clusters[cluster1].serverPod.env", "is")));
514+
contains(stringContainsInOrder("spec.clusters[cluster1].serverPod.env", "DOMAIN_HOME")));
515515
}
516516

517517
@Test
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.weblogic.domain.model;
55

66
import java.util.HashMap;
7-
import java.util.List;
87
import java.util.Map;
98

109
import org.junit.jupiter.api.Test;
1110

1211
import static oracle.kubernetes.utils.OperatorUtils.compareSortingStrings;
1312
import static oracle.kubernetes.utils.OperatorUtils.createSortedMap;
14-
import static oracle.kubernetes.utils.OperatorUtils.joinListGrammatically;
15-
import static oracle.kubernetes.utils.OperatorUtils.joinListGrammaticallyWithLimit;
1613
import static org.hamcrest.MatcherAssert.assertThat;
1714
import static org.hamcrest.Matchers.anEmptyMap;
1815
import static org.hamcrest.Matchers.contains;
19-
import static org.hamcrest.Matchers.equalTo;
2016
import static org.hamcrest.Matchers.lessThan;
2117

2218
class OperatorUtilsTest {
@@ -46,40 +42,4 @@ void verifyThatCreateSortedMap_returnsSortedMap() {
4642
assertThat(createSortedMap(map).keySet(), contains("server1", "server2", "server10"));
4743
assertThat(createSortedMap(map).values(), contains("server1-value", "server2-value", "server10-value"));
4844
}
49-
50-
@Test
51-
void grammaticallySortedListWithOneElement_containsOnlyThatElement() {
52-
assertThat(joinListGrammatically(List.of("one")), equalTo("one"));
53-
}
54-
55-
@Test
56-
void grammaticallySortedListWithTwoElements_separatesThemWithAnd() {
57-
assertThat(joinListGrammatically(List.of("one", "two")), equalTo("one and two"));
58-
}
59-
60-
@Test
61-
void grammaticallySortedListWithThreeElements_useOxfordComma() {
62-
assertThat(joinListGrammatically(List.of("one", "two", "three")), equalTo("one, two, and three"));
63-
}
64-
65-
@Test
66-
void limitedGrammaticallySortedListWithOneElement_containsOnlyThatElement() {
67-
assertThat(joinListGrammaticallyWithLimit(5, List.of("one")), equalTo("one"));
68-
}
69-
70-
@Test
71-
void limitedGrammaticallySortedListWithTwoElements_separatesThemWithAnd() {
72-
assertThat(joinListGrammaticallyWithLimit(5, List.of("one", "two")), equalTo("one and two"));
73-
}
74-
75-
@Test
76-
void limitedGrammaticallySortedListWithThreeElements_useOxfordComma() {
77-
assertThat(joinListGrammaticallyWithLimit(5, List.of("one", "two", "three")), equalTo("one, two, and three"));
78-
}
79-
80-
@Test
81-
void limitedGrammaticallySortedListMoreElementsThanLimit_truncatesTheResult() {
82-
assertThat(joinListGrammaticallyWithLimit(5, List.of("one", "two", "three", "four", "five", "six", "seven")),
83-
equalTo("one, two, three, four, five, and 2 more"));
84-
}
8545
}

0 commit comments

Comments
 (0)