Skip to content

Commit 7610035

Browse files
authored
Fix resource directories for configs. Add enabled flag to enable or disable configurations on demand (#21)
* Fix resource directories for configs * Add enabled flag to enable or disable configurations on demand * Update README.md and CHANGELOG.md; add more fixes * Apply suggestions from code review
1 parent 4a27f24 commit 7610035

File tree

9 files changed

+301
-180
lines changed

9 files changed

+301
-180
lines changed

CHANGELOG.md

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

37+
## [1.4.0] - 2020-12-25
38+
### Added
39+
- Add the `enabled` variable to enable or disable specific configurations.
40+
### Removed
41+
- Remove tasks that are disabled with the `enabled` flag or not configured.
42+
### Fixed
43+
- Fix an issue that didn't save flavor or build type specific strings in their default resources folder.
44+
3745
## [1.3.1] - 2020-12-21
3846
### Fixed
3947
- Fix percent symbols being escaped when variables are present.
@@ -82,7 +90,7 @@ android {
8290

8391
<details><summary>Kotlin</summary>
8492

85-
```kt
93+
```kotlin
8694
poEditor {
8795
defaultResPath = "your/res/path"
8896
}
@@ -162,7 +170,7 @@ android {
162170

163171
<details><summary>Kotlin</summary>
164172

165-
```kt
173+
```kotlin
166174
poEditor {
167175
// Default config that applies to all flavor/build type configurations.
168176
// Also executed when calling 'importPoEditorStrings'
@@ -225,7 +233,8 @@ res_dir_path -> resDirPath
225233
### Added
226234
- Initial release.
227235

228-
[Unreleased]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.3.1...HEAD
236+
[Unreleased]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.4.0...HEAD
237+
[1.4.0]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.3.1...1.4.0
229238
[1.3.1]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.3.0...1.3.1
230239
[1.3.0]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.2.0...1.3.0
231240
[1.2.0]: https://github.com/bq/poeditor-android-gradle-plugin/compare/1.1.0...1.2.0

README.md

Lines changed: 120 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildscript {
1818
maven { url 'https://jitpack.io' }
1919
}
2020
dependencies {
21-
classpath 'com.github.bq:poeditor-android-gradle-plugin:1.3.1'
21+
classpath 'com.github.bq:poeditor-android-gradle-plugin:1.4.0'
2222
}
2323
}
2424
```
@@ -27,13 +27,13 @@ buildscript {
2727

2828
<details><summary>Kotlin</summary>
2929

30-
```kt
30+
```kotlin
3131
buildscript {
3232
repositories {
3333
maven("https://jitpack.io")
3434
}
3535
dependencies {
36-
classpath("com.github.bq:poeditor-android-gradle-plugin:1.3.1")
36+
classpath("com.github.bq:poeditor-android-gradle-plugin:1.4.0")
3737
}
3838
}
3939
```
@@ -59,7 +59,7 @@ poEditor {
5959

6060
<details><summary>Kotlin</summary>
6161

62-
```kt
62+
```kotlin
6363
plugins {
6464
id "com.android.application"
6565
id "com.bq.poeditor"
@@ -80,8 +80,9 @@ Attribute | Description
8080
------------------------------|-----------------------------------------
8181
```apiToken``` | PoEditor API Token.
8282
```projectId``` | PoEditor project ID.
83-
```defaultLang``` | The lang to be used to build default ```strings.xml``` (```/values``` folder)
83+
```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.
85+
```enabled``` | (Since 1.4.0) (Optional) Enables the generation of the block's related task. Defaults to `true`.
8586

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

@@ -140,7 +141,7 @@ android {
140141

141142
<details><summary>Kotlin</summary>
142143

143-
```kt
144+
```kotlin
144145
poEditor {
145146
// Default config that applies to all flavor/build type configurations.
146147
// Also executed when calling 'importPoEditorStrings'
@@ -179,7 +180,89 @@ configuration: `importFreePoEditorStrings`, `importPaidPoEditorStrings`, `import
179180
`importReleasePoEditorStrings`.
180181

181182
Now the `importPoEditorStrings` task will import the main strings configured in the `poEditor` block and also the
182-
strings for each defined flavor or build type.
183+
strings for each defined flavor or build type.`
184+
185+
## Disabling task generation for specific configurations
186+
> Requires version 1.4.0 of the plug-in
187+
188+
There may be some cases where you only want certain configurations to have a related task.
189+
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
190+
main `poEditor` block to download any strings. For these cases you have the `enabled` variable that you can set to false
191+
when you want to disable a configuration.
192+
193+
Keep in mind that, if you disable the main `poEditor` block, you'll need to enable each specific configuration separately
194+
since they inherit the main block configuration. Let's see how this works:
195+
196+
<details open><summary>Groovy</summary>
197+
198+
```groovy
199+
poEditor {
200+
// Default config that applies to all flavor/build type configurations.
201+
// Also executed when calling 'importPoEditorStrings'
202+
enabled = false // This'll disable task generation for every configuration.
203+
apiToken = "your_common_api_token"
204+
}
205+
206+
android {
207+
flavorDimensions 'type'
208+
productFlavors {
209+
free { dimension 'type' }
210+
paid { dimension 'type' }
211+
}
212+
213+
poEditorConfig {
214+
free {
215+
// Specific configuration for the free flavor
216+
enabled = true // Explicitly enabled since the main block disables task generation
217+
projectId = 12345
218+
}
219+
paid {
220+
// Specific configuration for the paid flavor
221+
enabled = true // Explicitly enabled since the main block disables task generation
222+
projectId = 54321
223+
}
224+
}
225+
}
226+
```
227+
228+
</details>
229+
230+
<details><summary>Kotlin</summary>
231+
232+
```kotlin
233+
poEditor {
234+
// Default config that applies to all flavor/build type configurations.
235+
// Also executed when calling 'importPoEditorStrings'
236+
enabled = false // This'll disable task generation for every configuration.
237+
apiToken = "your_common_api_token"
238+
}
239+
240+
android {
241+
// If you have the following flavors...
242+
flavorDimensions("type")
243+
244+
productFlavors {
245+
register("free") { setDimension("type") }
246+
register("paid") { setDimension("type") }
247+
}
248+
249+
poEditorConfig {
250+
register("free") {
251+
// Specific configuration for the free flavor
252+
enabled = true // Explicitly enabled since the main block disables task generation
253+
projectId = 12345
254+
}
255+
register("paid") {
256+
// Specific configuration for the paid flavor
257+
enabled = true // Explicitly enabled since the main block disables task generation
258+
projectId = 54321
259+
}
260+
}
261+
}
262+
```
263+
264+
</details>
265+
183266

184267
## Handling library modules
185268
> Requires version 1.3.0 of the plug-in
@@ -203,7 +286,7 @@ poEditor {
203286

204287
<details><summary>Kotlin</summary>
205288

206-
```kt
289+
```kotlin
207290
plugins {
208291
id "com.android.library"
209292
id "com.bq.poeditor"
@@ -221,35 +304,14 @@ poEditor {
221304
You can also apply flavor and build type-specific configurations as you would do when setting them up with application modules.
222305
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`
223306

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

225-
## Handling tablet specific strings
226-
227-
You can mark some strings as tablet specific strings by adding ```_tablet```suffix to the string key in PoEditor.
228-
The plug-in will extract tablet strings to its own XML and save it in ```values-<lang>-sw600dp```.
229-
230-
If you define the following string in PoEditor:
231-
```welcome_message: Hey friend``` and ```welcome_message_tablet: Hey friend how are you doing today, you look great!```
232-
233-
The plug-in will create two `strings.xml` files:
234-
235-
`/values/strings.xml`
236-
```xml
237-
<string name="welcome_message">Hey friend</string>
238-
```
239-
240-
`/values-sw600dp/strings.xml`
241-
```xml
242-
<string name="welcome_message">Hey friend how are you doing today, you look great!</string>
243-
```
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.
244313

245-
## Handling placeholders
246-
You can add placeholders to your strings. We've defined a placeholder markup to use in PoEditor string definition: it uses a double braces syntax, like this one
247-
248-
```
249-
{{value}}
250-
```
251-
252-
The PoEditor string:
314+
For example, the PoEditor string:
253315

254316
```
255317
welcome_message: Hey {{user_name}} how are you
@@ -261,9 +323,7 @@ will become, in `strings.xml`
261323
<string name="welcome_message">Hey %1$s how are you</string>
262324
```
263325

264-
If you need more than one placeholder in the same string, you can use ordinals too:
265-
266-
PoEditor string:
326+
If you need more than one variable in the same string, you can also use ordinals. The string:
267327

268328
```
269329
welcome_message: Hey {1{user_name}} how are you, today offer is {2{current_offer}}
@@ -275,9 +335,9 @@ will become, `in strings.xml`
275335
<string name="welcome_message">Hey %1$s how are you, today offer is %2$s</string>
276336
```
277337

278-
This way you could change the order of the placeholders depending on the language:
338+
This way you can change the order of the placeholders depending on the language:
279339

280-
PoEditor string with Spanish translation:
340+
The same string, with the following Spanish translation:
281341

282342
```
283343
welcome_message: La oferta del día es {2{current_offer}} para ti, {1{user_name}}
@@ -289,6 +349,26 @@ will become, in `values-es/strings.xml`
289349
<string name="welcome_message">La oferta del día es %2$s para ti, %1$s</string>
290350
```
291351

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+
292372
## iOS alternative
293373
If you want a similar solution for your iOS projects, check this out: [poeditor-parser-swift](https://github.com/bq/poeditor-parser-swift)
294374

0 commit comments

Comments
 (0)