move-l10n.groovy 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Usage: groovy move-l10n.groovy hudson/model/OldClass/old-view jenkins/model/NewClass/new-view 'Some\ Translatable\ Text'
  2. // (The new view may be given as '-' to simply delete the key.)
  3. def oldview = args[0]
  4. def newview = args[1]
  5. def key = args[2]
  6. def scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
  7. def resDir = new File(scriptDir, 'src/main/resources')
  8. def basename = new File(resDir, oldview).name
  9. for (p in new File(resDir, oldview).parentFile.listFiles()) {
  10. def n = p.name
  11. if (n == "${basename}.properties" || n.startsWith("${basename}_") && n.endsWith(".properties")) {
  12. def lines = p.readLines('ISO-8859-1')
  13. // TODO does not handle multiline values correctly
  14. def matches = lines.findAll({it.startsWith("${key}=")})
  15. if (!matches.isEmpty()) {
  16. lines.removeAll(matches)
  17. p.withWriter('ISO-8859-1') {out ->
  18. lines.each {line -> out.writeLine(line)}
  19. }
  20. if (newview == '-') {
  21. println("deleting ${matches.size()} matches from ${n}")
  22. } else {
  23. def nue = new File(resDir, newview + n.substring(basename.length()))
  24. println("moving ${matches.size()} matches from ${n} to ${nue.name}")
  25. // TODO if the original lacked a trailing newline, this will corrupt previously final key
  26. nue.withWriterAppend('ISO-8859-1') {out ->
  27. matches.each {line -> out.writeLine(line)}
  28. }
  29. }
  30. }
  31. }
  32. }