{"id":13572883,"url":"https://github.com/PocketByte/locolaser-kotlin-mpp-example","last_synced_at":"2025-04-04T11:30:57.630Z","repository":{"id":84412975,"uuid":"137796406","full_name":"PocketByte/locolaser-kotlin-mpp-example","owner":"PocketByte","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-26T20:28:23.000Z","size":425,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T23:42:02.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PocketByte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-18T19:22:05.000Z","updated_at":"2024-05-25T08:42:41.000Z","dependencies_parsed_at":"2023-09-27T01:19:25.624Z","dependency_job_id":null,"html_url":"https://github.com/PocketByte/locolaser-kotlin-mpp-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PocketByte%2Flocolaser-kotlin-mpp-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PocketByte%2Flocolaser-kotlin-mpp-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PocketByte%2Flocolaser-kotlin-mpp-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PocketByte%2Flocolaser-kotlin-mpp-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PocketByte","download_url":"https://codeload.github.com/PocketByte/locolaser-kotlin-mpp-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247170031,"owners_count":20895397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:00:23.120Z","updated_at":"2025-04-04T11:30:52.620Z","avatar_url":"https://github.com/PocketByte.png","language":"JavaScript","readme":"# LocoLaser Kotlin Multiplatform Example\n[LocoLaser](https://github.com/PocketByte/LocoLaser/) - Localization tool that generate localization files for various platforms depends on common source.\n\u003cbr\u003eThis example shows how to use LocoLaser in Kotlin Mobile Multiplatform projects to generate localized strings repository class with common interface for both mobile platforms: Android and iOS.\n\n##### 1 Step: Add artifacts dependency\nChoose which type of artifact you will use and add them as **`classpath`** dependency. \nThis example uses artifact to work with Kotlin Mobile Multiplatform projects:\n```groovy\nbuildscript {\n    repositories {\n        // 1.1: Add maven repositories\n        maven { url \"https://plugins.gradle.org/m2/\" }\n        mavenCentral()\n        ...\n    }\n    dependencies {\n        // 1.2: Add plugin classpath dependency\n        classpath \"gradle.plugin.ru.pocketbyte.locolaser:plugin:2.2.5\"\n        \n        // 1.3: Add dependency for Kotlin Multiplatform\n        classpath \"ru.pocketbyte.locolaser:platform-kotlin-mpp:2.2.5\"\n        // 1.4: Add dependency for JSON platform (for JS i18next)\n        classpath \"ru.pocketbyte.locolaser:platform-json:2.2.5\"\n        \n        ...\n    }\n}\n```\n\n##### 2 Step: Apply and configure gradle plugin\nExample uses standard way to apply custom gradle plugin.\u003cbr\u003e\nApply plugin in **`build.gradle`** of common module:\n```groovy\n// 2.1: Apply LocoLaser plugin\napply plugin: \"ru.pocketbyte.locolaser\"\n\n// 2.2: Configure localization config\nlocalize {\n    configFromFile(\"${project.projectDir}/localize_config.json\")\n}\n```\n\n##### 3 Step: Create configuration file\nHow to build config file you can find in Wiki:[Platform: Kotlin Mobile Multiplatform](https://github.com/PocketByte/LocoLaser/wiki/Platform:-Kotlin-Mobile-Multiplatform) \nBy default this config file should have name`\"localize_config.json\"` and be placed in the root folder of the project.\n\n##### 4 Step: Run task 'localize' before build\nThis example run **`:localize`** task before each build. To do it add task dependencies in **`build.gradle`** of common module:\n```groovy\n// 4 Run task ‘localize’ before each build\npreBuild.dependsOn {\n    project.tasks.getByPath(':common:localize')\n}\n```\n\n\n##### 5 Step: Init repository\nAs a final step instance of Strings repository should be created. This example use common object [Repository](https://github.com/PocketByte/locolaser-kotlin-mpp-example/blob/master/common/src/commonMain/kotlin/ru/pocketbyte/locolaser/example/repository/Repository.kt) with ‘expect’ modifier. This object should be implemented for each platform independently.\nIn Android application it's better to implement [standard singleton](https://github.com/PocketByte/locolaser-kotlin-mpp-example/blob/master/common/src/androidMain/kotlin/ru/pocketbyte/locolaser/example/repository/Repository.kt) and initialize it in `Application` class in method `onCreate`:\n```kotlin\n// 5.1 Init Android Repository\nRepository.initInstance(AndroidStringRepository(this))\n```\nIn iOS application it's better to initialize property right in [property declaration](https://github.com/PocketByte/locolaser-kotlin-mpp-example/blob/master/common/src/iosMain/kotlin/ru/pocketbyte/locolaser/example/repository/Repository.kt)\n\nJS implementation require `i18next` object as parameter So at first first add dependency with externals into common **`build.gradle`**:\n```groovy\nkotlin {\n    sourceSets {\n        jsMain {\n            // 5.2 Add i18next dependency\n            dependencies {\n                api \"ru.pocketbyte.locolaser:i18next-externals:1.0\"\n            }\n        }\n    }\n}\n```\nThen you should initialize it before use:\n```kotlin\ni18next.init(localizationConfig) { _, _ -\u003e\n    // 5.3 Init JS Repository\n    Repository.init(JsStringRepository(i18next))\n    ...\n}\n```\n\n##### Usage in code\nNow any string can be received using code as following:\n```kotlin\nRepository.str.screen_main_hello_text\n```\n\n##### 6 Step: Move generated files into build folder\nBecause String Repository classes generated depends on string resources, no need to hold them together with other source classes and commit into git. This example overrides `res_dir` of kotlin classes and put them into folders `./build/generated/locolaser/[platform]`. To tell gradle plugin about this files, add source dirs into **`gradle.build`** of common module:\n```groovy\n\nkotlin {\n    sourceSets {\n        commonMain {\n            // 6.1 Add source dir for generated common classes\n            kotlin.srcDir('./build/generated/locolaser/common/')\n            \n            ...\n        }\n\n        androidMain {\n            // 6.2 Add source dir for generated android classes\n            kotlin.srcDir('./build/generated/locolaser/android/')\n            \n            ...\n        }\n\n        jsMain {\n            // 6.3 Add source dir for generated js classes\n            kotlin.srcDir('./build/generated/locolaser/js/')\n\n            ...\n        }\n\n        iosMain {\n            // 6.4 Add source dir for generated iOS classes\n            kotlin.srcDir('./build/generated/locolaser/ios/')\n            \n            ...\n        }\n    }\n    ...\n}\n```\n\n## License\n```\nCopyright © 2019 Denis Shurygin. All rights reserved.\nContacts: \u003cmail@pocketbyte.ru\u003e\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPocketByte%2Flocolaser-kotlin-mpp-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPocketByte%2Flocolaser-kotlin-mpp-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPocketByte%2Flocolaser-kotlin-mpp-example/lists"}