Skip to content

Gradle plugin to push and pull translations on a Phrase project

License

Notifications You must be signed in to change notification settings

Decathlon/gradle-plugin-phraseapp

Repository files navigation

PhraseApp Plugin

client module is a java library which allows you to communicate with the PhraseApp API.

api-gradle is the Gradle plugin which have the client as dependency.

Tasks

  • phraseClean starts task to clean all local resources.
  • phraseDownload starts task to download string resources.
  • phraseUpload starts task to upload a string resource.
  • phraseCheck starts task to apply all phrase checks (see bellow).
  • phraseDuplicateKeysCheck starts task to check if there are duplicate keys in res folder.
  • phrasePluralsCheck starts task to check if plural strings are well formatted.
  • phrasePlaceHolderCheck starts task to check if placeholders aren't removed in other locale string resource folders.

Parameters

When you want to use this plugin, you need to specify some mandatory parameters and you can customize the execution of the parameters with optional parameters.

Mandatory

Kotlin

import phrase.phrase

apply {
    plugin("com.decathlon.phrase")
}

phrase {
    authToken.set("token <token>")
    projectId.set("<id>>")
    mainLocaleId.set("<id>>")
    resFolders.set(arrayListOf("path_to_res_folder"))
}

Groovy

apply plugin: 'com.decathlon.phrase'

phrase {
    // Authentication token used to communicate with PhraseApp.
    authToken = 'token <token>'

    // Project id of your PhraseApp project.
    projectId = '<id>'

    // Identifier of the default locale.
    mainLocaleId = '<id>'

    // Target locations to print all translations from PhraseApp.
    resFolders = ['<path_to_res_folder>']
}

If one of your resource folder have multiple strings files, you can use resFoldersMultiStrings property:

Kotlin

phrase {
    resFoldersMultiStrings.set(
        mapOf(
            "${project.projectDir.absolutePath}/src/main/res" 
                    to arrayListOf("strings.xml, strings_2.xml", "strings_3.xml")
        )
    )
}

Groovy

def resFolders = [:]
resFolders.put(
        project.projectDir.absolutePath + '/src/main/res',
        [ "strings.xml", "strings_2.xml", "strings_3.xml" ]
)

phrase {
    // mandatory fields...

    resFoldersMultiStrings = resFolders
}

Optional

Kotlin

phrase {
    // mandatory fields...

    // Generate the output adapted to the platform. Can be 'ANDROID', soon 'IOS' and 'FLUTTER'
    platform.set(phraseapp.internal.Platform.ANDROID)

    // Download the default locale from PhraseApp and write it on the disk with the download task. Default: false.
    overrideDefaultFile.set(false)

    // phrase base url to consume phrase API. Default value: https://api.phraseapp.com/api
    phraseBaseUrl.set("<base_url>")

    // If you aren't interested by the json file generated by the download task, you don't need to fill this property.
    outputLocation.set("<path_to_location>")

    // If you want to convert a PhraseApp locale to your custom locale, add it into this map.
    // For example: ['zh-CN': 'zh-Hans']
    exceptions.set(mapOf())

    // If you want to convert all placeholder into your platform's placeholder, switch this parameter to true. Default: false.
    placeholder.set(false)

    // If you want to specify your custom locale in the name of a PhraseApp locale, you can specify the regex of your PhraseApp locale name here. Default: .+_([a-z]{2}-[A-Z]{2})
    localeNameRegex.set("<string>")

    // If you want to omit translation comments imported by the download task. Default: false
    ignoreComments.set(false)

    // If you want to import only some locales during the download task. Skip param to fetch all locales.
    // For example: ['cs-CZ', 'fr-FR', 'de-DE']
    allowedLocaleCodes.set(listOf("<locale_code>"))
}

Groovy

phrase {
    // mandatory fields...

    // Generate the output adapted to the platform. Can be 'ANDROID', soon 'IOS' and 'FLUTTER'
    platform = '<platform>'

    // Download the default locale from PhraseApp and write it on the disk with the download task. Default: false.
    overrideDefaultFile = false

    // Phrase base url to consume phrase API. Default value: https://api.phraseapp.com/api
    phraseBaseUrl = "<base_url>"

    // If you aren't interested by the json file generated by the download task, you don't need to fill this property.
    outputLocation = "<path_to_location>"

    // If you want to convert a PhraseApp locale to your custom locale, add it into this map.
    // For example: ['zh-CN': 'zh-Hans']
    exceptions = [:]

    // If you want to convert all placeholder into your platform's placeholder, switch this parameter to true. Default: false.
    placeholder = false

    // If you want to specify your custom locale in the name of a PhraseApp locale, you can specify the regex of your PhraseApp locale name here. Default: .+_([a-z]{2}-[A-Z]{2})
    localeNameRegex = "<string>"

    // If you want to omit translation comments imported by the download task. Default: false
    ignoreComments = false

    // If you want to import only some locales during the download task. Skip param to fetch all locales.
    // For example: ['cs-CZ', 'fr-FR', 'de-DE']
    allowedLocaleCodes = ["<locale_code>"]
}

Download

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("com.decathlon.phrase:phrase-gradle-plugin:<last-version>")
    }
}

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2021 Decathlon.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.