Gradle plugin for generating localized string resources
Gradle plugin for generating localized string resources
This plugin generates Android string resource XML files from CSV or XLS(X) file. Generation has to be invoked as additional gradle task. Java 1.8 is required.
translatableXML attribute
formattedXML attribute
tools:locale
In whichever
build.gradlefile.
groovy plugins { id 'pl.droidsonroids.localization' version '1.0.19' }Note: exact version number must be specified,
+cannot be used as wildcard.
build.gradlefile.
buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.5.3' classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.19' } }
Note:
mavenCentral()and/or
jcenter()repository can be specified,
+can be used as wildcard in version number.
build.gradleof the application, eg:
groovy apply plugin: 'pl.droidsonroids.localization'
Invoke
localizationgradle task. Task may be invoked from commandline or from Android Studio GUI. * from commandline:
./gradlew localization(or
gradlew.bat localizationon Windows) * from GUI: menu
View->Tool Windows->Gradleand double click
localization
Non existent folders will be created. WARNING existing XML files will be overwritten.
The following CSV file:
csv name,default ,pl ,comment ,translatable file,File ,"Plik" ,file label, app ,Application,,,falsewill produce 2 XML files: *
values/strings.xml:
xml File Application*
values-pl/strings.xml:
xml Plik
Add
localizationextension in
build.gradleof particular module.
groovy localization { csvFile=file('translations.csv') OR csvFileURI='https://docs.google.com/spreadsheets/d//export?format=csv' OR csvGenerationCommand='/usr/bin/xlsx2csv translation.xlsx' OR xlsFile=file('translations.xlsx') OR xlsFileURI='https://docs.google.com/spreadsheets/d//export?format=xlsx' }*
csvFileURIand
xlsFileURIcan be any valid URI, not necessarily Google Docs' one *
xlsFileand
xlsFileURIaccepts both XLSX and XLS files. If filename ends with
xlsfile will be treated as XLS, XLSX otherwise
Sources, exactly one of them must be specified: *
csvFile,
xlsFile- CSV/XLS(X) file, Gradle's
file()can be used to retrieve files by path relative to module location or absolute *
csvFileURI,
xlsFileURI- CSV/XLS(X) file URI *
csvGenerationCommand- shell command which writes CSV as text to standard output. Command string should be specified like for Runtime#exec(). Standard error of the command is redirected to the standard error of the process executing Gradle, so it could be seen in the Gradle console.
defaultColumnName- default=
'default', name of the column which corresponds to default localization (
valuesfolder)
nameColumnIndex- default=unset (
nameColumnNameis taken into account), index of the column containing key names (source for the
nameXML attribute)
nameColumnName- default=
'name'(if
nameColumnIndexis not present), name of the column containing key names (source for the
nameXML attribute)
translatableColumnName- default=
'translatable', name of the column containing translatable flags (source for the
translatableXML attribute)
commentColumnName- default=
'comment', name of the column containing comments
formattedColumnName- default=
'formatted', name of the column formatted flags (source for the
formattedXML attribute)
If both
nameColumnIndexand
nameColumnNameare specified exception is thrown.
The following options turn off some character escaping and substitutions, can be useful if you have something already escaped in source: *
escapeApostrophes- default=
true, if set to false apostrophes (
') won't be escaped *
escapeQuotes- default=
true, if set to false double quotes (
") won't be escaped *
escapeNewLines- default=
true, if set to false newline characters won't be escaped *
convertTripleDotsToHorizontalEllipsis- default=
true, if set to false triple dots (
...) won't be converted to ellipsis entity
…*
escapeSlashes- default=
true, if set to false slashes (
\) won't be escaped *
normalizationForm- default=Normalizer.Form.NFC if set to
nullUnicode normalization won't be performed, see javadoc of Normalizer for more details
tagEscapingStrategy- default=
IF_TAGS_ABSENT, defines X(H)TML tag brackets (< and >) escaping strategy possible values:
ALWAYS- brackets are always escaped. E.g. "<" in source becomes "<" in output XML
NEVER- brackets are never escaped. E.g. "<" in source is passed without change to output XML
IF_TAGS_ABSENT- Brackets aren't escaped if text contains tags or CDATA section. E.g. <b>bold</b> will be passed without change, but "if x<4 then…" becomes "if x<4 then…".
tagEscapingStrategyColumnName- default=unset (no column), name of the column containing non-default tag escaping strategy, if cell is non-empty then strategy defined there is used instead of global one
csvStrategy- default=
null(library default strategy, equivalent of CSVStrategy.DEFAULT_STRATEGY)
sheetName- default=, name of the sheet to be processed, only one can be specified, ignored if
useAllSheetsis set to true
useAllSheets- default=
false, if set to true all sheets are processed and
sheetNameis ignored
evaluateFormulas- default=
false, if set to true evaluates formulas in cells
ignorableColumns- default=
[], columns from that list will be ignored during parsing. List should contain column names e.g.
['Section', 'Notes']. Columns containing only empty cells are always ignored.
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 are created. If set to
truethen
allowEmptyTranslationsis 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 of throwing an exception
skipDuplicatedName- default=
false, if set to true then rows with duplicated key names will be ignored instead of throwing an exception. First rows with given key will be taken into account.
defaultLocaleQualifier- language (eg.
es) and optionally region (eg.
es_US) ISO codes of default translations. Default=
null(unset) which effectively means English
en, if set then value will be placed in
tools:localeXML attribute. See Tools Attributes for more information.
Since version 1.0.19 completely empty (effectively empty in case of XLS(X)) rows and columns are ignored. Moreover if qualifier (usually language code) is empty exception is thrown. Previously behavior in such cases was undefined.
Obsolete, non-scoped
localizationplugin id is no longer supported. The only valid id is
pl.droidsonroids.localization.
Versions older than 1.0.7 provided
escapeBoundarySpacesoption, which defaulted to
true. Currently strings are always escaped when corresponding parsed cell contains leading or trailing spaces, but such spaces are stripped by default CSV strategy. So effectively strings are trimmed by default. If you want to include mentioned spaces in output set appropriate
csvStrategy.
MIT License
See LICENSE file.