{"id":13605233,"url":"https://github.com/B3nedikt/AppLocale","last_synced_at":"2025-04-12T05:32:14.412Z","repository":{"id":43680184,"uuid":"234939423","full_name":"B3nedikt/AppLocale","owner":"B3nedikt","description":"AppLocale is a android library to update the app language dynamically.","archived":false,"fork":false,"pushed_at":"2023-09-26T11:03:10.000Z","size":526,"stargazers_count":135,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-07T10:40:53.700Z","etag":null,"topics":["android-library","kotlin"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/B3nedikt.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":"2020-01-19T17:41:53.000Z","updated_at":"2024-08-05T06:13:57.000Z","dependencies_parsed_at":"2024-01-16T23:30:17.506Z","dependency_job_id":"d3821f79-b309-4d1d-87b4-74ac3321e243","html_url":"https://github.com/B3nedikt/AppLocale","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B3nedikt%2FAppLocale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B3nedikt%2FAppLocale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B3nedikt%2FAppLocale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/B3nedikt%2FAppLocale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/B3nedikt","download_url":"https://codeload.github.com/B3nedikt/AppLocale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248524024,"owners_count":21118606,"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":["android-library","kotlin"],"created_at":"2024-08-01T19:00:56.138Z","updated_at":"2025-04-12T05:32:13.836Z","avatar_url":"https://github.com/B3nedikt.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.b3nedikt.applocale/applocale/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.b3nedikt.applocale/applocale)\n[![Build \u0026 Test](https://github.com/B3nedikt/AppLocale/actions/workflows/build-and-test.yaml/badge.svg)](https://github.com/B3nedikt/AppLocale/actions/workflows/build-and-test.yaml)\n[![codecov](https://codecov.io/gh/B3nedikt/applocale/branch/master/graph/badge.svg)](https://codecov.io/gh/B3nedikt/applocale)\n[![javadoc](https://javadoc.io/badge2/dev.b3nedikt.applocale/applocale/javadoc.svg)](https://javadoc.io/doc/dev.b3nedikt.applocale/applocale)\n\n## App Locale 3.1.0\n\nAppLocale is a android library to change the app language dynamically.\n\n### 1. Add dependencies\n\nIn addition to appcompat from androidX which you most likely already use,\nthe following three dependencies are needed:\n\n```groovy\n// Manages the Locale used by the app\nimplementation 'dev.b3nedikt.applocale:applocale:3.1.0'\n\n// Needed to intercept view inflation\nimplementation 'dev.b3nedikt.viewpump:viewpump:4.0.10'\n\n// Allows to update the text of views at runtime without recreating the activity\nimplementation 'dev.b3nedikt.reword:reword:4.0.4'\n```\n\n### 2. Initialize\n\nInitialize ViewPump \u0026 Reword in your `Application` class:\n\n```kotlin\n// To dynamically update views we need to intercept view inflation and update\n// the text of each view. The libraries ViewPump and reword do exactly that when setup\n// like this:\nViewPump.init(RewordInterceptor)\n```\n\n### 3. Inject into Context\n\nIf you use your application `Context` to retrieve string resources add the following to your\n`Application` class:\n\n```kotlin\nclass SampleApplication : Application() {\n\n    ...\n\n    override fun getResources(): Resources {\n        return AppLocale.wrapResources(applicationContext, super.getResources())\n    }\n}\n```\n\nIf you have a BaseActivity you can add this there, otherwise you have to add it to all of your activities:\n\n```kotlin\nabstract class BaseActivity : AppCompatActivity() {\n\n    private val appCompatDelegate: AppCompatDelegate by lazy {\n        ViewPumpAppCompatDelegate(\n                baseDelegate = super.getDelegate(),\n                baseContext = this,\n                wrapContext = AppLocale::wrap\n        )\n    }\n\n    override fun getDelegate(): AppCompatDelegate {\n        return appCompatDelegate\n    }\n}\n```\n\n### 3. Update the app language\n\nNow we can just set the desiredLocale to the Locale we want our app to use:\n\n```kotlin\nAppLocale.desiredLocale = Locale.FRENCH\n```\n\nWhen the activity gets restarted, all texts will be localized using the new Locale.\n\nAlternativeley you can reload the UI like this:\n\n```kotlin\n// If we want to update the app language without restarting the activity,\n// we need to perform the update of the texts manually:\nval rootView = window.decorView.findViewById\u003cContentFrameLayout\u003e(android.R.id.content)\nReword.reword(rootView)\n```\n\nIf you use this approach and you changed the texts of views in code, you need to update these\ntexts manually of course.\n\n## App Bundle support\n\nIf you use the new android app bundle (aab) format to distribute your app, android\nwill strip out all languages which are not the users devices default language.\nTo disable this add this to your build.gradle:\n\n```groovy\nandroid {\n    bundle {\n        language {\n            // We want to be able to switch the locale at runtime using AppLocale!\n            enableSplit = false\n        }\n    }\n}\n```\n\nAlternatively load the languages dynamically using the playcore library as described in its\n[Documentation](https://developer.android.com/guide/playcore/dynamic-delivery#lang_resources).\n\n## License\n\n```\nCopyright 2020 applocale Contributors.\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FB3nedikt%2FAppLocale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FB3nedikt%2FAppLocale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FB3nedikt%2FAppLocale/lists"}