Tolgee

open class Tolgee(val config: Tolgee.Config)(source)

The Tolgee class serves as the primary interface for interacting with the Tolgee localization and translation framework. It provides mechanisms for managing languages, locales, and translations in a coroutine-safe and thread-safe manner, ensuring seamless integration of localization features into Kotlin-based applications.

This class maintains internal caches and reactive flows for efficient retrieval and updates of translations and locales, prioritizing both performance and flexibility in multilingual environments.

Core features include:

  • Loading and caching of project languages and translations

  • Locale management with support for reactive updates

  • On-demand and immediate translation resolution

Designed for applications requiring dynamic multilingual support, the Tolgee class ensures thread-safe access patterns and handles asynchronous operations efficiently to maintain consistent behavior.

Properties:

  • config: Configuration settings for the Tolgee instance.

Methods:

  • tFlow: Processes and streams dynamic translations for a given key and parameters.

  • t: Immediately resolves a translation for a given key and parameters.

  • preload: Preloads languages and translations into memory for subsequent use.

  • setLocale: Updates the current locale using various parameter types.

Inheritors

Constructors

Link copied to clipboard
constructor(config: Tolgee.Config)

Types

Link copied to clipboard
interface ChangeListener

Interface for listening to changes in Tolgee translations.

Link copied to clipboard
object Companion

The companion object for the Tolgee class, providing static methods and properties to manage the global state and initialization of Tolgee instances.

Link copied to clipboard
data class Config

Represents the configuration used for API integration and content management.

Link copied to clipboard
sealed interface Formatter

Represents a formatter interface used for defining different formatting strategies for translations within the Tolgee platform.

Properties

Link copied to clipboard
val changeFlow: MutableSharedFlow<Unit>

A flow that emits whenever translations change.

Link copied to clipboard

Functions

Link copied to clipboard

Registers a listener to be notified when translations change.

Link copied to clipboard
open fun getLocale(): Locale

Gets the current locale for the Tolgee instance.

Link copied to clipboard
open suspend fun preload()

Preloads the required languages and their translations for the current Tolgee instance.

Link copied to clipboard

Unregisters a previously registered change listener.

Link copied to clipboard
open fun setLocale(locale: Locale): Locale

Sets the current locale for the Tolgee instance, updating it in the reactive locale flow.

open fun setLocale(localeTag: String): Locale

Adjusts the current locale used for translations.

Link copied to clipboard
open fun t(key: String, parameters: TolgeeMessageParams = TolgeeMessageParams.None): String?

Immediate Tolgee translation for a key with parameters.

Link copied to clipboard
open fun tArray(key: String): List<String>
Link copied to clipboard
open fun tArrayFlow(key: String): Flow<List<String>>
Link copied to clipboard
open fun tFlow(key: String, parameters: TolgeeMessageParams = TolgeeMessageParams.None): Flow<String>

Updating Tolgee translation for a key with parameters.