extract i18n message properties from gsp and groovy using regex


/ Published in: Groovy
Save to your folder(s)

should be improved


Copy this code and paste it in your HTML
  1. includeTargets << grailsScript("Init")
  2.  
  3. target(main: "The description of the script goes here!") {
  4.  
  5. /*
  6.   def properties = [:]
  7.   def matcher1
  8.   def matcher2
  9.  
  10.   new File(".").eachFileRecurse {
  11.   if (it.file) {
  12.   matcher1 = it.text =~ /code[:=]["'](.*?)["'].*default[:=]\s*["'](.*?)["']/
  13.   matcher1.each {
  14.   try {
  15.   properties[it[1]] = it[2]
  16.   } catch(Exception e) {
  17.   println e
  18.   }
  19.   }
  20.   }
  21.   }
  22.   properties = properties.sort()?.unique()?.join("\n")
  23.   println properties
  24.  
  25.   def oldMap = [:]
  26.   */
  27.  
  28. Map keyMap = new HashMap()
  29.  
  30. def file = new File("misc/messages_ru.properties")
  31. file.eachLine { line ->
  32. String[] pair = line.split('=')
  33. keyMap.put pair[0], pair[1]
  34. // oldMap.put pair[0], pair[1]
  35. }
  36. keyMap.each { entry ->
  37. println "INSERT INTO `message` (`code`, `tenant_id`, `text`, `is_translated`) VALUES ('" + entry.key + "', 4, '" + entry.value + "', 1);"
  38. }
  39.  
  40. /*
  41.   Set oldKeys = oldMap.keySet()
  42.  
  43.   properties.each {
  44.   if(!(it.key in oldKeys)) {
  45.   println "INSERT INTO `message` (`code`, `tenant_id`, `text`) VALUES ('"+it.key + "', '1', '" + it.value+"');"
  46.   println "${it.key}=${it.value}"
  47.   println it.key+"="+it.value
  48.   }
  49.   }
  50.   */
  51. }
  52.  
  53. setDefaultTarget(main)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.