Skip to content

Commit 5211721

Browse files
authored
Add PoEditor tags support (#26)
1 parent 5a7819c commit 5211721

File tree

9 files changed

+183
-124
lines changed

9 files changed

+183
-124
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222

2323
## [Unreleased]
2424
### Added
25-
- No new features!
25+
- Add `tags` parameter to `poEditorConfig` block to add PoEditor tags:
26+
```groovy
27+
poEditor {
28+
apiToken = "your_api_token"
29+
projectId = 12345
30+
defaultLang = "en"
31+
tags = ["tag1", "tag2"] // Download strings with the specified tags
32+
}
33+
```
2634
### Changed
2735
- No changed features!
2836
### Deprecated
@@ -36,8 +44,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3644

3745
## [2.0.0] - 2021-04-28
3846
### Changed
39-
- Changed repo ownership to [hyperdevs-team](https://github.com/hyperdevs-team). Thanks [bq](https://github.com/bq) for all the work!
40-
- Changed package names from `com.bq.*` to `com.hyperdevs.*`
47+
- Change repo ownership to [hyperdevs-team](https://github.com/hyperdevs-team). Thanks [bq](https://github.com/bq) for all the work!
48+
- Change package names from `com.bq.*` to `com.hyperdevs.*`
4149

4250
## [1.4.2] - 2020-12-29
4351
### Added

README.md

Lines changed: 116 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ In your main `build.gradle`, add [jitpack.io](https://jitpack.io/) repository in
1515
```groovy
1616
buildscript {
1717
repositories {
18-
maven { url 'https://jitpack.io' }
18+
maven { url "https://jitpack.io" }
1919
}
2020
dependencies {
21-
classpath 'com.github.hyperdevs-team:poeditor-android-gradle-plugin:2.0.0'
21+
classpath "com.github.hyperdevs-team:poeditor-android-gradle-plugin:2.1.0"
2222
}
2323
}
2424
```
@@ -33,7 +33,7 @@ buildscript {
3333
maven("https://jitpack.io")
3434
}
3535
dependencies {
36-
classpath("com.github.hyperdevs-team:poeditor-android-gradle-plugin:2.0.0")
36+
classpath("com.github.hyperdevs-team:poeditor-android-gradle-plugin:2.1.0")
3737
}
3838
}
3939
```
@@ -83,6 +83,7 @@ Attribute | Description
8383
```defaultLang``` | (Optional) The lang to be used to build default ```strings.xml``` (```/values``` folder). Defaults to English (`en`).
8484
```defaultResPath``` | (Since 1.3.0) (Optional) Path where the plug-in should dump strings. Defaults to the module's default (or build variant) `res` path.
8585
```enabled``` | (Since 1.4.0) (Optional) Enables the generation of the block's related task. Defaults to `true`.
86+
```tags``` | (Since 2.1.0) (Optional) List of PoEditor tags to download.
8687

8788
After the configuration is done, just run the new ```importPoEditorStrings``` task via Android Studio or command line:
8889

@@ -96,8 +97,71 @@ This task will:
9697
* Create and save strings.xml files to ```/values-<lang>``` (or ```/values``` in case of the default lang). It supports
9798
region specific languages by creating the proper folders (i.e. ```/values-es-rMX```).
9899

99-
## Handling multiple flavors and build types
100+
## Enhanced syntax
101+
The plug-in enhances your PoEditor experience by adding useful features over your project by adding some custom syntax for certain tasks.
102+
103+
### Variables
104+
The 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.
105+
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.
106+
107+
For example, the PoEditor string:
108+
109+
```
110+
welcome_message: Hey {{user_name}} how are you
111+
```
112+
113+
will become, in `strings.xml`
114+
115+
```xml
116+
<string name="welcome_message">Hey %1$s how are you</string>
117+
```
118+
119+
If you need more than one variable in the same string, you can also use ordinals. The string:
120+
121+
```
122+
welcome_message: Hey {1{user_name}} how are you, today offer is {2{current_offer}}
123+
```
124+
125+
will become, `in strings.xml`
126+
127+
```xml
128+
<string name="welcome_message">Hey %1$s how are you, today offer is %2$s</string>
129+
```
130+
131+
This way you can change the order of the placeholders depending on the language:
132+
133+
The same string, with the following Spanish translation:
134+
135+
```
136+
welcome_message: La oferta del día es {2{current_offer}} para ti, {1{user_name}}
137+
```
138+
139+
will become, in `values-es/strings.xml`
140+
141+
```xml
142+
<string name="welcome_message">La oferta del día es %2$s para ti, %1$s</string>
143+
```
144+
145+
### Tablet specific strings
146+
You can mark some strings as tablet specific strings by adding ```_tablet```suffix to the string key in PoEditor.
147+
The plug-in will extract tablet strings to its own XML and save it in ```values-<lang>-sw600dp```.
148+
149+
If you define the following string in PoEditor:
150+
```welcome_message: Hey friend``` and ```welcome_message_tablet: Hey friend how are you doing today, you look great!```
100151

152+
The plug-in will create two `strings.xml` files:
153+
154+
`/values/strings.xml`
155+
```xml
156+
<string name="welcome_message">Hey friend</string>
157+
```
158+
159+
`/values-sw600dp/strings.xml`
160+
```xml
161+
<string name="welcome_message">Hey friend how are you doing today, you look great!</string>
162+
```
163+
164+
## Handling multiple flavors and build types
101165
Sometimes we might want to import different strings for a given flavor (for example, in white label apps, we could have
102166
different string definitions depending on the brand where they're used). The plugin supports this kind of apps by providing
103167
specific configurations via the `poEditorConfig` block.
@@ -176,21 +240,61 @@ android {
176240
</details>
177241

178242
Each flavor (`free` and `paid`) and build type (`debug` and `release`) will have its own task to import strings for said
179-
configuration: `importFreePoEditorStrings`, `importPaidPoEditorStrings`, `importDebugPoEditorStrings` and
243+
configuration: `importFreePoEditorStrings`, `importPaidPoEditorStrings`, `importDebugPoEditorStrings` and
180244
`importReleasePoEditorStrings`.
181245

182246
Now the `importPoEditorStrings` task will import the main strings configured in the `poEditor` block and also the
183247
strings for each defined flavor or build type.`
184248

249+
## Handling library modules
250+
> Requires version 1.3.0 of the plug-in
251+
252+
You can also apply the plug-in to library modules. Here's an example:
253+
Apply and configure the plug-in in your library's `build.gradle` file:
254+
<details open><summary>Groovy</summary>
255+
256+
```groovy
257+
apply plugin: "com.android.library"
258+
apply plugin: "com.hyperdevs.poeditor"
259+
260+
poEditor {
261+
apiToken = "your_api_token"
262+
projectId = 12345
263+
defaultLang = "en"
264+
}
265+
```
266+
267+
</details>
268+
269+
<details><summary>Kotlin</summary>
270+
271+
```kotlin
272+
plugins {
273+
id "com.android.library"
274+
id "com.hyperdevs.poeditor"
275+
}
276+
277+
poEditor {
278+
apiToken = "your_api_token"
279+
projectId = 12345
280+
defaultLang = "en"
281+
}
282+
```
283+
284+
</details>
285+
286+
You can also apply flavor and build type-specific configurations as you would do when setting them up with application modules.
287+
The plug-in will generate the proper tasks needed to import the strings under your module: `:<your_module>:import<your_flavor_or_build_type_if_any>PoEditorStrings`
288+
185289
## Disabling task generation for specific configurations
186290
> Requires version 1.4.0 of the plug-in
187291
188-
There may be some cases where you only want certain configurations to have a related task.
292+
There may be some cases where you only want certain configurations to have a related task.
189293
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
190294
main `poEditor` block to download any strings. For these cases you have the `enabled` variable that you can set to false
191295
when you want to disable a configuration.
192296

193-
Keep in mind that, if you disable the main `poEditor` block, you'll need to enable each specific configuration separately
297+
Keep in mind that, if you disable the main `poEditor` block, you'll need to enable each specific configuration separately
194298
since they inherit the main block configuration. Let's see how this works:
195299

196300
<details open><summary>Groovy</summary>
@@ -263,112 +367,21 @@ android {
263367

264368
</details>
265369

370+
## Handling tags
371+
> Requires version 2.1.0 of the plug-in
266372
267-
## Handling library modules
268-
> Requires version 1.3.0 of the plug-in
269-
270-
You can also apply the plug-in to library modules. Here's an example:
271-
Apply and configure the plug-in in your library's `build.gradle` file:
272-
<details open><summary>Groovy</summary>
373+
You can also select the tags that you want strings to be downloaded from PoEditor, based on the tags that you defined in
374+
your PoEditor project.
273375

274376
```groovy
275-
apply plugin: "com.android.library"
276-
apply plugin: "com.hyperdevs.poeditor"
277-
278377
poEditor {
279378
apiToken = "your_api_token"
280379
projectId = 12345
281380
defaultLang = "en"
381+
tags = ["tag1", "tag2"] // Download strings with the specified tags
282382
}
283383
```
284384

285-
</details>
286-
287-
<details><summary>Kotlin</summary>
288-
289-
```kotlin
290-
plugins {
291-
id "com.android.library"
292-
id "com.hyperdevs.poeditor"
293-
}
294-
295-
poEditor {
296-
apiToken = "your_api_token"
297-
projectId = 12345
298-
defaultLang = "en"
299-
}
300-
```
301-
302-
</details>
303-
304-
You can also apply flavor and build type-specific configurations as you would do when setting them up with application modules.
305-
The plug-in will generate the proper tasks needed to import the strings under your module: `:<your_module>:import<your_flavor_or_build_type_if_any>PoEditorStrings`
306-
307-
## Enahanced syntax
308-
The plug-in enhances your PoEditor experience by adding useful features over your project by adding useful syntax for certain tasks.
309-
310-
### Variables
311-
The 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.
312-
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.
313-
314-
For example, the PoEditor string:
315-
316-
```
317-
welcome_message: Hey {{user_name}} how are you
318-
```
319-
320-
will become, in `strings.xml`
321-
322-
```xml
323-
<string name="welcome_message">Hey %1$s how are you</string>
324-
```
325-
326-
If you need more than one variable in the same string, you can also use ordinals. The string:
327-
328-
```
329-
welcome_message: Hey {1{user_name}} how are you, today offer is {2{current_offer}}
330-
```
331-
332-
will become, `in strings.xml`
333-
334-
```xml
335-
<string name="welcome_message">Hey %1$s how are you, today offer is %2$s</string>
336-
```
337-
338-
This way you can change the order of the placeholders depending on the language:
339-
340-
The same string, with the following Spanish translation:
341-
342-
```
343-
welcome_message: La oferta del día es {2{current_offer}} para ti, {1{user_name}}
344-
```
345-
346-
will become, in `values-es/strings.xml`
347-
348-
```xml
349-
<string name="welcome_message">La oferta del día es %2$s para ti, %1$s</string>
350-
```
351-
352-
### Tablet specific strings
353-
354-
You can mark some strings as tablet specific strings by adding ```_tablet```suffix to the string key in PoEditor.
355-
The plug-in will extract tablet strings to its own XML and save it in ```values-<lang>-sw600dp```.
356-
357-
If you define the following string in PoEditor:
358-
```welcome_message: Hey friend``` and ```welcome_message_tablet: Hey friend how are you doing today, you look great!```
359-
360-
The plug-in will create two `strings.xml` files:
361-
362-
`/values/strings.xml`
363-
```xml
364-
<string name="welcome_message">Hey friend</string>
365-
```
366-
367-
`/values-sw600dp/strings.xml`
368-
```xml
369-
<string name="welcome_message">Hey friend how are you doing today, you look great!</string>
370-
```
371-
372385
## iOS alternative
373386
If you want a similar solution for your iOS projects, check this out: [poeditor-parser-swift](https://github.com/hyperdevs-team/poeditor-parser-swift)
374387

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fun main() {
3333
val projectId = dotenv.get("PROJECT_ID", "-1").toInt()
3434
val resDirPath = dotenv.get("RES_DIR_PATH", "")
3535
val defaultLanguage = dotenv.get("DEFAULT_LANGUAGE", "")
36+
val tags = dotenv.get("TAGS", "").takeIf { it.isNotBlank() }?.split(",")?.map { it.trim() }
3637

37-
PoEditorStringsImporter.importPoEditorStrings(apiToken, projectId, defaultLanguage, resDirPath)
38+
PoEditorStringsImporter.importPoEditorStrings(apiToken, projectId, defaultLanguage, resDirPath, tags)
3839
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PoEditorPlugin : Plugin<Project> {
5050
enabled.convention(true)
5151
defaultLang.convention("en")
5252
defaultResPath.convention(mainResourceDirectory.asFile.absolutePath)
53+
tags.convention(emptyList())
5354
}
5455

5556
// Add flavor and build-type configurations if the project has the "com.android.application" plugin

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.hyperdevs.poeditor.gradle
2020

2121
import org.gradle.api.Named
2222
import org.gradle.api.model.ObjectFactory
23+
import org.gradle.api.provider.ListProperty
2324
import org.gradle.api.provider.Property
2425
import org.gradle.api.tasks.Input
2526
import org.gradle.api.tasks.Internal
@@ -76,6 +77,15 @@ open class PoEditorPluginExtension @Inject constructor(objects: ObjectFactory, p
7677
@get:Input
7778
val defaultResPath: Property<String> = objects.property(String::class.java)
7879

80+
/**
81+
* Tags to filter downloaded strings with, previously declared in PoEditor.
82+
*
83+
* Defaults to an empty list of tags if not present.
84+
*/
85+
@get:Optional
86+
@get:Input
87+
val tags: ListProperty<String> = objects.listProperty(String::class.java)
88+
7989
/**
8090
* Sets the configuration as enabled or not.
8191
*
@@ -125,4 +135,14 @@ open class PoEditorPluginExtension @Inject constructor(objects: ObjectFactory, p
125135
* Gradle Kotlin DSL users must use `defaultResPath.set(value)`.
126136
*/
127137
fun setDefaultResPath(value: String) = defaultResPath.set(value)
138+
139+
/**
140+
* Sets the tags to filter downloaded strings with, previously declared in PoEditor.
141+
*
142+
* NOTE: added for Gradle Groovy DSL compatibility. Check the note on
143+
* https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties for more details.
144+
*
145+
* Gradle Kotlin DSL users must use `defaultResPath.set(value)`.
146+
*/
147+
fun setTags(value: List<String>) = tags.set(value)
128148
}

0 commit comments

Comments
 (0)