Skip to content

Commit

Permalink
0.2.5 - Adds saveDefLangDuplicate field
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickpulver committed Feb 25, 2022
1 parent 8754eaf commit bd4fed7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 65 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
dependencies {
//…
classpath 'com.appswithlove.loco:loco:0.2.4'
classpath 'com.appswithlove.loco:loco:0.2.5'
}
}
```
Expand Down Expand Up @@ -59,6 +59,7 @@ Loco {
fallbackLang = 'en' // optional;, fallback language when not present
orderByAssetId = false // optional; order assets alphabetically by Asset ID
status = "translated" // optional; filter assets by status. Negate values by prefixing with !. e.g. "translated", or "!fuzzy".
saveDefLangDuplicate: false // default: defLang will only be saved in values folder. If set to true, the defLang will also be saved in the specific folder (such as values-en)
}
```

Expand Down Expand Up @@ -105,6 +106,7 @@ LocoMultiple {
fallbackLang: 'en', // optional; fallback language when not present
orderByAssetId: false // optional; order assets alphabetically by Asset ID
status: "translated" // optional; filter assets by status. Negate values by prefixing with !. e.g. "translated", or "!fuzzy".
saveDefLangDuplicate: false, // default: defLang will only be saved in values folder. If set to true, the defLang will also be saved in the specific folder (such as values-en)
it // Important: Note the explicit mention of it as the return value
),
new LocoConfig().with {
Expand All @@ -119,6 +121,7 @@ LocoMultiple {
fallbackLang: 'en', // optional;, fallback language when not present
orderByAssetId: false // optional; order assets alphabetically by Asset ID
status: "translated" // optional; filter assets by status. Negate values by prefixing with !. e.g. "translated", or "!fuzzy".
saveDefLangDuplicate: false, // default: defLang will only be saved in values folder. If set to true, the defLang will also be saved in the specific folder (such as values-en)
it // Important: Note the explicit mention of it as the return value
)
]
Expand Down Expand Up @@ -162,7 +165,7 @@ buildscript {
...
}
dependencies{
classpath 'com.appswithlove.loco:loco:0.2.4'
classpath 'com.appswithlove.loco:loco:0.2.5'
...
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
kotlin_version = '1.4.21'
kotlin_version = '1.5.30'
}
repositories {
maven {
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/com/appswithlove/loco/LocoConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class LocoConfig {
def fallbackLang = null
def orderByAssetId = false
def status
def saveDefLangDuplicate = false
}
34 changes: 20 additions & 14 deletions src/main/groovy/com/appswithlove/loco/TaskUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ class TaskUtils {
text = text.replaceAll(locoConfig.placeholderPattern, "%s")
}

def appendix = ""
if (lang != locoConfig.defLang) {
// Certain languages have multiple regions (e.g., Spanish (Spain) and Spanish (Mexico)),
// and their folder titles have an additional "r" in them.
if (lang.contains("-")) {
lang = lang.replace("-", "-r")
}

appendix = "-$lang"
// Certain languages have multiple regions (e.g., Spanish (Spain) and Spanish (Mexico)),
// and their folder titles have an additional "r" in them.
if (lang.contains("-")) {
lang = lang.replace("-", "-r")
}
def appendix = "-$lang"

// In some rare cases, the encoding parameter in the xml-tag is 'utf8' instead of 'utf-8'.
// todo: if there's a better, more reliable solution to handle this, please submit a PR.
Expand All @@ -62,14 +58,24 @@ class TaskUtils {
text = text.replace(wrongXmlString, expectedXmlString)
}

def directory = new File("${locoConfig.resDir}/values$appendix/")
if (!directory.exists()) {
directory.mkdir()
if (lang == locoConfig.defLang) {
saveFile(locoConfig, text)
}

def file = new File(directory.absolutePath + "/" + locoConfig.fileName + ".xml")
file.write(text)
if (lang != locoConfig.defLang || locoConfig.saveDefLangDuplicate) {
saveFile(locoConfig, text, appendix)
}
}
}
}

private static void saveFile(LocoConfig locoConfig, String text, String appendix = "") {
def directory = new File("${locoConfig.resDir}/values$appendix/")
if (!directory.exists()) {
directory.mkdir()
}

def file = new File(directory.absolutePath + "/" + locoConfig.fileName + ".xml")
file.write(text)
}
}
48 changes: 0 additions & 48 deletions src/test/groovy/com/appswithlove/loco/PluginSpec.groovy

This file was deleted.

0 comments on commit bd4fed7

Please sign in to comment.