private TermQuery createLocaleQuery(ProjectLocale locale) { return new TermQuery(new Term(FIELD_LOCALE, locale.getLocale().toString())); }
/** * @return a populated list of {@link Language}s for the given {@link ProjectVersion}.<br> */ private static List<Language> loadLanguages(Resolvable<?, ?> object) { List<Language> meta = new ArrayList<Language>(); List<ProjectLocale> projectLocales = ((ProjectVersion) object).getChildren(); for (ProjectLocale projectLocale : projectLocales) { meta.add(new Language(projectLocale.getLocale())); } return meta; } }
public ProjectLocale getProjectLocale(Locale locale) { if(locale==null) return getTemplate(); EList<ProjectLocale> locales = getChildren(); for (ProjectLocale projectLocale : locales) { if (locale.equals(projectLocale.getLocale())) return projectLocale; } return null; }
public static void createMissingDescriptorEntries(ProjectVersion parent, IProgressMonitor monitor) { EList<ProjectLocale> children = parent.getChildren(); monitor.beginTask("Adding missing localized resources", children.size() - 1); ProjectLocale template = parent.getTemplate(); for (ProjectLocale locale : children) { if (locale == template) continue; if (locale != null && locale.getLocale() != null) monitor.subTask("Add missing entries for " + locale.getLocale().getDisplayName()); createMissingChildren(template, locale); monitor.worked(1); } monitor.subTask(""); monitor.done(); }
@Override public Item<?> caseProjectLocale(ProjectLocale object) { if(object.getLocale()==null || object.getLocale()==ProjectLocale.TEMPLATE_LOCALE) return addCSSIcon("icon-book"); WebMarkupContainer markupContainer = new WebMarkupContainer("css-icon"); item.add(markupContainer); markupContainer.setVisible(false); Image image = new Image("regular-image", WicketUtil.getIconForLocale(object.getLocale())); item.add(image); return item; }
query.add(new TermQuery(new Term(QueryService.FIELD_LOCALE, descriptor.getProjectLocale().getLocale().toString())), Occur.MUST_NOT);
protected PropertyFileDescriptor createDescriptor(ProjectLocale projectLocale, URI childURI) { PropertyFileDescriptor fileDescriptor = PropertiesFactory.eINSTANCE.createPropertyFileDescriptor(); fileDescriptor.setLocation(childURI); fileDescriptor.setName(childURI.lastSegment()); fileDescriptor.setVariant(projectLocale.getLocale()); projectLocale.getDescriptors().add(fileDescriptor); Resolvable<?, Resolvable<?, ?>> parent = getOrCreateParent(projectLocale, childURI); parent.getChildren().add(fileDescriptor); return fileDescriptor; }
public static URI computeLocaleResourceLocation(Locale locale, ProjectVersion version, URI templateLocation) { PropertyScanner scanner = createScanner(version); URI parentPath = version.absoluteFilePath(); String childPath = templateLocation.path(); if (childPath != null && !childPath.startsWith("/")) childPath = "/" + childPath; File path = scanner.computeTranslationPath(new File(URI.decode(parentPath.path()) + URI.decode(childPath)), version.getTemplate().getLocale(), locale); /* * workaround for https://github.com/jutzig/jabylon/issues/238 certain * issues seem to trigger a bug in EMFs createFileURI */ URI location = URI.createURI(path.getAbsolutePath().replace('\\','/')); URI trimmedLocation = URI.createURI(location.segment(parentPath.segmentCount())); for (int i = parentPath.segmentCount() + 1; i < location.segmentCount(); i++) { // append the other segments trimmedLocation = trimmedLocation.appendSegment(location.segment(i)); } return trimmedLocation; }
private static void createMissingChildren(ProjectLocale template, ProjectLocale other) { EList<PropertyFileDescriptor> descriptors = template.getDescriptors(); for (PropertyFileDescriptor descriptor : descriptors) { URI derivedLocation = computeLocaleResourceLocation(other.getLocale(), other.getParent(), descriptor.getLocation()); Resolvable<?, ?> child = other.resolveChild(derivedLocation); if(child==null){ Resolvable<?, ?> folder = getOrCreateFolder(other, derivedLocation.trimSegments(1).segments()); PropertyFileDescriptor localeDescriptor = PropertiesFactory.eINSTANCE.createPropertyFileDescriptor(); localeDescriptor.setMaster(descriptor); localeDescriptor.setVariant(other.getLocale()); localeDescriptor.setLocation(derivedLocation); localeDescriptor.setProjectLocale(other); localeDescriptor.setParent(folder); localeDescriptor.setName(URI.decode(derivedLocation.lastSegment())); } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void addNewLocalizedDescriptor(PropertyFileDescriptor descriptor, ProjectLocale locale) { if (!descriptor.eIsSet(PropertiesPackage.Literals.PROPERTY_FILE_DESCRIPTOR__LOCATION)) throw new IllegalArgumentException("Property File Descriptor location is not set"); ProjectVersion version = locale.getParent(); ProjectLocale templateLocale = version.getTemplate(); URI templateResourceLocation = computeTemplateResourceLocation(locale.getLocale(), descriptor.getLocation(), templateLocale.getLocale(),version); Resolvable<?, ?> resolved = templateLocale.resolveChild(templateResourceLocation); PropertyFileDescriptor template = null; if (resolved instanceof PropertyFileDescriptor) { template = (PropertyFileDescriptor) resolved; } if (template == null) throw new IllegalArgumentException("Template property " + templateResourceLocation + " doesn't exist"); Resolvable container = getOrCreateFolder(locale, descriptor.getLocation().trimSegments(1).segments()); if (container.getChild(descriptor.getLocation().lastSegment()) != null) { PropertyFileDescriptor child = (PropertyFileDescriptor) container.getChild(descriptor.getLocation().lastSegment()); child.setMaster(null); container.getChildren().set(container.getChildren().indexOf(child), descriptor); locale.getDescriptors().remove(child); } else { container.getChildren().add(descriptor); } descriptor.setMaster(template); locale.getDescriptors().add(descriptor); }