@testncfpkg/ncf-weblate-cf-front
v1.0.1
Published
Kotlin Multiplatform resource library for managing localized strings across Android, iOS, and Web
Maintainers
Readme
NCF Weblate CF Front
A Kotlin Multiplatform (KMP) resource-only library for managing localized strings across Android, iOS, and Web platforms.
Features
- Resource-only KMP library with no platform-specific code
- Multi-language support using Moko Resources
- Organized by feature modules:
- Foundation
- UI
- Content
- Checkout
- Customer
- Bag
- Order
- Ready for Maven publishing
- Weblate integration ready
- Two consumption patterns: Moko Resources (StringResource) and generated String values
Setup
Gradle
dependencies {
implementation("com.ncf.weblate:ncf-weblate-cf-front:1.0.0")
}Usage
This library provides two ways to access localized strings:
- Generated Strings.kt - Direct
Stringvalues (recommended for most cases) - Moko Resources -
StringResourceobjects (for platform integration)
Generated Strings.kt (Recommended)
The library generates locale-specific Strings.kt files with actual string values:
stringResources/
├── base/
│ └── {feature}/Strings.kt
├── ptBR/
│ └── {feature}/Strings.kt
├── esAR/
│ └── {feature}/Strings.kt
└── ...Android (Kotlin/Compose)
import com.ncf.weblate.stringResources.base.bag.BagStrings
// Simple strings
val title: String = BagStrings.bagTitle
val empty: String = BagStrings.bagEmpty
// Usage in Compose
Text(text = BagStrings.bagTitle)
// Plurals
val itemsText = BagStrings.bagItemsCount.get(itemCount)
Text(text = String.format(itemsText, itemCount))iOS (Swift)
After building the framework, access the strings through the generated Kotlin objects:
// Swift access to generated strings
let bagStrings = BagStrings() // Uses base locale by default
let title = bagStrings.bagTitle
let empty = bagStrings.bagEmpty
// Plurals
let count = 5
let itemsText = bagStrings.bagItemsCount?.get(Int(count))Note: For Swift access, expose the strings through a wrapper in your shared module:
// In your shared KMP module
class BagStringsProvider {
fun getTitle(): String = com.ncf.weblate.stringResources.base.bag.BagStrings.bagTitle
fun getBagItemsCount(quantity: Int): String = com.ncf.weblate.stringResources.base.bag.BagStrings.bagItemsCount.get(quantity)
}Web (Kotlin/JS)
import com.ncf.weblate.stringResources.base.bag.BagStrings
// Simple strings
val title: String = BagStrings.bagTitle
// Plurals
val itemsText: String = BagStrings.bagItemsCount.get(itemCount)Moko Resources (StringResource)
For platform integration (XML layouts, string formatting, etc.), use the Moko Resources approach:
Android (Traditional Views)
import com.ncf.weblate.MR
import dev.icerock.moko.resources.desc.StringDesc
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = findViewById(R.id.my_text)
// Method 1: Get StringResource and convert to String
val stringResource = MR.strings.bag_items_title
textView.text = stringResource.getString(this) // Requires Context
// Method 2: Use StringDesc
val stringDesc: StringDesc = StringDesc.Resource(MR.strings.bag_checkout)
textView.text = stringDesc.toString(this)
}
}XML Layouts:
<!-- activity_main.xml -->
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bag_items_title"
tools:text="Bag Title" />Android (Compose)
import com.ncf.weblate.MR
Text(MR.foundation.strings.welcome_message.desc().toString())iOS (Swift)
// In your shared module
class ResourceManager {
fun getWelcomeMessage(): String {
return MR.foundation.strings.welcome_message.desc().toString()
}
fun getBagTitle(): String {
return MR.strings.bag_bag_title.desc().toString()
}
}// In your iOS project
let resourceManager = ResourceManager()
let welcomeMessage = resourceManager.getWelcomeMessage()
let bagTitle = resourceManager.getBagTitle()Web (Kotlin/JS)
import com.ncf.weblate.MR
// Accessing string resources
val appName = MR.foundation.strings.app_name.desc().toString()
val welcomeMessage = MR.foundation.strings.welcome_message.desc().toString()Feature Structure
Each feature has its own Strings object with all localized strings:
object FoundationStrings {
val appName: String get() = "NCF Weblate"
val cancel: String get() = "Cancel"
val errorGeneric: String get() = "An error occurred"
val retry: String get() = "Retry"
val welcomeMessage: String get() = "Welcome to our application"
val allKeys: List<String> get() = listOf(...)
val count: Int get() = allKeys.size
}Aggregated access through StringsBundle:
import com.ncf.weblate.stringResources.base.StringsBundle
// Access all features through a single entry point
StringsBundle.foundation.appName
StringsBundle.bag.bagTitle
StringsBundle.checkout.checkoutTitle
// Get feature string counts
StringsBundle.getFeatureStringCount("bag") // Returns count
StringsBundle.hasFeature("bag") // Returns Boolean
StringsBundle.totalStringCount // Returns total countLocale Selection
The library provides a convenient LocaleProvider for runtime locale switching:
import com.ncf.weblate.stringResources.localization.LocaleProvider
// Set locale at runtime
LocaleProvider.setLocale("esAR")
LocaleProvider.setLocale("ptBR")
LocaleProvider.setLocale("base") // Default
// Access strings - same code, different locale
textView.text = LocaleProvider.Strings.bag.bagTitle
textView.text = LocaleProvider.Strings.foundation.appName
textView.text = LocaleProvider.Strings.checkout.checkoutTitle
// Plurals
val itemsText = LocaleProvider.Strings.bag.bagItemsCount.get(itemCount)Supported locales:
"base"- English (default)"ptBR"/"pt-BR"- Brazilian Portuguese"esAR"/"es-AR"- Argentine Spanish"esCO"/"es-CO"- Colombian Spanish"esMX"/"es-MX"- Mexican Spanish"esCL"/"es-CL"- Chilean Spanish
Check locale support:
if (LocaleProvider.isSupported("esAR")) {
LocaleProvider.setLocale("esAR")
}
val currentLocale = LocaleProvider.getLocale() // Returns "esAR"Access all features:
LocaleProvider.Strings.foundation
LocaleProvider.Strings.bag
LocaleProvider.Strings.checkout
LocaleProvider.Strings.customer
LocaleProvider.Strings.order
LocaleProvider.Strings.content
LocaleProvider.Strings.uiWeblate Integration
This library is designed to work seamlessly with Weblate for translation management:
- Configure Weblate to monitor the
src/commonMain/resources/MR/base/directory - Set up translation components for each feature:
- Foundation
- UI
- Content
- Checkout
- Customer
- Bag
- Order
- Configure Weblate to output translations to
src/commonMain/resources/MR/{language}/ - When Weblate pushes translations, they will automatically be included in the next build
Weblate Component Configuration
For each feature, create a Weblate component with these settings:
- File format: Android XML strings
- File mask:
src/commonMain/resources/MR/*/feature_name/strings.xml - Monolingual base language file:
src/commonMain/resources/MR/base/feature_name/strings.xml
Continuous Integration
To automate the translation workflow:
- Set up a webhook in Weblate to trigger builds when translations are updated
- Configure your CI pipeline to pull translations from Weblate before building
- Publish new versions of the library when translations are updated
Publishing
To publish this library to a Maven repository:
- Configure your repository credentials in
~/.m2/settings.xmlor through environment variables - Run
./gradlew publish - The library will be published with the coordinates:
com.ncf.weblate:ncf-weblate-cf-front:1.0.0
Local Development
To build the library locally:
./gradlew buildTo publish to local Maven repository:
./gradlew publishToMavenLocalBuild
Prerequisites
- JDK 17+
- Android SDK (for Android builds)
- Xcode (for iOS builds)
All Platforms
To build for all platforms at once:
./gradlew buildAndroid
To build for Android:
./gradlew :ncf-weblate-cf-front:assembleReleaseOutput location: build/outputs/aar/
iOS
To build iOS frameworks for all architectures:
./gradlew linkReleaseFrameworkIosArm64
./gradlew linkReleaseFrameworkIosSimulatorArm64
./gradlew linkReleaseFrameworkIosX64Output locations:
- iOS ARM64 (device):
build/bin/iosArm64/releaseFramework/ - iOS Simulator ARM64:
build/bin/iosSimulatorArm64/releaseFramework/ - iOS Simulator x64:
build/bin/iosX64/releaseFramework/
Web/JS
To build the JavaScript bundle:
./gradlew jsBrowserDistributionOutput location: build/dist/js/production
Configuration
The project uses Moko Resources for multiplatform resource management rather than Kotlinx Resources. All string resources are organized by feature modules and are automatically included in builds for all supported platforms.
License
MIT License
