@Override protected void doOKAction() { final String errorString = myComponent.canCreateAllFilesForAllLocales(); if (errorString != null) { Messages.showErrorDialog(getContentPanel(), errorString); } else { final List<PsiFile> createFiles = myComponent.createPropertiesFiles(); myCreatedFiles = createFiles.toArray(new PsiElement[createFiles.size()]); super.doOKAction(); } }
@Nullable private static List<Locale> extractLocalesFromString(final String rawLocales) { if (rawLocales.isEmpty()) { return Collections.emptyList(); } final String[] splitRawLocales = rawLocales.split(","); final List<Locale> locales = new ArrayList<>(splitRawLocales.length); for (String rawLocale : splitRawLocales) { final Locale locale = PropertiesUtil.getLocale("_" + rawLocale + ".properties"); if (locale == PropertiesUtil.DEFAULT_LOCALE) { return null; } else if (!locales.contains(locale)) { locales.add(locale); } } return locales; }
private void combineToResourceBundleIfNeed(Collection<PsiFile> files) { Collection<PropertiesFile> createdFiles = ContainerUtil.map( files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> { final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom); LOG.assertTrue(file != null, dom.getName()); return file; }); ResourceBundle mainBundle = myResourceBundle; final Set<ResourceBundle> allBundles = new HashSet<>(); if (mainBundle != null) { allBundles.add(mainBundle); } boolean needCombining = false; for (PropertiesFile file : createdFiles) { final ResourceBundle rb = file.getResourceBundle(); if (mainBundle == null) { mainBundle = rb; } else if (!mainBundle.equals(rb)) { needCombining = true; } allBundles.add(rb); } if (needCombining) { final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles); final String baseName = getBaseName(); if (myResourceBundle != null) { toCombine.addAll(myResourceBundle.getPropertiesFiles()); } ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject()); for (ResourceBundle bundle : allBundles) { manager.dissociateResourceBundle(bundle); } manager.combineToResourceBundle(toCombine, baseName); } }
private MyExistLocalesListModel() { myLocales = new ArrayList<>(); myLocales.add(PropertiesUtil.DEFAULT_LOCALE); PropertiesReferenceManager.getInstance(myProject) .processPropertiesFiles( GlobalSearchScope.projectScope(myProject), new PropertiesFileProcessor() { @Override public boolean process(String baseName, PropertiesFile propertiesFile) { final Locale locale = propertiesFile.getLocale(); if (locale != PropertiesUtil.DEFAULT_LOCALE && !myLocales.contains(locale)) { myLocales.add(locale); } return true; } }, BundleNameEvaluator.DEFAULT); Collections.sort(myLocales, LOCALE_COMPARATOR); }
@Override public Locale getElementAt(int index) { return myLocales.get(index); }
@Override public int getSize() { return myLocales.size(); }