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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| private static void defaultLanguage(Object i18n, Locale locale, boolean AUser, I18nFiled i18nFiled, Field f) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { log.info("default locale"); if (AUser) { Field enField = i18n.getClass().getDeclaredField(i18nFiled.en()); enField.setAccessible(true); String enValue = enField.get(i18n).toString(); f.set(i18n, enValue); } else { Field tcField = i18n.getClass().getDeclaredField(i18nFiled.tc()); tcField.setAccessible(true); String tcValue = tcField.get(i18n).toString(); if (StringUtils.isNotEmpty(tcValue)) { Field enField = i18n.getClass() .getDeclaredField(i18nFiled.en()); enField.setAccessible(true); String enValue = enField.get(i18n).toString(); f.set(i18n, enValue); } } }
private static void convertI18n(Object i18n, Locale locale, boolean AUser) { log.info("locale: " + locale); Field[] fields = i18n.getClass().getDeclaredFields(); for (Field f : fields) { if (f.isAnnotationPresent(I18nFiled.class)) { f.setAccessible(true); I18nFiled i18nFiled = f.getAnnotation(I18nFiled.class); if (Locale.SIMPLIFIED_CHINESE.equals(locale)) { Field scField = i18n.getClass().getDeclaredField( i18nFiled.sc()); scField.setAccessible(true); String scValue = scField.get(i18n).toString(); if (StringUtils.isNotEmpty(scValue)) { f.set(i18n, scValue); } else { defaultLanguage(i18n, locale, AUser, i18nFiled, f); } } else if (Locale.TRADITIONAL_CHINESE.equals(locale)) { Field tcField = i18n.getClass().getDeclaredField( i18nFiled.tc()); tcField.setAccessible(true); String tcValue = tcField.get(i18n).toString(); if (StringUtils.isNotEmpty(tcValue)) { f.set(i18n, tcValue); } else { defaultLanguage(i18n, locale, AUser, i18nFiled, f); } } else { defaultLanguage(i18n, locale, AUser, i18nFiled, f); } } } }
public static <T> T convertI18n(T i18n, PortletRequest request) { Locale locale = request.getLocale(); User user = User.getCurrentUser(request); UserInfo info = user.getUserInfo(); if (info instanceof AUserUserInfo) { convertI18n(i18n, locale, true); } else if (info instanceof BUserUserInfo) { convertI18n(i18n, locale, false); } else if (info instanceof UnknownUserInfo) { convertI18n(i18n, locale, true); } return i18n; }
public static <T> T convertI18n(T i18n) { PortletRequest request = (PortletRequest) FacesContext .getCurrentInstance().getExternalContext().getRequest(); return convertI18n(i18n, request); }
|