0

I've got i18n messages files with translations. The problem is in that some languages (Italian for example) use single quotes in some words. I want to run some script (may be as a gradle.build task) to replace single quotes with double quotes. I paste following code into my build.gradle.kts file

task("replaceSingleQuotes") {
    doLast {
        ant.ReplaceRegExp(match:'\'', replace:'\'\'', flags:'g', byline:false) {
            fileset(dir: 'src/main/resources/i18n/', includes: '*')
        }
    }
}

The first problem is in that now my project failed to configure with following errors:

e: build.gradle.kts:139:32: Expecting ')'e: D:\Sources\delivery-backend\build.gradle.kts:139:33: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:140:15: Expecting ')'
e: build.gradle.kts:140:17: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:154:13: Expecting an element
e: build.gradle.kts:155:28: Expecting ')'
e: build.gradle.kts:155:29: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:156:20: Expecting ')'
e: build.gradle.kts:156:22: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:139:13: Unresolved reference: ReplaceRegExp
e: build.gradle.kts:139:27: Unresolved reference: match
e: build.gradle.kts:140:4: Unresolved reference: fileset
e: build.gradle.kts:140:12: Function invocation 'dir(...)' expected
e: build.gradle.kts:140:12: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public inline fun SourceSetOutput.dir(dir: Any, vararg options: Pair<String, Any?>): Unit defined in org.gradle.kotlin.dsl
e: build.gradle.kts:154:1: Function invocation 'task(...)' expected
e: build.gradle.kts:154:1: None of the following functions can be called with the arguments supplied: 
public abstract fun task(p0: String!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: String!, p1: Closure<(raw) Any!>!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: String!, p1: Action<in Task!>!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: (Mutable)Map<String!, *>!, p1: String!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: (Mutable)Map<String!, *>!, p1: String!, p2: Closure<(raw) Any!>!): Task! defined in org.gradle.api.Project
e: build.gradle.kts:155:9: Unresolved reference: replaceregexp
e: build.gradle.kts:155:23: Unresolved reference: match
e: build.gradle.kts:156:9: Unresolved reference: fileset
e: build.gradle.kts:156:17: Function invocation 'dir(...)' expected
e: build.gradle.kts:156:17: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public inline fun SourceSetOutput.dir(dir: Any, vararg options: Pair<String, Any?>): Unit defined in org.gradle.kotlin.dsl

The second problem, I guess, is in that every time my task executed it'll add more and more double quotes. Thus, two questions here: how to make my project configure with this task and how to change regex to match only single quote?

alanT
  • 15
  • 3
rudolfninja
  • 467
  • 7
  • 24
  • 1
    One thing to consider is that you probably don't want to edit the files in place in the source directory. That is one of the reasons you are getting the double double quotes. A better idea might be to work on the task that copies the files to the build directory and make the changes on their way to the build directory. – Jeff Scott Brown Mar 01 '22 at 22:23

1 Answers1

0

using match with "([^\\])'" and replace "\1\\\\'" should work

as suggested here https://stackoverflow.com/a/60127123

user1998494
  • 614
  • 7
  • 7