Skip to content

Commit 935520c

Browse files
authored
Add lazy property configuration (#71)
1 parent 835b5d5 commit 935520c

File tree

6 files changed

+211
-63
lines changed

6 files changed

+211
-63
lines changed

.idea/compiler.xml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
### Security
3535
- No security issues fixed!
3636

37+
## [4.1.0] - 2023-11-26
38+
### Changed
39+
- Allow PoEditor importing task lazy configuration.
40+
3741
## [4.0.0] - 2023-11-07
3842
### Changed
3943
- BREAKING CHANGE: Bump Gradle version to 8 and AGP version to 8.1.2.
@@ -483,7 +487,8 @@ res_dir_path -> resDirPath
483487
### Added
484488
- Initial release.
485489

486-
[Unreleased]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/4.0.0...HEAD
490+
[Unreleased]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/4.1.0...HEAD
491+
[4.1.0]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/4.0.0...4.1.0
487492
[4.0.0]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.2...4.0.0
488493
[3.4.2]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.1...3.4.2
489494
[3.4.1]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.0...3.4.1

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,25 @@ poEditor {
579579

580580
</details>
581581

582+
## Creating extra PoEditor tasks
583+
> Requires version 4.1.0 of the plug-in
584+
585+
You can create extra PoEditor tasks to import strings for other projects, for example. You can do so by adding this to
586+
your `build.gradle(.kts)` file:
587+
<details><summary>Kotlin</summary>
588+
589+
```kotlin
590+
tasks.register("importCustomPoEditorStrings", ImportPoEditorStringsTask::class.java) {
591+
description = "Imports custom strings from POEditor."
592+
group = "strings"
593+
594+
apiToken = "another_token_from_a_different_project"
595+
projectId = 12345
596+
resFileName = "strings_custom"
597+
}
598+
```
599+
600+
</details>
582601

583602
## iOS alternative
584603
If you want a similar solution for your iOS projects, check this out: [poeditor-parser-swift](https://github.com/hyperdevs-team/poeditor-parser-swift)

src/main/kotlin/com/hyperdevs/poeditor/gradle/PoEditorPlugin.kt

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.android.build.gradle.LibraryExtension
2525
import com.android.build.gradle.LibraryPlugin
2626
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
2727
import com.hyperdevs.poeditor.gradle.ktx.registerNewTask
28-
import com.hyperdevs.poeditor.gradle.network.api.OrderType
2928
import com.hyperdevs.poeditor.gradle.tasks.ImportPoEditorStringsTask
3029
import com.hyperdevs.poeditor.gradle.utils.*
3130
import org.gradle.api.NamedDomainObjectContainer
@@ -44,24 +43,11 @@ typealias ConfigName = String
4443
class PoEditorPlugin : Plugin<Project> {
4544
override fun apply(project: Project) {
4645
val mainConfigName = "main"
47-
val mainResourceDirectory = getResourceDirectory(project, mainConfigName)
4846

4947
// Add the 'poEditorPlugin' extension object in the project,
5048
// used to pass parameters to the main PoEditor task
5149
val mainPoEditorExtension: PoEditorPluginExtension = project.extensions
52-
.create<PoEditorPluginExtension>(DEFAULT_PLUGIN_NAME, project.objects, mainConfigName).apply {
53-
enabled.convention(true)
54-
defaultLang.convention("en")
55-
defaultResPath.convention(mainResourceDirectory.asFile.absolutePath)
56-
filters.convention(emptyList())
57-
order.convention(OrderType.NONE.name.toLowerCase())
58-
tags.convention(emptyList())
59-
languageValuesOverridePathMap.convention(emptyMap())
60-
minimumTranslationPercentage.convention(-1)
61-
resFileName.convention("strings")
62-
unquoted.convention(false)
63-
unescapeHtmlTags.convention(true)
64-
}
50+
.create<PoEditorPluginExtension>(DEFAULT_PLUGIN_NAME, project.objects, mainConfigName)
6551

6652
// Add flavor and build-type configurations if the project has the "com.android.application" plugin
6753
project.plugins.withType<AppPlugin> {
@@ -182,8 +168,10 @@ class PoEditorPlugin : Plugin<Project> {
182168
project.registerNewTask<ImportPoEditorStringsTask>(
183169
mainPoEditorTaskName,
184170
mainPoEditorTaskDescription,
185-
PLUGIN_GROUP,
186-
arrayOf(mainPoEditorExtension))
171+
PLUGIN_GROUP
172+
) {
173+
configureTask("main", mainPoEditorExtension)
174+
}
187175
}
188176
}
189177
}
@@ -205,8 +193,7 @@ class PoEditorPlugin : Plugin<Project> {
205193
project.tasks.findByName(configTaskName) ?: run {
206194
val rawConfigExtension = configsExtensionContainer.findByName(configName)?.also {
207195
// Don't forget to add the default resources path for the configuration
208-
val configResDir = getResourceDirectory(project, configName)
209-
it.defaultResPath.convention(configResDir.asFile.absolutePath)
196+
it.configName = configName
210197
}
211198

212199
if (rawConfigExtension != null) {
@@ -222,8 +209,10 @@ class PoEditorPlugin : Plugin<Project> {
222209
val newConfigPoEditorTask = project.registerNewTask<ImportPoEditorStringsTask>(
223210
configTaskName,
224211
getPoEditorDescriptionForConfig(configName),
225-
PLUGIN_GROUP,
226-
arrayOf(mergedConfigExtension))
212+
PLUGIN_GROUP
213+
) {
214+
configureTask(configName, mergedConfigExtension)
215+
}
227216

228217
configPoEditorTaskProvidersMap.put(configName, newConfigPoEditorTask)
229218
}
@@ -256,9 +245,6 @@ class PoEditorPlugin : Plugin<Project> {
256245

257246
private fun getPoEditorTaskName(configName: ConfigName = "") = "import${configName.capitalize()}PoEditorStrings"
258247

259-
private fun getResourceDirectory(project: Project, configName: ConfigName) =
260-
project.layout.projectDirectory.dir("src/$configName/res")
261-
262248
private fun getMainPoEditorDescription(): String = """
263249
Imports all PoEditor strings for all flavors and build types configurations.
264250
""".trimIndent()

src/main/kotlin/com/hyperdevs/poeditor/gradle/PoEditorPluginExtension.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ open class PoEditorPluginExtension @Inject constructor(objects: ObjectFactory, p
3737
@Internal
3838
override fun getName(): String = name
3939

40+
/**
41+
* Name of the configuration to use to save strings.
42+
*
43+
* Must be present in order to run the plugin. Configured internally
44+
*/
45+
@get:Optional
46+
@get:Input
47+
internal val configName: Property<String> = objects.property(String::class.java)
48+
4049
/**
4150
* Whether the configuration is enabled or not.
4251
*/
@@ -143,7 +152,7 @@ open class PoEditorPluginExtension @Inject constructor(objects: ObjectFactory, p
143152
val unquoted: Property<Boolean> = objects.property(Boolean::class.java)
144153

145154
/**
146-
* Whether or not HTML tags in strings should be unescaped or not.
155+
* Whether HTML tags in strings should be unescaped or not.
147156
*
148157
* Defaults to true.
149158
*/

0 commit comments

Comments
 (0)