Skip to content

Commit 98985f6

Browse files
authored
Use default language strings in the XML Processor if a translation is missing (#45)
1 parent 9476c48 commit 98985f6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lyricist-processor-xml/src/main/java/cafe/adriel/lyricist/processor/xml/internal/LyricistXmlSymbolProcessor.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ internal class LyricistXmlSymbolProcessor(
5757
?.let { writeStringsClassFile(fileName, stringsName, it, strings.keys) }
5858
?: logger.error("Default language tag not found")
5959

60+
val defaultStrings = strings[config.defaultLanguageTag].orEmpty()
61+
6062
strings.forEach { (languageTag, strings) ->
61-
writeStringsPropertyFile(fileName, languageTag, strings)
63+
val stringsWithMissingTranslations = if (languageTag != config.defaultLanguageTag) {
64+
val notTranslatedStrings = defaultStrings.filterKeys { key -> !strings.containsKey(key) }
65+
strings + notTranslatedStrings
66+
} else {
67+
strings
68+
}
69+
70+
writeStringsPropertyFile(fileName, languageTag, stringsWithMissingTranslations)
6271
}
6372
}
6473

sample-xml/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<string name="simple">Hello "world"</string>
33
<string name="params">Parameters: %1$s, %2$d, %s, %d</string>
44
<string name="replacement">@string/simple</string>
5+
<string name="missing_translation">Missing translation</string>
56

67
<string-array name="array">
78
<item>Avocado</item>

0 commit comments

Comments
 (0)