Skip to content

Commit

Permalink
Merge pull request #36 from Cryosleeper/cryo-defaults
Browse files Browse the repository at this point in the history
Cryo defaults
  • Loading branch information
koral-- authored Mar 2, 2018
2 parents ec5bd86 + 4add027 commit f0f3e77
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ contain column names eg. `['Section', 'Notes']`
* `allowNonTranslatableTranslation` - default=`false`, if set to true resources marked
non-translatable but translated are permitted
* `allowEmptyTranslations` - default=`false`, if set to true then empty values are permitted
* `handleEmptyTranslationsAsDefault` - default=`false`, if set to true empty values do not result in entries in non-default languages, i.e. no empty XML entries for non-default languages being created. If set to `true` then `allowEmptyTranslations` is ignored for all but default language
* `outputFileName` - default=`strings.xml`, XML file name (with extension) which should be generated as an output
* `outputIndent` - default=` `(two spaces), character(s) used to indent each line in output XML files
* `skipInvalidName` - default=`false`, if set to true then rows with invalid key names will be ignored instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.text.Normalizer
* @author koral--
*/
class ConfigExtension {
boolean handleEmptyTranslationsAsDefault = false
boolean allowNonTranslatableTranslation = false
boolean allowEmptyTranslations = false
boolean escapeApostrophes = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class ParserEngine {
if (value.empty) {
if (!translatable && builder.mQualifier != mConfig.defaultColumnName)
continue
if (mConfig.handleEmptyTranslationsAsDefault && builder.mQualifier != mConfig.defaultColumnName)
continue
if (!mConfig.allowEmptyTranslations)
throw new IllegalArgumentException("$name is not translated to locale $builder.mQualifier, row #${i + 1}")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ class ParseXLSXTest extends LocalizationPluginTestBase {
}
}

@Test
void testXlsxFileWithDefaults() {
def name = 'valid_with_defaults.xlsx'

ConfigExtension config = new ConfigExtension()
config.xlsFileURI = getClass().getResource(name).toString()
config.handleEmptyTranslationsAsDefault = true
config.allowEmptyTranslations = true
config.skipInvalidName = true
config.skipDuplicatedName = true
config.defaultColumnName = 'EN'
config.nameColumnName = 'Android'
config.ignorableColumns.add('WinPhone')
config.ignorableColumns.add('iOS')
config.ignorableColumns.add('END')
config.defaultLocaleQualifier = 'en'
config.useAllSheets = true

def resDir = parseTestFile(config)

resDir.traverse(type: FileType.FILES) {
def filePath = it.path.replace(resDir.path, '')
def expectedFileURL = getClass().getResource("parsed_valid_xlsx/$filePath")
def diff = DiffBuilder.compare(Input.fromFile(it))
.withTest(Input.fromURL(expectedFileURL))
.ignoreWhitespace()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes))
.checkForSimilar()
.build()
assertThat(diff.hasDifferences()).as('file: %s is different than expected %s', filePath, diff.toString()).isFalse()
}
}

@Test
void testXlsxURI() {
ConfigExtension config = new ConfigExtension()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="file">Plik</string><!-- file label -->
<plurals name="cow">
<item quantity="other">krowy</item><!-- comment -->
<item quantity="one">krowa</item>
</plurals>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
<string name="app" translatable="false">Application</string>
<string name="file">File</string><!-- file label -->
<string name="percent" translatable="false" formatted="false">%d %s</string>
<string name="empty"></string>
<plurals name="cow">
<item quantity="other">cows</item><!-- comment -->
<item quantity="one">cow</item>
</plurals>
<string-array name="days" translatable="false">
<item>monday</item>
<item>tuesday</item>
<item>wednesday</item>
</string-array>
</resources>
Binary file not shown.

0 comments on commit f0f3e77

Please sign in to comment.