forked from fanruan/design
Henry.Wang
3 years ago
13 changed files with 8 additions and 138 deletions
@ -1,97 +0,0 @@
|
||||
package com.fr.design.i18n; |
||||
|
||||
import com.fr.general.CloudCenter; |
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.locale.LocaleBundle; |
||||
import com.fr.locale.LocaleFiles; |
||||
import com.fr.locale.LocaleManager; |
||||
import com.fr.locale.impl.FineLocaleManager; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
|
||||
public class UrlI18nManager { |
||||
private static final String I18N_URL_PATH = "com/fr/design/i18n/url"; |
||||
|
||||
private static UrlI18nManager instance = new UrlI18nManager(); |
||||
|
||||
public static UrlI18nManager getInstance() { |
||||
return instance; |
||||
} |
||||
|
||||
private LocaleManager localeManager = FineLocaleManager.create(); |
||||
|
||||
private UrlI18nManager() { |
||||
localeManager.addResource(I18N_URL_PATH); |
||||
} |
||||
|
||||
public String getI18nUrl(String key) { |
||||
String i18NUrl = getI18nUrlFromCloudCenter(key); |
||||
if (StringUtils.isBlank(i18NUrl)) { |
||||
i18NUrl = getI18nUrlFromLocal(key); |
||||
} |
||||
return i18NUrl; |
||||
} |
||||
|
||||
private String getI18nUrlFromCloudCenter(String key) { |
||||
List<String> availableKeys = getCloudCenterAvailableKeys(key); |
||||
for (String availableKey : availableKeys) { |
||||
String i18NUrl = CloudCenter.getInstance().acquireConf(availableKey); |
||||
if (!StringUtils.isBlank(i18NUrl)) { |
||||
return i18NUrl; |
||||
} |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
private List<String> getCloudCenterAvailableKeys(String key) { |
||||
List<String> availableKeys = new ArrayList<>(); |
||||
availableKeys.add(key + "." + GeneralContext.getLocale() + "." + ProductConstants.MAIN_VERSION); |
||||
availableKeys.add(key + "." + Locale.ENGLISH + "." + ProductConstants.MAIN_VERSION); |
||||
availableKeys.add(key + "." + Locale.CHINA + "." + ProductConstants.MAIN_VERSION); |
||||
availableKeys.add(key + "." + GeneralContext.getLocale()); |
||||
availableKeys.add(key + "." + Locale.ENGLISH); |
||||
availableKeys.add(key + "." + Locale.CHINA); |
||||
availableKeys.add(key + "." + ProductConstants.MAIN_VERSION); |
||||
availableKeys.add(key); |
||||
return availableKeys; |
||||
} |
||||
|
||||
private String getI18nUrlFromLocal(String key) { |
||||
List<Locale> availableLocales = getAvailableLocales(); |
||||
LocaleBundle localeBundle = null; |
||||
for (Locale availableLocale : availableLocales) { |
||||
localeBundle = localeManager.getLocalBundle(availableLocale); |
||||
if (isExist(localeBundle, localeManager, key)) { |
||||
break; |
||||
} |
||||
} |
||||
if (localeBundle != null) { |
||||
return localeBundle.getText(localeManager, key); |
||||
} else { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
} |
||||
|
||||
private List<Locale> getAvailableLocales() { |
||||
List<Locale> availableLocales = new ArrayList<>(); |
||||
availableLocales.add(GeneralContext.getLocale()); |
||||
availableLocales.add(Locale.ENGLISH); |
||||
availableLocales.add(Locale.CHINA); |
||||
return availableLocales; |
||||
} |
||||
|
||||
private boolean isExist(LocaleBundle localeBundle, LocaleManager localeManager, String key) { |
||||
List<LocaleFiles> filesList = localeManager.getReverseList(); |
||||
for (LocaleFiles files : filesList) { |
||||
if (files.contains(localeBundle.getLocale(), key)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -1,7 +0,0 @@
|
||||
help=https://help.fanruan.com/finereport-en/ |
||||
help.remote.design=https://help.fanruan.com/finereport-en/doc-view-3862.html?source=4 |
||||
odbc.help=https://help.fanruan.com/finereport-en/doc-view-289.html |
||||
plugin.mobile.style=https://help.fanruan.com/finereport-en/doc-view-2656.html |
||||
help.install.font=https://help.fanruan.com/finereport-en/doc-view-3875.html |
||||
website=https://www.finereport.com/en/ |
||||
nine.point.help=https://help.fanruan.com/finereport-en/doc-view-3876.html |
@ -1,7 +0,0 @@
|
||||
help=https://help.fanruan.com/finereport-jp/ |
||||
help.remote.design=https://help.fanruan.com/finereport-jp/doc-view-3891.html |
||||
odbc.help=https://help.fanruan.com/finereport-jp/doc-view-289.html |
||||
plugin.mobile.style=https://help.fanruan.com/finereport-jp/doc-view-2656.html |
||||
help.install.font=https://help.fanruan.com/finereport-jp/doc-view-3892.html |
||||
website=https://www.finereport.com/jp/ |
||||
nine.point.help=https://help.fanruan.com/finereport-jp/doc-view-3896.html |
@ -1 +0,0 @@
|
||||
website=https://www.finereport.com/kr/ |
@ -1,7 +0,0 @@
|
||||
help=https://help.fanruan.com/finereport/ |
||||
help.remote.design=https://help.fanruan.com/finereport/doc-view-3925.html |
||||
odbc.help=https://help.fanruan.com/finereport/doc-view-289.html |
||||
plugin.mobile.style=https://help.fanruan.com/finereport/doc-view-2656.html |
||||
help.install.font=https://help.fanruan.com/finereport/doc-view-3999.html |
||||
website=https://www.finereport.com/ |
||||
nine.point.help=https://help.fanruan.com/finereport/doc-view-4135.html |
@ -1,7 +0,0 @@
|
||||
help=https://help.fanruan.com/finereport-tw/ |
||||
help.remote.design=https://help.fanruan.com/finereport/doc-view-3925.html |
||||
odbc.help=https://help.fanruan.com/finereport/doc-view-289.html |
||||
plugin.mobile.style=https://help.fanruan.com/finereport/doc-view-2656.html |
||||
help.install.font=https://help.fanruan.com/finereport/doc-view-3999.html |
||||
website=https://www.finereport.com/tw/ |
||||
nine.point.help=https://help.fanruan.com/finereport-tw/doc-view-4519.html |
Loading…
Reference in new issue