在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):hyperdevs-team/poeditor-android-gradle-plugin开源软件地址(OpenSource Url):https://github.com/hyperdevs-team/poeditor-android-gradle-plugin开源编程语言(OpenSource Language):Kotlin 98.9%开源软件介绍(OpenSource Introduction):PoEditor Android Gradle Plug-inSimple plug-in that eases importing PoEditor localized strings to your Android project. PurposeThis plug-in super-charges your Android project by providing tasks to download your localized strings from the PoEditor service into you Android project. It also provides a built-in syntax to handle placeholders to enhance the already awesome Android support from PoEditor. Minimum requirements
Setting UpIn your main Groovybuildscript {
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.github.hyperdevs-team:poeditor-android-gradle-plugin:<latest_version>"
}
} Kotlinbuildscript {
repositories {
maven("https://jitpack.io")
}
dependencies {
classpath("com.github.hyperdevs-team:poeditor-android-gradle-plugin:<latest_version>")
}
} How to useApply and configure the plug-in in your app's Groovyapply plugin: "com.android.application"
apply plugin: "com.hyperdevs.poeditor"
poEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
} Kotlinplugins {
id "com.android.application"
id "com.hyperdevs.poeditor"
}
poEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
} The complete attribute list is the following:
After the configuration is done, just run the new
This task will:
Enhanced syntaxThe plug-in enhances your PoEditor experience by adding useful features over your project by adding some custom syntax for certain tasks. VariablesThe plug-in does not parse string placeholders, instead it uses variables with a specific markup to use in PoEditor's string definition: it uses a double braces syntax to declare them. This allows more clarity for translators that use the platform, since it allows them to know what the placeholders really mean and better reuse them in translations. For example, the PoEditor string:
will become, in <string name="welcome_message">Hey %1$s how are you</string> If you need more than one variable in the same string, you can also use ordinals. The string:
will become, <string name="welcome_message">Hey %1$s how are you, today offer is %2$s</string> This way you can change the order of the placeholders depending on the language: The same string, with the following Spanish translation:
will become, in <string name="welcome_message">La oferta del día es %2$s para ti, %1$s</string> Tablet specific stringsYou can mark some strings as tablet specific strings by adding If you define the following string in PoEditor:
The plug-in will create two
<string name="welcome_message">Hey friend</string>
<string name="welcome_message">Hey friend how are you doing today, you look great!</string> Handling multiple flavors and build typesSometimes we might want to import different strings for a given flavor (for example, in white label apps, we could have
different string definitions depending on the brand where they're used). The plugin supports this kind of apps by providing
specific configurations via the Let's see an example configuration: GroovypoEditor {
// Default config that applies to all flavor/build type configurations.
// Also executed when calling 'importPoEditorStrings'
}
android {
// If you have the following flavors...
flavorDimensions 'type'
productFlavors {
free { dimension 'type' }
paid { dimension 'type' }
}
poEditorConfig {
free {
// Configuration for the free flavor, same syntax as the standard 'poEditor' block
}
paid {
// Configuration for the paid flavor, same syntax as the standard 'poEditor' block
}
debug {
// Configuration for the debug build type, same syntax as the standard 'poEditor' block
}
release {
// Configuration for the release build type, same syntax as the standard 'poEditor' block
}
}
} KotlinpoEditor {
// Default config that applies to all flavor/build type configurations.
// Also executed when calling 'importPoEditorStrings'
}
android {
// If you have the following flavors...
flavorDimensions("type")
productFlavors {
register("free") { setDimension("type") }
register("paid") { setDimension("type") }
}
poEditorConfig {
register("free") {
// Configuration for the free flavor, same syntax as the standard 'poEditor' block
}
register("paid") {
// Configuration for the paid flavor, same syntax as the standard 'poEditor' block
}
register("debug") {
// Configuration for the debug build type, same syntax as the standard 'poEditor' block
}
register("release") {
// Configuration for the release build type, same syntax as the standard 'poEditor' block
}
}
} Each flavor ( Now the Handling library modules
You can also apply the plug-in to library modules. Here's an example:
Apply and configure the plug-in in your library's Groovyapply plugin: "com.android.library"
apply plugin: "com.hyperdevs.poeditor"
poEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
} Kotlinplugins {
id "com.android.library"
id "com.hyperdevs.poeditor"
}
poEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
} You can also apply flavor and build type-specific configurations as you would do when setting them up with application modules.
The plug-in will generate the proper tasks needed to import the strings under your module: Disabling task generation for specific configurations
There may be some cases where you only want certain configurations to have a related task.
One of these examples may be to only have tasks for the configured flavors or build types, but you don't want to have the
main Keep in mind that, if you disable the main GroovypoEditor {
// Default config that applies to all flavor/build type configurations.
// Also executed when calling 'importPoEditorStrings'
enabled = false // This'll disable task generation for every configuration.
apiToken = "your_common_api_token"
}
android {
flavorDimensions 'type'
productFlavors {
free { dimension 'type' }
paid { dimension 'type' }
}
poEditorConfig {
free {
// Specific configuration for the free flavor
enabled = true // Explicitly enabled since the main block disables task generation
projectId = 12345
}
paid {
// Specific configuration for the paid flavor
enabled = true // Explicitly enabled since the main block disables task generation
projectId = 54321
}
}
} KotlinpoEditor {
// Default config that applies to all flavor/build type configurations.
// Also executed when calling 'importPoEditorStrings'
enabled = false // This'll disable task generation for every configuration.
apiToken = "your_common_api_token"
}
android {
// If you have the following flavors...
flavorDimensions("type")
productFlavors {
register("free") { setDimension("type") }
register("paid") { setDimension("type") }
}
poEditorConfig {
register("free") {
// Specific configuration for the free flavor
enabled = true // Explicitly enabled since the main block disables task generation
projectId = 12345
}
register("paid") {
// Specific configuration for the paid flavor
enabled = true // Explicitly enabled since the main block disables task generation
projectId = 54321
}
}
} Handling tags
You can also select the tags that you want strings to be downloaded from PoEditor, based on the tags that you defined in your PoEditor project. GroovypoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
tags = ["tag1", "tag2"] // Download strings with the specified tags
} KotlinpoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
tags = listOf("tag1", "tag2")
} Overriding default values folder for specific languages
Sometimes you may want to override the default You can add the parameter GroovypoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
languageValuesOverridePathMap = [
"free" : "${rootDir}/app/src/free/res/values",
"paid" : "${rootDir}/app/src/paid/res/values"
]
} KotlinpoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
languageValuesOverridePathMap = mapOf(
"free" to "${rootDir}/app/src/free/res/values",
"paid" to "${rootDir}/app/src/paid/res/values"
)
} Tweaking minimum translation percentages
The plug-in also allows setting a minimum percentage of translated strings to download languages. This is set-up with the GroovypoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
minimumTranslationPercentage = 85
} KotlinpoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
minimumTranslationPercentage = 85
} Handling filters
The plug-in also allows setting filters for narrowing down the type of terms to be downloaded.
Supported filters are defined by the POEditor API and currently include: GroovypoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
filters = ["translated", "not_fuzzy"]
} KotlinpoEditor {
apiToken = "your_api_token"
projectId = 12345
defaultLang = "en"
filters = listOf("translated", "not_fuzzy")
} iOS alternativeIf you want a similar solution for your iOS projects, check this out: poeditor-parser-swift Authors & Collaborators
AcknowledgementsThe work in this repository up to April 28th, 2021 was done by bq. Thanks for all the work!! LicenseThis project is licensed under the Apache Software License, Version 2.0.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论