Skip to content

greencode-cz/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

  • phraseappClean starts task to clean all local resources.
  • phraseappCheck starts task to check if remote string resources are well formed.
  • phraseappDownload starts task to download string resources.
  • phraseappUpload starts task to upload a string resource.

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 phraseapp.phraseapp

apply {
    plugin("cz.greencode.phraseapp")
}

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

Groovy

apply plugin: 'cz.greencode.phraseapp'

phraseapp {
    // 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

phraseapp {
    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" ]
)

phraseapp {
    // mandatory fields...

    resFoldersMultiStrings = resFolders
}

Optional

Kotlin

phraseapp {
    // 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)

    // Phraseapp base url to consume Phraseapp API. Default value: https://api.phraseapp.com/api
    phraseappBaseUrl.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>"))

    // Do not remove keys in the default locale that are not defined in the PhraseApp during the download task.
    // By default false.
    dontDeleteKeys.set(false)
}

Groovy

phraseapp {
    // 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

    // Phraseapp base url to consume Phraseapp API. Default value: https://api.phraseapp.com/api
    phraseappBaseUrl = "<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>"]

    // Do not remove keys in the default locale that are not defined in the PhraseApp during the download task.
    // By default false.
    dontDeleteKeys = false
}

Download

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("cz.greencode: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.

About

Gradle plugin to push and pull translations on a Phrase project

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%