forked from fanruan/design
Hades
6 years ago
15 changed files with 47 additions and 370 deletions
@ -1,21 +0,0 @@
|
||||
package com.fr.design.i18n; |
||||
|
||||
/** |
||||
* 包装一些动作 |
||||
* @author Hades |
||||
* @date 2019/6/4 |
||||
*/ |
||||
public interface Action { |
||||
|
||||
Action EMPTY_ACTION = new Action() { |
||||
@Override |
||||
public void todo() { |
||||
// do nothing
|
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 具体动作 |
||||
*/ |
||||
void todo(); |
||||
} |
@ -1,38 +0,0 @@
|
||||
package com.fr.design.i18n; |
||||
|
||||
/** |
||||
* 不同语言环境下的action |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public enum ActionType { |
||||
|
||||
/** |
||||
* 视频教学 |
||||
*/ |
||||
VIDEO("video"), |
||||
|
||||
/** |
||||
* 激活码 |
||||
*/ |
||||
ACTIVATION_CODE("activationCode"), |
||||
|
||||
/** |
||||
* 帮助文档 |
||||
*/ |
||||
HELP_DOCUMENT("helpDocument"), |
||||
|
||||
/** |
||||
* 论坛 |
||||
*/ |
||||
BBS("bbs"); |
||||
|
||||
|
||||
private String description; |
||||
|
||||
ActionType(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
} |
@ -1,54 +0,0 @@
|
||||
package com.fr.design.i18n; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.i18n.impl.ChinaLocaleAction; |
||||
import com.fr.design.i18n.impl.JapanLocaleAction; |
||||
import com.fr.design.i18n.impl.KoreaLocaleAction; |
||||
import com.fr.design.i18n.impl.TaiWanLocaleAction; |
||||
import com.fr.design.i18n.impl.USLocaleAction; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.GeneralContext; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 不同语言环境的动作管理 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class LocaleCenter { |
||||
|
||||
private Map<Locale, LocaleDifference> actionMap = new HashMap<Locale, LocaleDifference>(); |
||||
|
||||
private LocaleCenter() { |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
actionMap.put(Locale.CHINA, new ChinaLocaleAction()); |
||||
actionMap.put(Locale.US, new USLocaleAction()); |
||||
actionMap.put(Locale.TAIWAN, new TaiWanLocaleAction()); |
||||
actionMap.put(Locale.JAPAN, new JapanLocaleAction()); |
||||
actionMap.put(Locale.KOREA, new KoreaLocaleAction()); |
||||
} |
||||
|
||||
private static class Holder { |
||||
private static final LocaleCenter INSTANCE = new LocaleCenter(); |
||||
} |
||||
|
||||
public static LocaleCenter getInstance() { |
||||
return Holder.INSTANCE; |
||||
} |
||||
|
||||
public LocaleDifference getLocaleAction() { |
||||
Locale locale = GeneralContext.getLocale(); |
||||
if (!ComparatorUtils.equals(locale, DesignerEnvManager.getEnvManager().getLanguage())) { |
||||
locale = DesignerEnvManager.getEnvManager().getLanguage(); |
||||
} |
||||
LocaleDifference localeDifference = actionMap.get(locale); |
||||
return localeDifference == null ? actionMap.get(Locale.CHINA) : localeDifference; |
||||
} |
||||
} |
@ -1,47 +0,0 @@
|
||||
package com.fr.design.i18n; |
||||
|
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 国际化之间有不同表现的动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public interface LocaleDifference { |
||||
|
||||
/** |
||||
* 返回该国际化所有的url |
||||
* @return url |
||||
*/ |
||||
Map<ActionType, String> getUrls(); |
||||
|
||||
|
||||
/** |
||||
* 哪些国际化需要执行该动作 |
||||
* @param locales |
||||
*/ |
||||
void doAction(Locale ...locales); |
||||
|
||||
/** |
||||
* 构建具体的动作 |
||||
* @param action |
||||
* @return |
||||
*/ |
||||
LocaleDifference buildAction(Action action); |
||||
|
||||
/** |
||||
* 返回设计器启动画面路径 |
||||
* @return 路径 |
||||
*/ |
||||
String getSplashPath(); |
||||
|
||||
/** |
||||
* 对应的国际化 |
||||
* @return |
||||
*/ |
||||
Locale getLocale(); |
||||
|
||||
} |
@ -1,60 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import com.fr.design.i18n.Action; |
||||
import com.fr.design.i18n.LocaleDifference; |
||||
import com.fr.design.i18n.ActionType; |
||||
import com.fr.general.CloudCenter; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.EnumMap; |
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 一些默认的实现 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public abstract class AbstractDefaultLocaleAction implements LocaleDifference { |
||||
|
||||
protected EnumMap<ActionType, String> urls = new EnumMap<ActionType, String>(ActionType.class); |
||||
private Action action = Action.EMPTY_ACTION; |
||||
|
||||
protected void init() { |
||||
urls.put(ActionType.BBS, CloudCenter.getInstance().acquireUrlByKind("bbs")); |
||||
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video")); |
||||
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.cn")); |
||||
urls.put(ActionType.HELP_DOCUMENT, CloudCenter.getInstance().acquireUrlByKind("help.zh_CN.10")); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ActionType, String> getUrls() { |
||||
if (urls.isEmpty()) { |
||||
init(); |
||||
} |
||||
return urls; |
||||
} |
||||
|
||||
@Override |
||||
public void doAction(Locale ...locales) { |
||||
List<Locale> localeList = Arrays.asList(locales); |
||||
if (localeList.contains(this.getLocale())) { |
||||
action.todo(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public LocaleDifference buildAction(Action action) { |
||||
this.action = action; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public String getSplashPath() { |
||||
return "/com/fr/design/images/splash_10_en.gif"; |
||||
} |
||||
} |
@ -1,22 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 简体中文环境具体的表现动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class ChinaLocaleAction extends AbstractDefaultLocaleAction { |
||||
|
||||
@Override |
||||
public String getSplashPath() { |
||||
return "/com/fr/design/images/splash_10.gif"; |
||||
} |
||||
|
||||
@Override |
||||
public Locale getLocale() { |
||||
return Locale.CHINA; |
||||
} |
||||
} |
@ -1,34 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import com.fr.design.i18n.ActionType; |
||||
import com.fr.general.CloudCenter; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 日文环境具体的表现动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class JapanLocaleAction extends AbstractDefaultLocaleAction { |
||||
|
||||
@Override |
||||
protected void init() { |
||||
super.init(); |
||||
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.jp")); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getSplashPath() { |
||||
return "/com/fr/design/images/splash_10_jp.gif"; |
||||
} |
||||
|
||||
@Override |
||||
public Locale getLocale() { |
||||
return Locale.JAPAN; |
||||
} |
||||
|
||||
|
||||
} |
@ -1,17 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 韩文环境具体的表现动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class KoreaLocaleAction extends AbstractDefaultLocaleAction { |
||||
|
||||
@Override |
||||
public Locale getLocale() { |
||||
return Locale.KOREA; |
||||
} |
||||
} |
@ -1,28 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import com.fr.design.i18n.ActionType; |
||||
import com.fr.general.CloudCenter; |
||||
|
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 繁体中文具体的表现动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class TaiWanLocaleAction extends AbstractDefaultLocaleAction { |
||||
|
||||
@Override |
||||
protected void init() { |
||||
super.init(); |
||||
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video.zh_TW")); |
||||
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.tw")); |
||||
} |
||||
|
||||
@Override |
||||
public Locale getLocale() { |
||||
return Locale.TAIWAN; |
||||
} |
||||
} |
@ -1,28 +0,0 @@
|
||||
package com.fr.design.i18n.impl; |
||||
|
||||
import com.fr.design.i18n.ActionType; |
||||
import com.fr.general.CloudCenter; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 英文环境具体的表现动作 |
||||
* |
||||
* @author Hades |
||||
* @date 2019/5/30 |
||||
*/ |
||||
public class USLocaleAction extends AbstractDefaultLocaleAction { |
||||
|
||||
@Override |
||||
protected void init() { |
||||
super.init(); |
||||
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video.en")); |
||||
urls.put(ActionType.HELP_DOCUMENT, CloudCenter.getInstance().acquireUrlByKind("help.en_US.10")); |
||||
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.en")); |
||||
} |
||||
|
||||
@Override |
||||
public Locale getLocale() { |
||||
return Locale.US; |
||||
} |
||||
} |
Loading…
Reference in new issue