/** * If we make it here, we know that the {@link Property} exists in the master * {@link PropertyFileDescriptor}, but we don't know if a corresponding {@link Property} exists * for the existing {@link PropertyFile}. If it does not, we create a new {@link Property}.<br> * * Hence perform a quick check, and create a new {@link Property} which we add to this * {@link PropertyFileDescriptor} if it does not yet exist.<br> */ private static void updateExistingProperty(PropertyFile existingFile, Property existingProperty, Property newProperty) { if (existingProperty == null) { existingProperty = PropertiesFactory.eINSTANCE.createProperty(); existingProperty.setKey(newProperty.getKey()); existingFile.getProperties().add(existingProperty); } existingProperty.setValue(newProperty.getValue()); existingProperty.setComment(newProperty.getComment()); }
private List<TerminologyTranslation> analyze(IModel<PropertyPair> pair, Map<String, Property> terminology) { List<TerminologyTranslation> translations = new ArrayList<TerminologyTranslation>(); if(terminology==null || terminology.isEmpty() || pair==null || pair.getObject()==null || pair.getObject().getTemplate() == null) return translations; Collection<String> tokens = getTokens(pair.getObject().getTemplate().getValue(), terminology); for (String term : tokens) { Property property = terminology.get(term); if(property==null) property = terminology.get(term.toLowerCase()); if(property!=null) { translations.add(new TerminologyTranslation(property.getKey(), property.getValue(), property.getComment())); } } return translations; }
if(current.getValue()==null || current.getKey()==null) annotation.getValues().put(PropertyAnnotations.SOURCE_LANGUAGE, normalizeLanguage(srcLanguage)); annotation.getValues().put(PropertyAnnotations.TARGET_LANGUAGE, normalizeLanguage(targetLanguage)); current.getAnnotations().add(annotation); file.getProperties().add(current); current.setKey(currentValue.toString()); current.setValue(currentValue.toString());
property.setComment(comment.toString()); PropertyAnnotation nonTranslatable = property.findAnnotation(PropertyAnnotations.NON_TRANSLATABLE); if(nonTranslatable!=null) { logger.info("Property {} in file {} is marked as non-translatable. Skipping",property.getKey(),uri); propertyValue.setLength(0); comment.setLength(0);; continue; property.setKey(parts[0]); property.setValue(parts[1]); checkedForHeader = true; return property; if(property!=null && property.getKey()==null) return null; return property;
private void createMessageFile(InputStream in, URI target, boolean isTemplate) throws IOException { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); Property property = null; POHelper helper = new POHelper(); PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); while((property=helper.readProperty(reader))!=null) { if(isTemplate) { property.setValue(property.getKey()); //get rid of the german comment property.setComment(null); } file.getProperties().add(property); } PropertiesResourceImpl resource = new PropertiesResourceImpl(target); resource.getContents().add(file); resource.save(new HashMap<Object, Object>()); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getMessage(),e); } finally { reader.close(); } }
property.setKey(matcher.group(1).replace("\\n", "\n")); if(comment.length()>0) property.setComment(comment.toString()); if(matcher.matches()) property.setValue(matcher.group(1).replace("\\n", "\n")); return property;
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { boolean template = false; URL url = new URL("http://pootle.locamotion.org/export/terminology/de/essential.po"); InputStream openStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(openStream, "UTF-8")); Property property = null; POHelper helper = new POHelper(); PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); while((property=helper.readProperty(reader))!=null) { if(template) property.setValue(property.getKey()); file.getProperties().add(property); } PropertiesResourceImpl resource = new PropertiesResourceImpl(org.eclipse.emf.common.util.URI.createFileURI("messages.properties")); resource.getContents().add(file); resource.save(new HashMap<Object, Object>()); }
public String getOriginalComment() { if(getTemplate()==null) return ""; //$NON-NLS-1$ return getTemplate().getComment(); }
public void setTranslated(String translated) { getOrCreateTranslation().setValue(translated); }
public void setTranslatedComment(String comment) { getOrCreateTranslation().setComment(comment); }
/** * extracts the target locale from a property annotation. * @param property * @return */ private Locale extractTargetLocale(Property property) { PropertyAnnotation annotation = property.findAnnotation(PropertyAnnotations.ANNOTATION_LANGUAGE); if(annotation==null) return null; String localeString = annotation.getValues().get(PropertyAnnotations.TARGET_LANGUAGE); if(localeString==null) return null; return (Locale) PropertiesFactory.eINSTANCE.createFromString(PropertiesPackage.Literals.LOCALE, localeString); }
doc.add(new Field(QueryService.FIELD_TMX, Boolean.TRUE.toString(), Store.YES, Index.NOT_ANALYZED)); if (property.getKey() != null) { Field masterValueField = new Field(QueryService.FIELD_MASTER_VALUE, property.getKey(), Store.YES, Index.ANALYZED); doc.add(masterValueField); if (property.getComment() != null) { Field masterCommentField = new Field(QueryService.FIELD_MASTER_COMMENT, property.getComment(), Store.YES, Index.ANALYZED); doc.add(masterCommentField); doc.add(pathField); Field comment = new Field(QueryService.FIELD_COMMENT, nullSafe(property.getComment()), Store.YES, Index.ANALYZED); doc.add(comment); Field key = new Field(QueryService.FIELD_KEY, nullSafe(property.getKey()), Store.YES, Index.NOT_ANALYZED); doc.add(key); Field analyzedKey = new Field(QueryService.FIELD_KEY, nullSafe(property.getKey()), Store.YES, Index.ANALYZED); doc.add(analyzedKey); doc.add(new Field(QueryService.FIELD_TMX_VALUE, nullSafe(property.getValue()), Store.YES, Index.ANALYZED)); doc.add(new Field(QueryService.FIELD_VALUE, nullSafe(property.getKey()), Store.YES, Index.ANALYZED)); String templateLocation = location.toString(); Field templateLoc = new Field(QueryService.FIELD_TEMPLATE_LOCATION, templateLocation, Store.YES, Index.NOT_ANALYZED);
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated NOT */ public Property getProperty(String key) { EList<Property> eList = getProperties(); synchronized (eList) { for (Property property : eList) { if (key.equals(property.getKey())) return property; } } return null; }
public void writeProperty(Writer writer, Property property) throws IOException { writeCommentAndAnnotations(writer, property); String key = property.getKey(); key = key.replaceAll("([ :=\n])", "\\\\$1"); if(unicodeEscaping) writer.write(NativeToAsciiConverter.convertUnicodeToEncoded(key,true)); else writer.write(key); writer.write(" = "); String value = property.getValue(); if(value!=null) { //leading spaces need to be masked //see https://github.com/jutzig/jabylon/issues/186 if(value.startsWith(" ")) value = "\\"+value; value = value.replace("\r", "\\r"); value = value.replace("\n", "\\n"); if(unicodeEscaping) value = NativeToAsciiConverter.convertUnicodeToEncoded(value, true); writer.write(value); } writer.write('\n'); }
private Notification computeDiff(Property orignalPropertery, Property modifiedProperty) { if (orignalPropertery.getValue() == null && modifiedProperty.getValue() == null) return null; // if both are null, it's all good if (orignalPropertery.getValue() == null && modifiedProperty.getValue() != null) { return new CustomNotification(Notification.SET, null, modifiedProperty.getValue(), modifiedProperty); } if (modifiedProperty.getValue() == null && orignalPropertery.getValue() != null) { return new CustomNotification(Notification.UNSET, orignalPropertery.getValue(), null, modifiedProperty); } if(modifiedProperty.getValue().equals(orignalPropertery.getValue())) return null; return new CustomNotification(Notification.SET, orignalPropertery.getValue(), modifiedProperty.getValue(), modifiedProperty); }