Translations Diff Tool Snippet
This application looks for all calls to msg.get(...) in the wiki and warns you if the used keys aren't present in the translation pageCode
1.1 Translations diff tool
#info("This application looks for all calls to msg.get in the wiki and warns you if the used keys aren't present in the translation page")
<form action="">
Your translation page : <input type='text' name='tr_name' /><br/>
Languages you want to check ~~(optional, comma separated)~~ : <input type='text' name='tr_list' /><br/>
<input type='submit' value='Search for untranslated keys' /><br/>
</form>
<%
import java.util.TreeSet
import java.util.ArrayList
import java.util.Collections
import java.util.regex.Matcher
import java.util.regex.Pattern
if (request.get("tr_name")) {
String tr_name = request.get("tr_name")
String excluded_spaces = "Utiyls"
// Get translations document
tr_doc = xwiki.getDocument(tr_name)
// Get translations list
Map translations = new HashMap<String,String>()
List available_fr;
if (request.get("tr_list")) {
available_tr = Arrays.asList(available_tr = request.get("tr_list").split(","))
} else {
available_tr = tr_doc.getTranslationList()
}
for (lang in available_tr) {
translations.put(lang, tr_doc.getTranslatedContent(lang))
}
plist = xwiki.searchDocuments("where 1=1 and doc.fullName != '" + tr_name + "' and doc.web != '" + excluded_spaces + "' order by doc.fullName")
clist = new ArrayList()
Pattern p = Pattern.compile(/msg\.get\(\"[^\"^\$]+\"\)/);
ArrayList results = new ArrayList()
for (item in plist) {
content = xwiki.getDocument(item).getContent()
Matcher m = p.matcher(content)
boolean b = m.find()
while (b) {
String match = m.group()
// retrieve msg.get key
String key = match.substring(9, match.size() - 2)
// go to next result
b = m.find()
// push result in results list
if (!results.contains(key)) {
results.add(key)
}
}
}
// sort results
Collections.sort(results)
// display missing translations in all available languages
for (current_lang in available_tr) {
println ("1.1 Missing translations in : " + current_lang)
String tr_content = translations.get(current_lang)
for (current_key in results) {
if (!tr_content.contains(current_key + "=")) {
println("" + current_key + "<br/>")
}
}
}
}
%>Result
Missing translations in : fr
confirmdelattachment confirmdelwikipageMissing translations in : en
changelogo confirmdelattachment
Version 2.1 last modified by VincentMassol on 09/12/2007 at 15:28
Document data
Attachments:
No attachments for this document
Comments: 0