Skip to content

Commit 9ee8efc

Browse files
authored
0.1.1 - doc updates, plugin tests, etc. (#6)
Work for release 0.1.1 - Mostly cosmetic cleanup of plugin tasks to improve functional organization, readability, and logging - Unit test validation added for plugin and all individual tasks - Java/Android locales lists added as docs as user information - Update README with more streamlined instructions, linked to wiki for more info Related work on Github - PR tests workflow added to validate changes before merging - Add deeper config details and locale information to wiki - Add roadmap to Discussions
1 parent b544f61 commit 9ee8efc

19 files changed

+2017
-146
lines changed

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
# Android Locale Resource Generator
22

33
A Gradle plugin for Android projects to automate locale configuration and provide supporting source/resource files.
4-
Built with Android Gradle Plugin (AGP) 7.4.0
4+
Built with Android Gradle Plugin (AGP) 7.5.0
55

6-
## Primary Function
6+
## Functionality
77

8-
This plugin was built mostly to generate `locale-config.xml` file to support [per-app language settings](https://developer.android.com/guide/topics/resources/app-languages) for Android API 33+. Instead of remembering to modify files each time you add support for a locale, you just add the locale _once_ into your build.gradle file and let this plugin generate the xml resources you need for locale support.
8+
- Generates `locale-config.xml` file for Android [per-app language settings](https://developer.android.com/guide/topics/resources/app-languages)
9+
- Generates `SupportedLocales` Kotlin class for in-app access to your configured locales
10+
- Includes pseudolocale support when pseudolocales enabled for build variant
911

10-
**Bonus:** The plugin automatically includes pseudolocale options if you have them enabled for a build variant.
12+
## Community and Docs
1113

12-
## Secondary Functions
14+
- [Wiki](../../wiki) for more details on language tag support and plugin configuration
15+
- [Discussions](../../discussions) for project roadmap, ideas, Q&A, and polls
16+
- [Issues](../../issues) for found bugs and reporting specific locale issues
1317

14-
A `SupportedLocales.kt` source file is generated with maps of the locales your app is set to support. It includes language tags, langauge names (both exonyms and endonyms provided), and functions to get them. This data is intended to assist with building an in-app language selector, but I'd love to hear about other uses.
18+
## Setup
1519

16-
## How to Use
20+
### Plugin Dependency Management
1721

1822
```kotlin
19-
// settings.gradle.kts (project settings)
23+
// File - settings.gradle.kts (project settings)
24+
2025
dependencyResolutionManagement {
21-
// should already have this section, don't modify
26+
// don't modify
2227
}
2328

2429
// add this if you don't have it
@@ -30,22 +35,24 @@ pluginManagement {
3035
}
3136
```
3237

33-
The `resourceConfigurations` property below is a list of explicitly configured resource types to be added to your project. Often, it's used to prevent building your project with extra resources you don't need (like tons of locale resources you don't support coming from dependencies you didn't know hda them.)
38+
### Project Locale Configuration
39+
40+
The `resourceConfigurations` property is a list of explicitly configured resource types to be added to your project. Often, it's used to prevent building your project with extra resources you don't need (like locale resources you don't support coming from project dependencies)
3441

35-
Since it's good practice to specify resources in use, this plugin utilizes the same `resourceConfigurations` list in during generation. Just add your supported locales into this list, and the plugin will handle the rest!
42+
Since it's good practice to specify resources in use, this plugin utilizes the same `resourceConfigurations` list to guide its resource generation. Add your supported locales into this list, and the plugin will handle the rest!
3643

3744
```kotlin
38-
// build.gradle.kts (application level)
45+
// File - build.gradle.kts (app module)
46+
3947
plugins {
4048
//...
41-
id("com.mermake.locale-resource-generator") version "0.1" // check release page for latest version
49+
id("com.mermake.locale-resource-generator") version "{{latest}}"
4250
}
4351

4452
android {
4553
//...
4654
defaultConfig {
4755
//...
48-
4956
resourceConfigurations.addAll(
5057
listOf(
5158
"en",
@@ -60,16 +67,17 @@ android {
6067
}
6168
}
6269
```
63-
> Notice the different formats of the language tags below. They're not _quite_ Unicode tags, but it's okay. Android recognizes both the `xx-rXX` and `bxx+XX+` formats ([more info on locale resolution here](https://developer.android.com/guide/topics/resources/multilingual-support#postN)). This is important to know since some language tags like `de-DE` would cause a build failure and the `b+` format is required. ([BCP-47 spec](https://cldr.unicode.org/development/development-process/design-proposals/bcp47-syntax-mapping)) In any case, the plugin converts everything to Unicode-friendly tags since that what we need in the manifest and source code anyway.
70+
> See the wiki page on [Locales and Android Support](../../wiki/Locales-and-Android-Support) for details on supported language tags.
71+
72+
### Manifest Configuration
6473

6574
```xml
6675
<!-- AndroidManifest.xml -->
6776
<application>
68-
<!-- Include this line in your application tag. The file is generated when you build and resolves without issue. -->
77+
<!-- Include this line in your application tag. The file is generated when you build or run the locale config task. -->
6978
android:localeConfig="@xml/locale_config"
70-
71-
72-
<!-- Add this for supporting lower than API 33 (see linked Android docs for more details) -->
79+
80+
<!-- Add this for supporting lower than API 33 (see Android docs for more info) -->
7381
<service
7482
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
7583
android:enabled="false"
@@ -81,16 +89,9 @@ android {
8189
</application>
8290
```
8391

84-
The plugin runs automatically as part of your normal builds. You can also run individual tasks:
85-
- `generateLocaleConfig[Debug|Release|etc]` - generates `locale_config.xml` file for per-app language support
86-
87-
## Glossary
88-
89-
- **Endonym** - A name used by a group or category of people to refer to themselves or their language, as opposed to a name given to them by other groups.
90-
- In Germany (Deutcshland), the 'German' language is written as 'Deutsche'
91-
- In Japan (日本), the 'Japanese' language is written as '日本語'
92-
92+
## Gradle Tasks
9393

94-
- **Exonym** - Opposite of exonym. A name used to refer to a language or people that is not what they use to refer to themsleves their own language. Many languages have different names for each language.
95-
- 'French' in Japanese is 'フランス語'
96-
- 'French' in German is 'Französisch'
94+
The plugin runs its tasks automatically before the `preBuild` step of your normal builds. A variant task is configured for each of your project's build variants. (debug, release, wumbo, etc.)
95+
- `generateLocaleConfig[Variant]` - generates `locale_config.xml` resource file
96+
- `generateSupportedLocales[Variant]` - generates `SupportedLocales.kt` class
97+
- `soakConfiguredLocales[Variant]` - creates the intermediate files with supported locale information that is used in the other tasks

build.gradle.kts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,67 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
44
kotlin("jvm") version "1.7.20"
5-
`kotlin-dsl` // gradle manages version for compatibility
65
id("com.gradle.plugin-publish") version "1.1.0"
7-
signing
6+
`kotlin-dsl` // gradle kotlin dsl, syntax allows gradle to manage version for compatibility
7+
signing // gradle signing plugin
8+
groovy // for testing with Spock
89
}
910

10-
group = "com.mermake"
11-
version = "0.1"
12-
1311
repositories {
14-
mavenCentral()
1512
google()
13+
gradlePluginPortal()
1614
}
1715

1816
dependencies {
1917
implementation("com.android.tools.build:gradle:7.4.0")
20-
implementation("org.redundent:kotlin-xml-builder:1.8.0")
21-
implementation("com.squareup:kotlinpoet:1.12.0") {
18+
implementation("org.redundent:kotlin-xml-builder:1.8.0") // todo: 1.9.0
19+
implementation("com.squareup:kotlinpoet:1.12.0") { // todo: 1.17.0
2220
exclude(module = "kotlin-reflect")
2321
}
22+
23+
testImplementation(gradleTestKit())
24+
testImplementation(platform("org.spockframework:spock-bom:2.3-groovy-3.0"))
25+
testImplementation("org.spockframework:spock-core")
26+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
2427
}
2528

2629
tasks.withType<KotlinCompile>().configureEach {
2730
kotlinOptions.apiVersion = "1.7"
28-
kotlinOptions.jvmTarget = "11"
31+
kotlinOptions.jvmTarget = "11" // todo: test java 8 for broader backwards compatibility
2932
}
3033

34+
tasks.withType<Test>().configureEach {
35+
useJUnitPlatform()
36+
}
37+
38+
group = "com.mermake"
39+
version = "0.1.1"
40+
3141
gradlePlugin {
3242
plugins {
3343
register("localeResourceGeneratorPlugin") {
3444
id = "com.mermake.locale-resource-generator"
3545
displayName = "Locale Resource Generator"
36-
description = "Automatically generates locale_config.xml for per-app language support on Android 13 and higher. " +
37-
"Also generates map of supported locales/languages for use in a runtime language picker."
3846
implementationClass = "com.mermake.locale_resource_generator.LocaleResourceGeneratorPlugin"
47+
description =
48+
"Automatically generates locale_config.xml for per-app language support on Android 13 and higher. " +
49+
"Also generates map of supported locales/languages for use in a runtime language picker."
3950
}
4051
}
4152
}
4253

4354
pluginBundle {
44-
// TODO: update with mermake group info when available (date very much tbd)
4555
website = "https://adamormsby.com"
4656
vcsUrl = "https://github.com/aormsby/android-locale-resource-generator"
47-
tags = listOf("android", "android 13", "localization", "locale config", "language support", "automation")
57+
tags = listOf(
58+
"android",
59+
"android plugin",
60+
"android 13",
61+
"tiramisu",
62+
"localization",
63+
"internationalization",
64+
"locale config",
65+
"language support",
66+
"automation"
67+
)
4868
}

0 commit comments

Comments
 (0)