mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
Refs #1710 Cut all except language from Locale when searching for messages
This commit is contained in:
parent
0a5cc23b77
commit
9777444367
@ -8,6 +8,7 @@ package com.haulmont.cuba.client.sys;
|
|||||||
|
|
||||||
import com.haulmont.cuba.client.ClientConfig;
|
import com.haulmont.cuba.client.ClientConfig;
|
||||||
import com.haulmont.cuba.core.app.LocalizedMessageService;
|
import com.haulmont.cuba.core.app.LocalizedMessageService;
|
||||||
|
import com.haulmont.cuba.core.global.Configuration;
|
||||||
import com.haulmont.cuba.core.global.Messages;
|
import com.haulmont.cuba.core.global.Messages;
|
||||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||||
import com.haulmont.cuba.core.sys.AbstractMessages;
|
import com.haulmont.cuba.core.sys.AbstractMessages;
|
||||||
@ -29,12 +30,21 @@ import java.util.Locale;
|
|||||||
public class MessagesClientImpl extends AbstractMessages {
|
public class MessagesClientImpl extends AbstractMessages {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LocalizedMessageService localizedMessageService;
|
protected LocalizedMessageService localizedMessageService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected UserSessionSource userSessionSource;
|
protected UserSessionSource userSessionSource;
|
||||||
|
|
||||||
private volatile boolean remoteSearch;
|
protected volatile boolean remoteSearch;
|
||||||
|
|
||||||
|
protected ClientConfig clientConfig;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void setConfiguration(Configuration configuration) {
|
||||||
|
super.setConfiguration(configuration);
|
||||||
|
clientConfig = configuration.getConfig(ClientConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Locale getUserLocale() {
|
protected Locale getUserLocale() {
|
||||||
@ -73,6 +83,6 @@ public class MessagesClientImpl extends AbstractMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRemoteSearch(boolean remoteSearch) {
|
public void setRemoteSearch(boolean remoteSearch) {
|
||||||
this.remoteSearch = remoteSearch && configuration.getConfig(ClientConfig.class).getRemoteMessagesSearchEnabled();
|
this.remoteSearch = remoteSearch && clientConfig.getRemoteMessagesSearchEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,5 +131,12 @@ public interface GlobalConfig extends Config {
|
|||||||
@Property("cuba.allowQueryFromSelected")
|
@Property("cuba.allowQueryFromSelected")
|
||||||
@DefaultBoolean(true)
|
@DefaultBoolean(true)
|
||||||
boolean getAllowQueryFromSelected();
|
boolean getAllowQueryFromSelected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If true, localized messages search will use locale language only, ignoring country, variant, etc.
|
||||||
|
*/
|
||||||
|
@Property("cuba.useLocaleLanguageOnly")
|
||||||
|
@DefaultBoolean(true)
|
||||||
|
boolean getUseLocaleLanguageOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,19 +41,18 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
public static final String EXT = ".properties";
|
public static final String EXT = ".properties";
|
||||||
public static final String ENCODING = "UTF-8";
|
public static final String ENCODING = "UTF-8";
|
||||||
|
|
||||||
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected MessageTools messageTools;
|
protected MessageTools messageTools;
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected Configuration configuration;
|
|
||||||
|
|
||||||
protected Pattern enumSubclassPattern = Pattern.compile("\\$[1-9]");
|
protected Pattern enumSubclassPattern = Pattern.compile("\\$[1-9]");
|
||||||
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected GlobalConfig globalConfig;
|
||||||
|
|
||||||
protected String confDir;
|
protected String confDir;
|
||||||
|
|
||||||
private String mainMessagePack;
|
protected String mainMessagePack;
|
||||||
|
|
||||||
protected Map<String, String> strCache = new ConcurrentHashMap<>();
|
protected Map<String, String> strCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -64,6 +63,12 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
|
|
||||||
protected abstract String searchRemotely(String pack, String key, Locale locale);
|
protected abstract String searchRemotely(String pack, String key, Locale locale);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public void setConfiguration(Configuration configuration) {
|
||||||
|
globalConfig = configuration.getConfig(GlobalConfig.class);
|
||||||
|
confDir = globalConfig.getConfDir().replaceAll("\\\\", "/");
|
||||||
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
protected void init() {
|
protected void init() {
|
||||||
mainMessagePack = AppContext.getProperty("cuba.mainMessagePack");
|
mainMessagePack = AppContext.getProperty("cuba.mainMessagePack");
|
||||||
@ -71,7 +76,7 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
throw new IllegalStateException("Property cuba.messagePack is not set");
|
throw new IllegalStateException("Property cuba.messagePack is not set");
|
||||||
log.debug("Main message pack: " + mainMessagePack);
|
log.debug("Main message pack: " + mainMessagePack);
|
||||||
|
|
||||||
for (Locale locale : configuration.getConfig(GlobalConfig.class).getAvailableLocales().values()) {
|
for (Locale locale : globalConfig.getAvailableLocales().values()) {
|
||||||
Datatypes.setFormatStrings(
|
Datatypes.setFormatStrings(
|
||||||
locale,
|
locale,
|
||||||
new FormatStrings(
|
new FormatStrings(
|
||||||
@ -186,6 +191,9 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
if (key == null)
|
if (key == null)
|
||||||
throw new IllegalArgumentException("Message key is null");
|
throw new IllegalArgumentException("Message key is null");
|
||||||
|
|
||||||
|
if (globalConfig.getUseLocaleLanguageOnly())
|
||||||
|
locale = Locale.forLanguageTag(locale.getLanguage());
|
||||||
|
|
||||||
String cacheKey = makeCacheKey(packs, key, locale, false);
|
String cacheKey = makeCacheKey(packs, key, locale, false);
|
||||||
|
|
||||||
String msg = strCache.get(cacheKey);
|
String msg = strCache.get(cacheKey);
|
||||||
@ -277,13 +285,9 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
|
|
||||||
log.trace("searchFiles: " + cacheKey);
|
log.trace("searchFiles: " + cacheKey);
|
||||||
|
|
||||||
File file;
|
|
||||||
if (confDir == null)
|
|
||||||
confDir = configuration.getConfig(GlobalConfig.class).getConfDir().replaceAll("\\\\", "/");
|
|
||||||
|
|
||||||
String packPath = confDir + "/" + pack.replaceAll("\\.", "/");
|
String packPath = confDir + "/" + pack.replaceAll("\\.", "/");
|
||||||
while (packPath != null && !packPath.equals(confDir)) {
|
while (packPath != null && !packPath.equals(confDir)) {
|
||||||
file = new File(packPath + "/" + BUNDLE_NAME + getLocaleSuffix(defaultLocale ? null : locale) + EXT);
|
File file = new File(packPath + "/" + BUNDLE_NAME + getLocaleSuffix(defaultLocale ? null : locale) + EXT);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
FileInputStream stream = new FileInputStream(file);
|
FileInputStream stream = new FileInputStream(file);
|
||||||
@ -338,14 +342,10 @@ public abstract class AbstractMessages implements Messages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getAllIncludes(List<Properties> list, String pack, Locale locale, boolean defaultLocale) {
|
private void getAllIncludes(List<Properties> list, String pack, Locale locale, boolean defaultLocale) {
|
||||||
File file;
|
|
||||||
if (confDir == null)
|
|
||||||
confDir = configuration.getConfig(GlobalConfig.class).getConfDir().replaceAll("\\\\", "/");
|
|
||||||
|
|
||||||
log.trace("include: " + pack);
|
log.trace("include: " + pack);
|
||||||
|
|
||||||
String packPath = confDir + "/" + pack.replaceAll("\\.", "/");
|
String packPath = confDir + "/" + pack.replaceAll("\\.", "/");
|
||||||
file = new File(packPath + "/" + BUNDLE_NAME + getLocaleSuffix(defaultLocale ? null : locale) + EXT);
|
File file = new File(packPath + "/" + BUNDLE_NAME + getLocaleSuffix(defaultLocale ? null : locale) + EXT);
|
||||||
InputStream stream;
|
InputStream stream;
|
||||||
try {
|
try {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user