protected Object decorate(String undecoratedResult, T proxiedObject, Method method) { final String[] keys; if (undecoratedResult != null) { keys = new String[]{undecoratedResult}; } else { keys = keyGenerator.keysFor(undecoratedResult, proxiedObject, method); } final String basename = keyGenerator.messageBundleNameFor(proxiedObject); return translationService.translate(localeProvider, basename, keys); }
private List<String> getKeysFromAncestors(final ActionDefinition actionDefinition, final AnnotatedElement el, final Object root) { final List<I18nKeyGenerator> keyGenerators = getAncestorKeyGenerators(actionDefinition); final List<String> ancestorKeys = new ArrayList<>(); for (I18nKeyGenerator keygen : keyGenerators) { if (keygen instanceof NullKeyGenerator) { continue; } final String[] keysTmp = keygen.keysFor(null, root, el); Collection<String> ancestorGeneratedKeys = Collections2.filter(Arrays.asList(keysTmp), new Predicate<String>() { @Override public boolean apply(String input) { if (StringUtils.isNotBlank(input)) { return true; } return false; } }); if (ancestorGeneratedKeys.isEmpty()) { continue; } final String key = ancestorGeneratedKeys.iterator().next(); ancestorKeys.add(StringUtils.substringBefore(key, ".label")); } return ancestorKeys; }
@Override protected void keysFor(List<String> keys, OptionDefinition definition, AnnotatedElement el) { FieldDefinition selectField = getParentViaCast(definition); I18nKeyGenerator<FieldDefinition> parentKG = getKeyGenerator(selectField); String[] parentKeys; try { // We take the method from the select field, as all that is needed is the name of the method parentKeys = parentKG.keysFor(null, selectField, selectField.getClass().getMethod("getOptions")); for (String parentKey : parentKeys) { addKey(keys, parentKey, definition.getName()); } } catch (NoSuchMethodException e) { throw new IllegalStateException("Key generator was expecting to find a method getOptions on " + selectField.getClass().getName(), e); } } }
@Override protected Object decorate(String undecoratedResult, T proxiedObject, Method method) { final Object decorated = super.decorate(undecoratedResult, proxiedObject, method); // two lines below copied from I18nTextMethodDecorator.decorate() final String[] keys = keyGen.keysFor(undecoratedResult, proxiedObject, method); final String basenameKG = keyGen.messageBundleNameFor(proxiedObject); final String theKeyThatShouldBe; if (keys[0].equals(undecoratedResult)) { theKeyThatShouldBe = keys[1]; } else { theKeyThatShouldBe = keys[0]; } final LegacyMessage legacyMessage = getLegacyMessage(localeProvider.getLocale(), basenameKG, keys); if (legacyMessage != null) { // System.out.println("> legacyMessage: " + legacyMessage.key+" ->"+legacyMessage.value); // System.out.println("legacyMessage[0].equals(keys[0]): " + legacyMessage.key.equals(keys[0])); // System.out.println(" --> we want new key: "+keys[1]+" and old translation:"+legacyMessage.value); genRes.add(new GeneratorResult.AddKeyToNewBundle(localeProvider.getLocale(), theKeyThatShouldBe, legacyMessage.value)); genRes.add(new GeneratorResult.RemoveKeyFromLegacyBundle(legacyMessage.basename, legacyMessage.key, /* we don't know the path yet */null)); } else if (undecoratedResult != null && Locale.ENGLISH.equals(localeProvider.getLocale())) { // we have a configured value, but no translation in the legacy files - assume it's an hard-configured text: genRes.add(new GeneratorResult.AddKeyToNewBundle(localeProvider.getLocale(), theKeyThatShouldBe, undecoratedResult)); } else { genRes.add(new GeneratorResult.AddUntranslatedKeyToNewBundle(localeProvider.getLocale(), theKeyThatShouldBe)); } return decorated; } };
String[] parentKeys = getKeyGenerator(parent).keysFor(null, parent, el); String parentKey = parentKeys[0]; if (parentKey.endsWith(fieldOrGetterName)) {