Return to Snippet

Revision: 50859
at September 6, 2011 20:54 by skurt


Initial Code
includeTargets << grailsScript("Init")

target(main: "The description of the script goes here!") {

  /*
  def properties = [:]
  def matcher1
  def matcher2
  
  new File(".").eachFileRecurse {
      if (it.file) {
        matcher1 = it.text =~ /code[:=]["'](.*?)["'].*default[:=]\s*["'](.*?)["']/
        matcher1.each {
          try {
            properties[it[1]] = it[2]
          } catch(Exception e) {
            println e
          }
        }
      }
  }
  properties = properties.sort()?.unique()?.join("\n")
  println properties

  def oldMap = [:]
  */
  
  Map keyMap = new HashMap()
  
  def file = new File("misc/messages_ru.properties")
  file.eachLine { line ->
    String[] pair = line.split('=')
    keyMap.put pair[0], pair[1]
    // oldMap.put pair[0], pair[1]
  }
  keyMap.each { entry ->
    println "INSERT INTO `message` (`code`, `tenant_id`, `text`, `is_translated`) VALUES ('" + entry.key + "', 4, '" + entry.value + "', 1);"
  }
  
  /*
  Set oldKeys = oldMap.keySet()
  
  properties.each {
    if(!(it.key in oldKeys)) {
      println "INSERT INTO `message` (`code`, `tenant_id`, `text`) VALUES ('"+it.key + "', '1', '" + it.value+"');"
      println "${it.key}=${it.value}"
      println it.key+"="+it.value
    }
  }
  */
}

setDefaultTarget(main)

Initial URL

                                

Initial Description
should be improved

Initial Title
extract i18n message properties from gsp and groovy using regex

Initial Tags

                                

Initial Language
Groovy