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() + "'":"") +");"; }
protected String localizeURI(String linkStr, Locale locale) { I18nContentSupport i18n = Components.getComponent(I18nContentSupport.class); if (!i18n.getLocales().contains(locale.toString())) { //not supported locale - use current one return i18n.toI18NURI(linkStr); } if (locale.equals(i18n.getDefaultLocale())) { return linkStr; } if (linkStr.startsWith("/")) { return "/" + locale.toString() + linkStr; } return linkStr; } }
@Override public String getTitle() { return I18nContentSupportFactory.getI18nSupport().getNodeData(this, "title").getString(); }
protected String createURI(Content currentPage, Locale locale) { // we are going to change the context language, this is ugly but is safe as only the current Thread is modified Locale currentLocale = i18nContentSupport.getLocale(); String uri=null; try { // this is going to set the local in the aggregation state and hence wont change the i18nSupport object itself i18nContentSupport.setLocale(locale); uri = LinkUtil.createAbsoluteLink(currentPage); } // make sure that we always reset to the original locale finally{ i18nContentSupport.setLocale(currentLocale); } return uri; }
@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; }
/** * Get the language used currently. * * @return The language as a String. */ public String language() { return i18nContentSupport.get().getLocale().toString(); }
@Override public boolean isEnabled() { return getI18nContentSupport().isEnabled(); }
@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() + ")"); } } } } }
@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); }
/** * 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 Property getProperty(Node node, String name, Locale locale) throws RepositoryException { return getI18nContentSupport().getProperty(node, name, locale); }
NodeData nodeData = I18nContentSupportFactory.getI18nSupport().getNodeData(contentNode, this.getNodeDataName()); Locale locale; if (this.dateLanguage == null) { locale = I18nContentSupportFactory.getI18nSupport().getLocale();
@Override public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { if (i18nContentSupport != null) { final Locale locale = i18nContentSupport.determineLocale(); i18nContentSupport.setLocale(locale); AggregationState aggregationState = MgnlContext.getAggregationState(); String currentUri = aggregationState.getCurrentURI(); String newUri = i18nContentSupport.toRawURI(currentUri); // MAGNOLIA-2064 ... do not set current uri if it hasn't changed to prevent double removal of context path. if (!currentUri.equals(newUri)) { aggregationState.setCurrentURI(newUri); } } chain.doFilter(request, response); } }
@Override public void setLocale(Locale locale) { getI18nContentSupport().setLocale(locale); }
Property propertyNavTitle = i18nContentSupport.getProperty(child, NODEDATA_NAVIGATIONTITLE); String title = null; if (propertyNavTitle != null) { out.print(i18nContentSupport.toI18NURI(child.getPath())); out.print(".html\"");
List<String> cssClasses = new ArrayList<String>(4); NodeData nodeData = I18nContentSupportFactory.getI18nSupport().getNodeData(child, NODEDATA_NAVIGATIONTITLE); String title = nodeData.getString(StringUtils.EMPTY); out.print(I18nContentSupportFactory.getI18nSupport().toI18NURI(child.getHandle())); out.print(".html\""); //$NON-NLS-1$
@Override public String toI18NURI(String uri) { return getI18nContentSupport().toI18NURI(uri); }
@Override public Collection<Locale> getLocales() { return getI18nContentSupport().getLocales(); }
@Override public Locale getDefaultLocale() { return getI18nContentSupport().getDefaultLocale(); } }
@Override public Locale getFallbackLocale() { return getI18nContentSupport().getFallbackLocale(); }