public Languages getLanguages() { I18nManager i18nMgr = I18nManager.getInstance(); Collection<String> enabledKeysSet = I18nModule.getEnabledLanguageKeys(); Map<String, String> langNames = new HashMap<String, String>(); Map<String, String> langTranslators = new HashMap<String, String>(); String[] enabledKeys = ArrayHelper.toArray(enabledKeysSet); String[] names = new String[enabledKeys.length]; for (int i = 0; i < enabledKeys.length; i++) { String key = enabledKeys[i]; String langName = i18nMgr.getLanguageInEnglish(key, I18nModule.isOverlayEnabled()); langNames.put(key, langName); names[i] = langName; String author = i18nMgr.getLanguageAuthor(key); langTranslators.put(key, author); } ArrayHelper.sort(enabledKeys, names, true, true, true); return new Languages(enabledKeys, langNames, langTranslators); }
/** * @see * org.olat.search.service.indexer.AbstractHierarchicalIndexer#doIndex(org.olat.search.service.SearchResourceContext, * java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer) */ @Override public void doIndex( SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException { if (!ContextHelpModule.isContextHelpEnabled()) { // don't index context help when disabled return; } long startTime = System.currentTimeMillis(); Set<String> helpPageIdentifyers = ContextHelpModule.getAllContextHelpPages(); Set<String> languages = I18nModule.getEnabledLanguageKeys(); if (log.isDebug()) log.debug( "ContextHelpIndexer helpPageIdentifyers.size::" + helpPageIdentifyers.size() + " and languages.size::" + languages.size()); // loop over all help pages for (String helpPageIdentifyer : helpPageIdentifyers) { String[] identifyerSplit = helpPageIdentifyer.split(":"); String bundleName = identifyerSplit[0]; String page = identifyerSplit[1]; // fxdiff: FXOLAT-221: don't use velocity on images if (page == null || !page.endsWith(".html")) { continue; } // Translator with default locale. Locale is set to each language in the // language iteration below Translator pageTranslator = new PackageTranslator(bundleName, I18nModule.getDefaultLocale()); // Open velocity page for this help page String pagePath = bundleName.replace('.', '/') + ContextHelpModule.CHELP_DIR + page; VelocityContainer container = new VelocityContainer("contextHelpPageVC", pagePath, pageTranslator, null); Context ctx = container.getContext(); GlobalSettings globalSettings = new GlobalSettings() { public int getFontSize() { return 100; } public AJAXFlags getAjaxFlags() { return new EmptyAJAXFlags(); } public ComponentRenderer getComponentRendererFor(Component source) { return null; } public boolean isIdDivsForced() { return false; } }; Renderer renderer = Renderer.getInstance( container, pageTranslator, new EmptyURLBuilder(), null, globalSettings); // Add render decorator with helper methods VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, container, null); ctx.put("r", vrdec); // Add empty static dir url - only used to not generate error messages ctx.put("chelpStaticDirUrl", ""); // Create document for each language using the velocity context for (String langCode : languages) { Locale locale = I18nManager.getInstance().getLocaleOrNull(langCode); String relPagePath = langCode + "/" + bundleName + "/" + page; if (log.isDebug()) log.debug("Indexing help page with path::" + relPagePath); SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext); searchResourceContext.setBusinessControlFor( OresHelper.createOLATResourceableType( ContextHelpModule.class.getSimpleName())); // to match the list of indexer // Create context help document and index now, set translator to current locale pageTranslator.setLocale(locale); Document document = ContextHelpDocument.createDocument( searchResourceContext, bundleName, page, pageTranslator, ctx, pagePath); indexWriter.addDocument(document); } IOUtils.closeQuietly(vrdec); } long indexTime = System.currentTimeMillis() - startTime; if (log.isDebug()) log.debug("ContextHelpIndexer finished in " + indexTime + " ms"); }