private Serializable getClosestValue(MLText mlText) { Set<Locale> locales = mlText.getLocales(); Locale contentLocale = I18NUtil.getContentLocale(); Locale locale = I18NUtil.getNearestLocale(contentLocale, locales); if (locale != null) { return mlText.getValue(locale); } // If the content locale is too specific, try relaxing it to just language Locale contentLocaleLang = I18NUtil.getContentLocaleLang(); // We do not expect contentLocaleLang to be null if (contentLocaleLang != null) { locale = I18NUtil.getNearestLocale(contentLocaleLang, locales); if (locale != null) { return mlText.getValue(locale); } } else { logger.warn("contentLocaleLang is null in getClosestValue. This is not expected."); } // Just return the default translation return mlText.getDefaultValue(); }
MLText mlTextValue = new MLText(); mlTextValue.put(Locale.ENGLISH, sb.toString()); MLText mlTextValue1 = new MLText(); mlTextValue1.put(Locale.ENGLISH, sb.toString()); map.put("MLText", mlTextValue1); MLText mlTextValue2 = new MLText(); mlTextValue2.put(Locale.ENGLISH, sb.toString()); list.add(mlTextValue2);
/** * Replace any text in mlText having the same language (but any variant) as contentLocale * with updatedText keyed by the language of contentLocale. This ensures that the mlText * will have no more than one entry for the particular language. * * @param contentLocale Locale * @param updatedText String * @param mlText MLText */ private void replaceTextForLanguage(Locale contentLocale, String updatedText, MLText mlText) { String language = contentLocale.getLanguage(); // Remove all text entries having the same language as the chosen contentLocale // (e.g. if contentLocale is en_GB, then remove text for en, en_GB, en_US etc. Iterator<Locale> locales = mlText.getLocales().iterator(); while (locales.hasNext()) { Locale locale = locales.next(); if (locale.getLanguage().equals(language)) { locales.remove(); } } // Add the new value for the specific language mlText.addValue(new Locale(language), updatedText); } }
MLText mlTextProperty = new MLText(); mlTextProperty.addValue(Locale.UK, "en_GB String"); mlTextProperty.addValue(Locale.FRANCE, "fr_FR String"); rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE); assertEquals(2, ((MLText) textValue).size()); assertEquals("en_GB String", ((MLText) textValue).getValue(Locale.UK)); assertEquals("fr_FR String", ((MLText) textValue).getValue(Locale.FRANCE)); rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE); assertEquals(2, ((MLText) textValue).size()); assertEquals("Text wasn't updated correctly", "Not using MLText for this part.", ((MLText) textValue).getValue(Locale.ENGLISH)); assertEquals("Failed to get text using locale it was added with", "Not using MLText for this part.", ((MLText) textValue).getClosestValue(Locale.US)); assertEquals("Failed to get text using original locale", "Not using MLText for this part.", ((MLText) textValue).getClosestValue(Locale.UK)); assertEquals("fr_FR String", ((MLText) textValue).getValue(Locale.FRANCE));
MLText mlTextProperty = new MLText(); mlTextProperty.addValue(Locale.ENGLISH, "Very good!"); mlTextProperty.addValue(Locale.FRENCH, "Très bon!"); mlTextProperty.addValue(Locale.GERMAN, "Sehr gut!"); assertEquals( "Default locale value not taken for ML text", mlTextProperty.getValue(Locale.ENGLISH), textValueFiltered); assertEquals( "Default locale value not taken for ML text in Map", mlTextProperty.getValue(Locale.ENGLISH), propertiesFiltered.get(BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
Locale defaultLocale = I18NUtil.getLocale(); MLText mlTextCheck2 = (MLText) mlTextCheck; String mlTextDefaultCheck = mlTextCheck2.getDefaultValue(); assertEquals("Default MLText value was not set correctly", text, mlTextDefaultCheck); MLText mlText = new MLText(); mlText.addValue(Locale.ENGLISH, "Very good!"); mlText.addValue(Locale.FRENCH, "Très bon!"); mlText.addValue(Locale.GERMAN, "Sehr gut!"); nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, mlText);
String ITALY_DESCRIPTION = "italy description"; String DEFAULT_DESCRIPTION = "default description"; MLText description = new MLText(); description.addValue(Locale.getDefault(), DEFAULT_DESCRIPTION); description.addValue(Locale.FRANCE, FRENCH_DESCRIPTION); description.addValue(Locale.GERMAN, GERMAN_DESCRIPTION); description.addValue(Locale.ITALY, ITALY_DESCRIPTION); props.put(ContentModel.PROP_DESCRIPTION, description); assertEquals("French description is wrong", FRENCH_DESCRIPTION, value.get(Locale.FRANCE)); assertEquals("German description is wrong", GERMAN_DESCRIPTION, value.get(Locale.GERMAN));
Set<Locale> locales = mltext.getLocales(); for (Locale locale : locales) mltext.put(locale, SchemaBootstrap.trimStringForTextFields(mltext.getValue(locale)));
newMLValue = new MLText(); if (currentMLValue != null) newMLValue.putAll(currentMLValue); newMLValue = new MLText(); MLText newMLValue = new MLText(); if (currentMLValue != null) newMLValue.putAll(currentMLValue); newMLValue.remove(contentLocale); returnMLList.set(i, newMLValue); for(MLText mlText : returnMLList) if(mlText.keySet().size() > 0) MLText returnMLValue = new MLText(); if (currentValue != null) returnMLValue.putAll(currentMLValue);
MLText mlTextValue = new MLText(); mlTextValue.put(Locale.ENGLISH, sb.toString()); MLText mlTextValue1 = new MLText(); mlTextValue1.put(Locale.ENGLISH, sb.toString()); map.put("MLText", mlTextValue1); MLText mlTextValue2 = new MLText(); mlTextValue2.put(Locale.ENGLISH, sb.toString()); list.add(mlTextValue2);
values.add(new MLText(Locale.UK, "en_GB text")); values.add(new MLText(Locale.US, "en_US text")); values.add(new MLText(Locale.FRANCE, "fr_FR text")); rootNodeRef, PROP_QNAME_MULTI_ML_VALUE); assertEquals("Expected 3 MLText values back", 3, checkValues.size()); assertEquals("en_GB text", ((MLText) checkValues.get(0)).getValue(Locale.UK)); assertEquals("en_US text", ((MLText) checkValues.get(1)).getValue(Locale.US)); assertEquals("fr_FR text", ((MLText) checkValues.get(2)).getValue(Locale.FRANCE)); assertEquals("en_GB should be replaced with new, not added to", 1, mlText.size()); assertEquals("text 1 added using en_US", mlText.getValue(Locale.ENGLISH)); assertEquals("en_US should be replaced with new, not added to", 1, mlText.size()); assertEquals("text 2 added using en_US", mlText.getValue(Locale.ENGLISH)); assertEquals("en_US should be added to fr_FR", 2, mlText.size()); assertEquals("fr_FR text", mlText.getValue(Locale.FRANCE)); assertEquals("text 3 added using en_US", mlText.getValue(Locale.ENGLISH)); assertEquals("entirely new text value should be added", 1, mlText.size()); assertEquals("text 4 added using en_US", mlText.getValue(Locale.ENGLISH));
private void checkSiteTitlePropertyRenamed(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) { QName nodeRefType = nodeService.getType(nodeRef); if (dictionaryService.isSubClass(nodeRefType, TYPE_SITE) && propertyChanged(before, after, ContentModel.PROP_TITLE)) { String oldName = ((MLText) before.get(ContentModel.PROP_TITLE)).getDefaultValue(); String newName = ((MLText) after.get(ContentModel.PROP_TITLE)).getDefaultValue(); eventsService.nodeRenamed(nodeRef, oldName, newName); } }
Set<Locale> locales = valueMLT.getLocales(); for (Locale locale : locales) String localeValue = valueMLT.getValue(locale); exporter.startValueMLText(nodeRef, locale, localeValue == null); walkProperty(nodeRef, property, localeValue, -1, parameters, exporter);
String value = mlText.get(closestLocale); if(value != null)
String s1 = DefaultTypeConverter.INSTANCE.convert(MLText.class, o1).getClosestValue(locale); String s2 = DefaultTypeConverter.INSTANCE.convert(MLText.class, o2).getClosestValue(locale);
Locale locale = (Locale)props.get("locale"); String value = buffer.toString(); mltext.addValue(locale, value); props.put("value", mltext);
@Override public Void execute() throws Throwable { MLPropertyInterceptor.setMLAware(true); List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(writeFolderNodeRef); // Count assertEquals(1, childAssocs.size()); NodeRef fileNodeRef = childAssocs.get(0).getChildRef(); MLText descriptions = (MLText) nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION); assertNotNull("No descriptions added", descriptions); assertEquals("Incorrect number of unique descriptions added: ", 10, descriptions.size()); assertTrue("Expect the default language to be present. ", descriptions.containsKey(new Locale(Locale.getDefault().getLanguage()))); return null; } };
for (Entry<Locale, String> entry : mltext.entrySet())