GithubHelp home page GithubHelp logo

sundarsan / android-gradle-localization-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from koral--/android-gradle-localization-plugin

0.0 1.0 0.0 1.14 MB

Gradle plugin for generating localized string resources

License: MIT License

Groovy 100.00%

android-gradle-localization-plugin's Introduction

android-gradle-localization-plugin

Maven Central Bintray Android Arsenal Build Status

Gradle plugin for generating localized string resources

Overview

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.

##Supported features

  • string arrays - see Arrays
  • plurals - see Plurals
  • non-translatable resources - translatable XML attribute
  • auto-escaping double quotes, apostrophes and newlines
  • auto-quoting leading and trailing spaces
  • syntax validation - duplicated, empty, invalid names detection
  • comments
  • formatted strings - formatted XML attribute
  • default locale specification - tools:locale

Applying plugin

Gradle 2.1+

In whichever build.gradle file.

plugins {
  id 'pl.droidsonroids.localization' version '1.0.9'
}

Note: exact version number must be specified, + cannot be used as wildcard.

All versions of Gradle

  1. Add dependency to the top-level build.gradle file.
 buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.8'
    }
}

Note: mavenCentral() and/or jcenter() repository can be specified, + can be used as wildcard in version number. 2. Apply plugin and add configuration to build.gradle of the application, eg:

apply plugin: 'pl.droidsonroids.localization'

Usage

Invoke localization gradle task. Task may be invoked from commandline or from Android Studio GUI.

  • from commandline: ./gradlew localization (or gradlew.bat localization on Windows)
  • from GUI: menu View->Tool Windows->Gradle and double click localization

Non existent folders will be created. WARNING existing XML files will be overwritten.

##Example The following CSV file:

name,default    ,pl       ,comment   ,translatable
file,File       ,"Plik"   ,file label,
app ,Application,,,false

will produce 2 XML files:

  • values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
  <string name="file">File</string><!-- file label -->
  <string name="app" translatable="false">Application</string>
</resources>
  • values-pl/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
  <string name="file">Plik</string><!-- file label -->
</resources>

##Configuration Add localization extension in build.gradle of particular module.

localization
    {
        csvFile=file('translations.csv')
        OR
        csvFileURI='https://docs.google.com/spreadsheets/d/<key>/export?format=csv'
        OR
        csvGenerationCommand='/usr/bin/xlsx2csv translation.xlsx'
        OR
        xlsFile=file('translations.xlsx')
        OR
        xlsFileURI='https://docs.google.com/spreadsheets/d/<key>/export?format=xlsx'
    }
  • csvFileURI and xlsFileURI can be any valid URI, not necessarily Google Docs' one
  • xlsFile and xlsFileURI accepts both XLSX and XLS files. If filename ends with xls file 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.

Spreadsheet format:

  • defaultColumnName - default='default', name of the column which corresponds to default localization (values folder)
  • nameColumnName - default='name', name of the column containing key names (source for the name XML attribute)
  • translatableColumnName - default='translatable', name of the column containing translatable flags (source for the translatable XML attribute)
  • commentColumnName - default='comment', name of the column containing comments
  • formattedColumnName - default='formatted', name of the column formatted flags (source for the formatted XML attribute)

The following options turn off some character escaping and substitutions, can be useful if you have something already escaped in CSV:

  • 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 &#8230
  • escapeSlashes - default=true, if set to false slashes (\) won't be escaped
  • normalizationForm - default=Normalizer.Form.NFC if set to null Unicode 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. Eg. "<" in source becomes "&lt;" in output XML
  • NEVER - brackets are never escaped. Eg. "<" in source is passed without change to output XML
  • IF_TAGS_ABSENT - Brackets aren't escaped if text contains tags. Eg. <b>bold</b>} will be passed without change, but "if x<4 then…" becomes "if x&lt;4 then…". See JSoup - library used to detect tags

CSV format:

XLS(X) format:

  • sheetName - default=<name of the first sheet>, name of the sheet to be parsed, only one can be specified

Advanced options:

  • ignorableColumns - default=[], columns from that list will be ignored during parsing. List should 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
  • 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:locale XML attribute. See Tools Attributes for more information.

Migration from versions <1.0.7:

Versions older than 1.0.7 provided escapeBoundarySpaces option, which defaulted to true. Currently strings are always escaped when corresponding parsed ceil 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.

##License

MIT License
See LICENSE file.

android-gradle-localization-plugin's People

Contributors

koral-- avatar ihrthk avatar michallankof avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.