-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageSourceConfig.java
More file actions
59 lines (53 loc) · 2.41 KB
/
Copy pathMessageSourceConfig.java
File metadata and controls
59 lines (53 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package dev.escalated.config;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import java.nio.charset.StandardCharsets;
/**
* Wires the helpdesk's {@link MessageSource} so translation strings come from
* the central <code>dev.escalated:escalated-locale</code> Maven artifact, with
* an optional local override layer.
*
* <p>Resolution order (first match wins):
* <ol>
* <li><code>classpath:i18n/overrides/messages</code> -- host-app overrides
* checked into <code>src/main/resources/i18n/overrides/</code>.</li>
* <li><code>classpath:META-INF/escalated/locale/messages</code> -- shipped by
* the central <code>escalated-locale</code> artifact.</li>
* </ol>
*
* <p>The central artifact is assumed to package its bundles under
* <code>META-INF/escalated/locale/messages_{locale}.properties</code>. This
* mirrors the convention used by other Escalated host plugins and avoids
* collisions with the host app's own <code>messages.properties</code>.
*/
@Configuration
public class MessageSourceConfig {
/**
* Central artifact basename. The artifact ships its bundles at
* <code>META-INF/escalated/locale/messages_{locale}.properties</code>.
*/
private static final String CENTRAL_BASENAME =
"classpath:META-INF/escalated/locale/messages";
/**
* Local override basename. Drop a <code>messages_{locale}.properties</code>
* file under <code>src/main/resources/i18n/overrides/</code> in the host
* app to override individual keys without forking the central artifact.
*/
private static final String OVERRIDE_BASENAME =
"classpath:i18n/overrides/messages";
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource source =
new ReloadableResourceBundleMessageSource();
// Order matters: overrides resolved before the central bundle.
source.setBasenames(OVERRIDE_BASENAME, CENTRAL_BASENAME);
source.setDefaultEncoding(StandardCharsets.UTF_8.name());
source.setFallbackToSystemLocale(false);
// Cache forever; translations are immutable jar resources.
source.setCacheSeconds(-1);
source.setUseCodeAsDefaultMessage(true);
return source;
}
}