https://github.com/mewebstudio/spring-boot-jpa-translatable-kotlin
Spring Boot JPA Translatable Kotlin - Maven package
https://github.com/mewebstudio/spring-boot-jpa-translatable-kotlin
hibernate jpa kotlin maven spring-boot translatable
Last synced: 28 days ago
JSON representation
Spring Boot JPA Translatable Kotlin - Maven package
- Host: GitHub
- URL: https://github.com/mewebstudio/spring-boot-jpa-translatable-kotlin
- Owner: mewebstudio
- License: mit
- Created: 2025-05-07T22:44:53.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-05-07T23:22:36.000Z (about 1 month ago)
- Last Synced: 2025-05-08T00:24:35.914Z (about 1 month ago)
- Topics: hibernate, jpa, kotlin, maven, spring-boot, translatable
- Language: Kotlin
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Translatable for Spring Boot JPA (Kotlin)
[](https://opensource.org/licenses/MIT)
[](https://central.sonatype.com/artifact/com.mewebstudio/spring-boot-jpa-translatable-kotlin)
[](https://javadoc.io/doc/com.mewebstudio/spring-boot-jpa-translatable-kotlin)This module provides an abstract and reusable foundation for supporting **translatable (multi-language) entities** using Spring Data JPA.
It defines core interfaces, abstract repositories, and a base service class to handle translations with locale-specific logic.---
## 📦 Package Structure
```
com.mewebstudio.springboot.jpa.translatable
├── ITranslatable.kt
├── ITranslation.kt
├── JpaTranslatableRepository.kt
├── JpaTranslationRepository.kt
└── AbstractTranslatableService.kt
```---
## 🧩 Interfaces
### `ITranslatable>`
Represents an entity that supports translations.
```kotlin
interface ITranslatable> {
val id: ID
val translations: MutableList
}
```---
### `ITranslation`
Represents a translation of an entity in a specific locale.
```kotlin
interface ITranslation {
val id: ID
val owner: T
val locale: String
}
```---
## 🗃 Repositories
### `JpaTranslatableRepository, ID, TR : ITranslation> : JpaRepository`
Generic JPA repository for translatable entities.
```kotlin
@NoRepositoryBean
interface JpaTranslatableRepository, ID, TR : ITranslation> : JpaRepository {
// ...
}
```---
### `JpaTranslationRepository`
Generic JPA repository for translation entities.
```kotlin
@NoRepositoryBean
interface JpaTranslationRepository, ID, OWNER> : JpaRepository {
// ...
}
```---
## 🧠 Abstract Service
### `AbstractTranslatableService`
Provides a base service class for business logic operations.
```kotlin
abstract class AbstractTranslatableService, ID, TR : ITranslation>(
open val repository: JpaTranslatableRepository
) {
// ...
}
```### `AbstractTranslationService, ID, OWNER>`
Provides a base service class for business logic operations.
```kotlin
abstract class AbstractTranslationService, ID, OWNER>(
open val repository: JpaTranslationRepository
) {
// ...
}
```---
## 📥 Installation
#### for maven users
Add the following dependency to your `pom.xml` file:
```xmlcom.mewebstudio
spring-boot-jpa-translatable-kotlin
0.1.0```
#### for gradle users
Add the following dependency to your `build.gradle` file:
```groovy
implementation 'com.mewebstudio:spring-boot-jpa-translatable-kotlin:0.1.0'
```---
## 📌 Usage
You can extend these interfaces and abstract class to implement your own translatable entities and services:
### Translatable Entity Example
```kotlin
@Entity
@Table(name = "categories")
class Category(
@Id
val id: Long,@OneToMany(mappedBy = "owner", cascade = [CascadeType.ALL], orphanRemoval = true, fetch = FetchType.LAZY)
@OrderBy("locale ASC")
override var translations: MutableList = mutableListOf(),
) : ITranslatable {
override fun toString(): String = "${this::class.simpleName}(id = $id)"
}
```### Translation Entity Example
```kotlin
@Entity
class CategoryTranslation(
@Id
val id: Long,@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
override val owner: Category,@Column(name = "locale", nullable = false)
override val locale: String,@Column(name = "name", nullable = false, length = 255)
var name: String,@Column(name = "description", columnDefinition = "text")
var description: String? = null,
) : ITranslation {
override fun toString(): String =
"${this::class.simpleName}(id = $id, name = $name, locale = $locale, owner = $owner)"
}
```### Translatable Repository Example
```kotlin
interface CategoryRepository : JpaTranslatableRepository
```### Translation Repository Example
```kotlin
interface CategoryTranslationRepository : JpaTranslationRepository
```### Translatable Service Example
```kotlin
@Service
class CategoryService(
private val categoryRepository: CategoryRepository,
private val categoryTranslationRepository: CategoryTranslationRepository
) : AbstractTranslatableService(categoryRepository) {
private val log: Logger by logger()init {
log.debug("CategoryService initialized with repository: {}", repository)
requireNotNull(repository) { "CategoryRepository cannot be null" }
}// Custom business logic methods can be added here...
}
```---
## 🛠 Requirements
- Java 17+
- Kotlin 1.9.23+
- Spring Boot 3.x
- Spring Data JPA---
## 🔁 Other Implementations
[Spring Boot JPA Translatable (Java Maven Package)](https://github.com/mewebstudio/spring-boot-jpa-translatable)
## 💡 Example Implementations
[Spring Boot JPA Translatable - Kotlin Implementation](https://github.com/mewebstudio/spring-boot-jpa-translatable-kotlin-impl)
[Spring Boot JPA Translatable - Java Implementation](https://github.com/mewebstudio/spring-boot-jpa-translatable-java-impl)
## 📃 License
MIT © [mewebstudio](https://github.com/mewebstudio)