@Override public boolean isEnabled() { return getI18nContentSupport().isEnabled(); }
protected String onClickForNewButton(String path, String nodeCollectionName, String nodeName, String paragraph, String repository, String dialogName) { return "mgnlOpenDialog('" + path + "','" + nodeCollectionName + "','" + nodeName + "','" + paragraph + "','" + repository + "','.magnolia/dialogs/" + dialogName + ".html'" + ", null" //width + ", null" //height + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"") +");"; }
/** * Creates a map of localized links to the node for all supported languages. * * See {@link #localizedLinks()} for details. */ public Map<String, String> localizedLinks(Node content) throws RepositoryException { final Node pageNode = page(content); final String pageIdentifier = pageNode.getIdentifier(); final Collection<Locale> locales = i18nContentSupport.get().getLocales(); if (i18nContentSupport.get().isEnabled() && locales.size() > 1) { final Map<String, String> map = new LinkedHashMap<>(); for (Locale locale : locales) { final String uri = createURI(pageIdentifier, locale); // Using toString() method in order to be able to create link to e.g. // de_CH, de_DE, de_AT final String label = locale.toString(); map.put(label, uri); } return map; } return Collections.emptyMap(); }
@Override public Control getLanguageChooser() { if (isEnabled() && i18nContentSupport.isEnabled() && i18nContentSupport.getLocales().size()>1){ Select select = new Select(); select.setName("locale"); select.setEvent("onchange", "window.location = this.value"); Content currentPage = MgnlContext.getAggregationState().getMainContent(); String currentUri = createURI(currentPage, i18nContentSupport.getLocale()); select.setValue(currentUri); for (Locale locale : i18nContentSupport.getLocales()) { String uri = createURI(currentPage, locale); String label = StringUtils.capitalize(locale.getDisplayLanguage(locale)); if(StringUtils.isNotEmpty(locale.getCountry())){ label += " (" + StringUtils.capitalize(locale.getDisplayCountry()) + ")"; } select.setOptions(label, uri); } return select; } return null; }
public void setDefaultOnclick() { String nodeCollectionName = this.getNodeCollectionName(); if (nodeCollectionName == null) { nodeCollectionName = StringUtils.EMPTY; } String nodeName = this.getNodeName(); if (nodeName == null) { nodeName = StringUtils.EMPTY; } String repository = MgnlContext.getAggregationState().getRepository(); this.setOnclick("mgnlOpenDialog('" //$NON-NLS-1$ + this.getPath() + "','" //$NON-NLS-1$ + nodeCollectionName + "','" //$NON-NLS-1$ + nodeName + "','" //$NON-NLS-1$ + this.getDialog() + "','" //$NON-NLS-1$ + repository + "'," + (dialogPath != null ? "'" + dialogPath + "'" : "null") + ", null" //width + ", null" //height + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"") +");"); }
@Override public void i18nIze(Dialog dialog) { // TODO: should this be set in the aggregation state? Locale locale = LocaleUtils.toLocale(dialog.getConfigValue("locale", null)); boolean isFallbackLanguage = i18nContentSupport.getFallbackLocale().equals(locale); if (isEnabled() && i18nContentSupport.isEnabled() && locale != null) { List<DialogControlImpl> tabs = dialog.getSubs(); for (DialogControlImpl tab : tabs) { List<DialogControlImpl> controls = tab.getSubs(); for (DialogControlImpl control : controls) { boolean i18n = BooleanUtil.toBoolean(control.getConfigValue("i18n"), false); if (i18n) { if(!isFallbackLanguage){ String newName = control.getName() + "_" + locale.toString(); control.setName(newName); } String translatedLabel = control.getMessage(control.getLabel()); control.setLabel(translatedLabel + " (" + locale.toString() + ")"); } } } } }
+ repository + "',null, null, null" + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"") + ")");
@Before public void setUp() throws Exception { MockUtil.initMockContext(); List<ConfiguredFieldDefinition> fields = new ArrayList<ConfiguredFieldDefinition>(); // Init definition. TextFieldDefinition text1 = new TextFieldDefinition(); text1.setName("text1"); fields.add(text1); TextFieldDefinition text2 = new TextFieldDefinition(); text2.setName("text2"); fields.add(text2); definition.setName("composite"); definition.setFields(fields); // Init rootItem. MockSession session = new MockSession("test"); ((MockContext) MgnlContext.getInstance()).addSession("test", session); rootNode = new MockNode(session); rootNode.setName("root"); rootItem = new JcrNodeAdapter(rootNode); i18NAuthoringSupport = mock(I18NAuthoringSupport.class); i18nContentSupport = mock(I18nContentSupport.class); when(i18nContentSupport.getDefaultLocale()).thenReturn(defaultLocal); when(i18nContentSupport.isEnabled()).thenReturn(false); }
else if (I18nContentSupportFactory.getI18nSupport().isEnabled() && "true".equals(this.getConfigValue("i18n")))
@Before public void setUp() throws Exception { MockUtil.initMockContext(); // Init definition definition = new MultiValueFieldDefinition(); definition.setName(fieldName); definition.setI18n(false); // Init rootItem MockSession session = new MockSession("test"); ((MockContext) MgnlContext.getInstance()).addSession("test", session); rootNode = new MockNode(session); rootNode.setName("root"); rootNode.setPrimaryType(NodeTypes.ContentNode.NAME); rootNode.addNode(new MockNode("multi0", NodeTypes.ContentNode.NAME)); rootNode.addNode(new MockNode("multi0_de", NodeTypes.ContentNode.NAME)); rootNode.addNode(new MockNode("titi", NodeTypes.ContentNode.NAME)); rootItem = new JcrNodeAdapter(rootNode); i18nContentSupport = mock(I18nContentSupport.class); when(i18nContentSupport.getDefaultLocale()).thenReturn(defaultLocal); when(i18nContentSupport.isEnabled()).thenReturn(false); i18NAuthoringSupport = mock(I18NAuthoringSupport.class); }
@Test public void readFromItemWithI18nSupport() { // GIVEN when(i18nContentSupport.isEnabled()).thenReturn(true); definition.setI18n(true); DelegatingMultiValueFieldTransformer transformer = new DelegatingMultiValueFieldTransformer(rootItem, definition, PropertysetItem.class, createI18AuthoringSupportMock()); // WHEN PropertysetItem res = transformer.readFromItem(); // THEN assertNotNull(res); assertEquals(1, res.getItemPropertyIds().size()); assertNotNull(res.getItemProperty(0)); Item subItem = (Item) res.getItemProperty(0).getValue(); assertTrue(subItem instanceof JcrNodeAdapter); assertEquals(rootItem, ((JcrNodeAdapter) subItem).getParent()); assertEquals(subItem, rootItem.getChild("multi0")); }
@Test public void readFromItemWithI18nSupport() { // GIVEN when(i18nContentSupport.isEnabled()).thenReturn(true); definition.setI18n(true); DelegatingSubnodeCompositeTransformer transformer = new DelegatingSubnodeCompositeTransformer(rootItem, definition, PropertysetItem.class, createI18AuthoringSupportMock()); // WHEN transformer.setLocale(Locale.GERMAN); JcrNodeAdapter rootItem = transformer.getRootItem(); // THEN assertNotNull(rootItem); assertEquals("composite_de", rootItem.getNodeName()); // WHEN transformer.setLocale(Locale.ENGLISH); rootItem = transformer.getRootItem(); // THEN assertNotNull(rootItem); assertEquals("composite", rootItem.getNodeName()); }
@Test public void readFromItemWithI18nSupportNotDefaultLocal() { // GIVEN when(i18nContentSupport.isEnabled()).thenReturn(true); definition.setI18n(true); final I18NAuthoringSupport i18nAuthoringSupport = createI18AuthoringSupportMock(); DelegatingMultiValueFieldTransformer transformer = new DelegatingMultiValueFieldTransformer(rootItem, definition, PropertysetItem.class, i18nAuthoringSupport); transformer.setLocale(Locale.GERMANY); // WHEN PropertysetItem res = transformer.readFromItem(); // THEN assertNotNull(res); assertEquals(1, res.getItemPropertyIds().size()); assertNotNull(res.getItemProperty(0)); Item subItem = (Item) res.getItemProperty(0).getValue(); assertTrue(subItem instanceof JcrNodeAdapter); assertEquals(rootItem, ((JcrNodeAdapter) subItem).getParent()); assertEquals(subItem, rootItem.getChild("multi0_de")); }
@Test public void readFromItemWithI18nSupport() { // GIVEN when(i18nContentSupport.isEnabled()).thenReturn(true); definition.setI18n(true); DelegatingMultiValueChildNodeWithLocaleTransformer transformer = new DelegatingMultiValueChildNodeWithLocaleTransformer(rootItem, definition, PropertysetItem.class, createI18AuthoringSupportMock()); // WHEN transformer.setLocale(Locale.GERMAN); JcrNodeAdapter rootItem = transformer.getRootItem(); // THEN assertNotNull(rootItem); assertEquals("multi_de", rootItem.getNodeName()); // WHEN transformer = new DelegatingMultiValueChildNodeWithLocaleTransformer(rootItem, definition, PropertysetItem.class, createI18AuthoringSupportMock()); transformer.setLocale(Locale.ENGLISH); rootItem = transformer.getRootItem(); // THEN assertNotNull(rootItem); assertEquals("multi", rootItem.getNodeName()); }
@Test public void createNewElementWithI18nSupport() { // GIVEN when(i18nContentSupport.isEnabled()).thenReturn(true); definition.setI18n(true); DelegatingMultiValueFieldTransformer transformer = new DelegatingMultiValueFieldTransformer(rootItem, definition, PropertysetItem.class, createI18AuthoringSupportMock()); transformer.setLocale(Locale.GERMANY); transformer.readFromItem(); // WHEN Property<?> res = transformer.createProperty(); // THEN assertNotNull(res); assertTrue(res.getValue() instanceof JcrNewNodeAdapter); assertEquals("multi1_de", ((JcrNewNodeAdapter) res.getValue()).getNodeName()); assertEquals(rootItem, ((JcrNodeAdapter) res.getValue()).getParent()); assertEquals(res.getValue(), rootItem.getChild("multi1_de")); }