private String translateCategories(
String text, boolean translate) throws APIException {
if (!translate) {
return text;
}
Namespace categoryNamespace = getWikipedia().getWikiConfiguration().getNamespace(Namespace.CATEGORY);
if (categoryNamespace == null) {
return text;
}
PageAnalysis analysis = page.getAnalysis(text, true);
Collection<PageElementCategory> categories = analysis.getCategories();
Map<String, String> interwikis = new HashMap<String, String>();
StringBuilder newText = new StringBuilder();
int lastPosition = 0;
for (PageElementCategory category : categories) {
String categoryName = category.getName();
String fullCategoryName = categoryNamespace.getCanonicalTitle() + ":" + categoryName;
setText(GT._("Retrieving interwiki for {0}", fullCategoryName));
String translated = null;
if (!interwikis.containsKey(categoryName)) {
translated = getLanguageLink(fullCategoryName);
interwikis.put(categoryName, translated);