{"id":17472378,"url":"https://github.com/pranavpandey/dynamic-locale","last_synced_at":"2025-04-22T10:46:04.666Z","repository":{"id":88144585,"uuid":"214565693","full_name":"pranavpandey/dynamic-locale","owner":"pranavpandey","description":"Perform runtime locale changes on Android.","archived":false,"fork":false,"pushed_at":"2025-03-05T19:20:16.000Z","size":1150,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T20:26:10.750Z","etag":null,"topics":["android","font-scale","library","locale","runtime"],"latest_commit_sha":null,"homepage":"https://dynamic.pranavpandey.com","language":"Java","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/pranavpandey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"pranavpandey","patreon":"pranavpandey","open_collective":"pranavpandeydev","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["paypal.me/pranavpandeydev"]}},"created_at":"2019-10-12T02:47:04.000Z","updated_at":"2025-03-05T19:20:20.000Z","dependencies_parsed_at":"2023-12-10T14:47:39.895Z","dependency_job_id":null,"html_url":"https://github.com/pranavpandey/dynamic-locale","commit_stats":{"total_commits":78,"total_committers":1,"mean_commits":78.0,"dds":0.0,"last_synced_commit":"d4e812300b890b6a5e18715db92a065508009143"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranavpandey%2Fdynamic-locale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranavpandey%2Fdynamic-locale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranavpandey%2Fdynamic-locale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranavpandey%2Fdynamic-locale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pranavpandey","download_url":"https://codeload.github.com/pranavpandey/dynamic-locale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249184650,"owners_count":21226428,"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","font-scale","library","locale","runtime"],"created_at":"2024-10-18T17:09:09.547Z","updated_at":"2025-04-16T16:31:54.178Z","avatar_url":"https://github.com/pranavpandey.png","language":"Java","funding_links":["https://github.com/sponsors/pranavpandey","https://patreon.com/pranavpandey","https://opencollective.com/pranavpandeydev","paypal.me/pranavpandeydev","https://paypal.me/pranavpandeydev"],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./graphics/icon.png\" height=\"160\"\u003e\n\n# Dynamic Locale\n\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![Build Status](https://travis-ci.org/pranavpandey/dynamic-locale.svg?branch=master)](https://travis-ci.org/pranavpandey/dynamic-locale)\n[![Release](https://img.shields.io/maven-central/v/com.pranavpandey.android/dynamic-locale)](https://search.maven.org/artifact/com.pranavpandey.android/dynamic-locale)\n\n**A library to perform runtime locale changes on Android 4.1 (API 16) and above.**\n\n\u003e [!IMPORTANT]\n\u003e It uses [AndroidX][androidx] so, first [migrate][androidx-migrate] your project to AndroidX.\n\u003cbr/\u003eSince v2.1.0, it is dependent on Java 8 due to the dependency on\n[Dynamic Utils](https://github.com/pranavpandey/dynamic-utils).\n\u003cbr/\u003eSince v2.4.1, it is targeting Java 17 to provide maximum compatibility.\n\u003cbr/\u003eSince v2.5.0, the minimum SDK is Android 4.4 (API 19) to comply with the latest policies.\n\n---\n\n## Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Application](#application)\n    - [Activity](#activity)\n    - [Dependency](#dependency)\n- [License](#license)\n\n---\n\n## Installation\n\nIt can be installed by adding the following dependency to your `build.gradle` file:\n\n```groovy\ndependencies {\n    // For AndroidX enabled projects.\n    implementation 'com.pranavpandey.android:dynamic-locale:2.5.0'\n}\n```\n\n---\n\n## Usage\n\nIt provides an [interface][dynamic-locale] that can be implemented in the \n[application][dynamic-application] or [activity][dynamic-activity] class to provide the modified\nbase `context`. It has optional feature to provide `font scale` to make the text smaller or larger. \nIt would be beneficial for some specific locales and theme styles.\n\n\u003e For a complete reference, please read the [documentation][documentation].\n\n### Application\n\nImplement the `DynamicLocale` interface for the `application` class by using the \n[helper][dynamic-locale-utils] class and register it in the `AndroidManifest` to apply \nthe locale at runtime.\n\n\u003e While using it for the application class, you should update the `context` when user \n\u003e configuration changes as Android caches the application in the memory and the \n\u003e `attachBaseContext(Context)` might not be called each time. \n\u003e\n\u003e Please check an example [here][dynamic-application-example].\n\n```java\npublic class DynamicApp extends Application implements DynamicLocale {\n\n    @Override\n    public void attachBaseContext(@NonNull Context base) {\n        // Set the dynamic locale.\n        super.attachBaseContext(setLocale(base));\n    }    \n\n    @Override\n    public @Nullable String[] getSupportedLocales() {\n        // Returns an array of supported locales.\n        return new String[] {\n            Locale.ENGLISH.toString(),\n                Locale.GERMAN.toString(),\n                new Locale(DynamicLocaleUtils.ADS_LOCALE_SPANISH, \"\").toString(),\n                new Locale(DynamicLocaleUtils.ADS_LOCALE_INDONESIA, \"\").toString(),\n                Locale.ITALIAN.toString(),\n                new Locale(DynamicLocaleUtils.ADS_LOCALE_TURKISH, \"\").toString(),\n                Locale.CHINESE.toString() };\n    }\n\n    @Override\n    public @NonNull Locale getDefaultLocale(@NonNull Context context) {\n        // Returns the default locale to be used if no dynamic locale support is provided.\n        return DynamicLocaleUtils.getDefaultLocale(context, getSupportedLocales());\n    }\n    \n    @Override\n    public @Nullable Locale getLocale() {\n        // Returns the locale to be applied.\n        return DynamicLocaleUtils.toLocale(DynamicLocaleUtils.ADS_LOCALE_HINDI);\n    }\n\n    @Override\n    public @NonNull Context setLocale(@NonNull Context context) {\n        // Apply the locale according to the configuration.\n        return DynamicLocaleUtils.setLocale(context,\n                DynamicLocaleUtils.getLocale(getLocale(),\n                    getDefaultLocale(context)), getFontScale());\n    }\n\n    @Override\n    public float getFontScale() {\n        // Returns the font scale to be applied.\n        // Use the default font scale.\n        return 1f;\n    }\n}\n```\n\n### Activity\n\nSimilarly, it can be used for the `activity` to apply locale at runtime.\n\n\u003e You should `recreate()` the activity when user configuration changes.\n\n```java\npublic class DynamicActivity extends Activity implements DynamicLocale {\n\n    @Override\n    public void attachBaseContext(@NonNull Context base) {\n        // Set the dynamic locale.\n        super.attachBaseContext(setLocale(base));\n    }    \n\n    ...\n\n    @Override\n    public @NonNull Context setLocale(@NonNull Context context) {\n        // Apply the locale according to the configuration.\n        return DynamicLocaleUtils.setLocale(context,\n                DynamicLocaleUtils.getLocale(getLocale(),\n                    getDefaultLocale(context)), getFontScale());\n    }\n\n    ...\n}\n```\n\n### Dependency\n\nIt depends on the [dynamic-utils][dynamic-utils] to perform various internal operations. \nSo, its functions can also be used to perform other useful operations.\n\n---\n\n## Author\n\nPranav Pandey\n\n[![GitHub](https://img.shields.io/github/followers/pranavpandey?label=GitHub\u0026style=social)](https://github.com/pranavpandey)\n[![Follow on Twitter](https://img.shields.io/twitter/follow/pranavpandeydev?label=Follow\u0026style=social)](https://twitter.com/intent/follow?screen_name=pranavpandeydev)\n[![Donate via PayPal](https://img.shields.io/static/v1?label=Donate\u0026message=PayPal\u0026color=blue)](https://paypal.me/pranavpandeydev)\n\n---\n\n## License\n\n    Copyright 2019-2024 Pranav Pandey\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n[androidx]: https://developer.android.com/jetpack/androidx\n[androidx-migrate]: https://developer.android.com/jetpack/androidx/migrate\n[documentation]: https://pranavpandey.github.io/dynamic-locale\n[dynamic-locale]: https://github.com/pranavpandey/dynamic-locale/blob/master/dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocale.java\n[dynamic-application]: https://github.com/pranavpandey/dynamic-support/blob/master/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java\n[dynamic-application-example]: https://github.com/pranavpandey/dynamic-support/blob/5d94b3e700e49b55008069f42763965f6d3bf033/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java#L206\n[dynamic-activity]: https://github.com/pranavpandey/dynamic-support/blob/master/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java\n[dynamic-locale-utils]: https://github.com/pranavpandey/dynamic-locale/blob/master/dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocaleUtils.java\n[dynamic-utils]: https://github.com/pranavpandey/dynamic-utils\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranavpandey%2Fdynamic-locale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpranavpandey%2Fdynamic-locale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranavpandey%2Fdynamic-locale/lists"}