Skip to content

Commit

Permalink
fix: set default language of annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
adrielcafe committed May 13, 2022
1 parent ddb6ae5 commit c0e12a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true

# Maven
GROUP=cafe.adriel.lyricist
VERSION_NAME=1.2.0
VERSION_NAME=1.2.1

POM_DESCRIPTION=The missing I18N/L10N library for Jetpack Compose!
POM_INCEPTION_YEAR=2021
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ internal class LyricistSymbolProcessor(

val stringsName = "${config.moduleName.toLowerCamelCase()}Strings"

val defaultLanguageTag = declarations
.firstNotNullOfOrNull { it.annotations.getDefaultLanguageTag() }
?.let { "\"$it\"" }
?: "Locale.current.toLanguageTag()"

val defaultStrings = declarations
.first { it.annotations.getValue<Boolean>(ANNOTATION_PARAM_DEFAULT) == true }

Expand Down Expand Up @@ -86,7 +91,7 @@ internal class LyricistSymbolProcessor(
|
|@Composable
|public fun remember$fileName(
| languageTag: LanguageTag = Locale.current.toLanguageTag()
| languageTag: LanguageTag = $defaultLanguageTag
|): Lyricist<$stringsClassOutput> =
| rememberStrings($stringsName, languageTag)
|
Expand Down Expand Up @@ -133,6 +138,16 @@ internal class LyricistSymbolProcessor(
private fun KSPropertyDeclaration.getClassQualifiedName(): String? =
getter?.returnType?.resolve()?.declaration?.qualifiedName?.asString()

private fun Sequence<KSAnnotation>.getDefaultLanguageTag(): String? =
firstOrNull {
withName(ANNOTATION_NAME)
?.arguments
?.withName(ANNOTATION_PARAM_DEFAULT)
?.value == true
}?.arguments
?.withName(ANNOTATION_PARAM_LANGUAGE_TAG)
?.value as? String

private inline fun <reified T> Sequence<KSAnnotation>.getValue(argumentName: String): T? =
withName(ANNOTATION_NAME)
?.arguments
Expand Down

0 comments on commit c0e12a2

Please sign in to comment.