From cc49dca7249bdcd8a39e316cb625c5db6f995d4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 15 Dec 2023 03:34:35 +0600 Subject: [PATCH] add resources docs --- docs/micro_utils/resources.md | 44 +++++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 45 insertions(+) create mode 100644 docs/micro_utils/resources.md diff --git a/docs/micro_utils/resources.md b/docs/micro_utils/resources.md new file mode 100644 index 0000000..359d7d1 --- /dev/null +++ b/docs/micro_utils/resources.md @@ -0,0 +1,44 @@ +# Resources + +**Package**: `dev.inmo:micro_utils.resources` + +This package aimed to make some multiplatform support for resources of your application. As for now, __there is only +support for strings__. Sample: + +```kotlin +object Translations { + val someVariable = buildStringResource( + "Sample default string" + ) { + IetfLanguageCode.German variant lazy "Beispiel für eine Standardzeichenkette" + } +} +``` + +In this case, you will be able to use it with next logic: + +```kotlin +Translation.someVariable.translation(IetfLanguageCode.French) // "Sample default string" as default one +Translation.someVariable.translation(IetfLanguageCode.German) // "Beispiel für eine Standardzeichenkette" as available variant +Translation.someVariable.translation(IetfLanguageCode.German.DE) // "Beispiel für eine Standardzeichenkette" as available parent variant +``` + +## Additional opportunities on Android platform + +On Android you may use `Configuration` (as well as `Resources` or `Context`) to get translation for current locale. For +example: + +```kotlin +val context: Context = // context retrieving + +context.translation(Translation.someVariable) +``` + +## Additional opportunities on JVM platform + +On JVM platform you usually may use `Locale.getDefault()` to get `Locale` object and pass it to `translation` extension: + +```kotlin +Translation.someVariable.translation(Locale.getDefault()) +Translation.someVariable.translation() // Locale.getDefault() hidden +``` diff --git a/mkdocs.yml b/mkdocs.yml index 3753082..3be243b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,6 +10,7 @@ nav: - Home: 'index.md' - 'MicroUtils': - 'micro_utils/index.md' + - 'micro_utils/resources.md' - 'Telegram Bot API': - 'tgbotapi/index.md' - KDocs: 'https://tgbotapi.inmo.dev'