├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── issue_template.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── build.yml ├── .gitignore ├── .travis.yml ├── CNAME ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── build.gradle ├── dynamic-locale ├── build.gradle ├── maven.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ ├── androidx │ └── appcompat │ │ └── app │ │ └── DynamicLocaleDelegate.java │ └── com │ └── pranavpandey │ └── android │ └── dynamic │ └── locale │ ├── DynamicLocale.java │ └── DynamicLocaleUtils.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── graphics ├── icon.png ├── icon.psd └── legacy │ ├── icon.png │ └── icon.psd └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: pranavpandey 4 | patreon: pranavpandey 5 | open_collective: pranavpandeydev 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['paypal.me/pranavpandeydev'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Issue 3 | about: Create a issue to help us improve 4 | title: "Short description of the issue" 5 | --- 6 | 7 | **Description:** Full description of the issue. 8 | 9 | **Expected behavior:** Screenshots and/or description of the expected behavior. 10 | 11 | **Source code:** [OPTIONAL] The code snippet which is causing this issue. 12 | 13 | **Sample app and/or repro:** [OPTIONAL] A sample app or steps to reproduce the issue. You may attach a `zip` or `APK` file of the sample app or a link to the GitHub repository. 14 | 15 | **Android API version:** Android API version. `API 19` 16 | 17 | **Library version:** The Library version you are using. `1.0.0` 18 | 19 | **Device:** Device on which the bug was encountered. `Emulator or Brand Model` 20 | 21 | *Please make sure that you are using the [latest version](https://github.com/pranavpandey/dynamic-locale/releases) of the library and we also accept [pull requests](https://github.com/pranavpandey/dynamic-locale/pulls).* 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Thanks for starting a pull request! 2 | 3 | ## Changes 4 | 5 | - 6 | - 7 | 8 | ## Testing 9 | 10 | Describe how you tested your changes. 11 | 12 | ## Issues 13 | 14 | [OPTIONAL] Link to GitHub issues it solves. `Resolve #1234` 15 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | timeout-minutes: 60 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v3 16 | 17 | - name: Setup JDK 17 18 | uses: actions/setup-java@v3 19 | with: 20 | distribution: 'zulu' 21 | java-version: 17 22 | 23 | - name: Setup Gradle 24 | uses: gradle/gradle-build-action@v2 25 | 26 | - name: Build with Gradle 27 | run: | 28 | chmod +x gradlew 29 | ./gradlew build 30 | 31 | - name: Generate Javadoc 32 | if: github.ref_type == 'tag' 33 | run: ./gradlew generateJavadoc 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | release/ 19 | 20 | # IntelliJ project files 21 | **.iml 22 | .idea 23 | 24 | # Android Studio captures folder 25 | captures/ 26 | 27 | # Local configuration file (sdk path, etc) 28 | local.properties 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | # Log Files 34 | *.log 35 | 36 | # Misc 37 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk17 3 | 4 | before_install: 5 | - mkdir "$ANDROID_HOME/licenses" || true 6 | - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" 7 | - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" 8 | 9 | android: 10 | components: 11 | - tools 12 | - platform-tools 13 | - build-tools-35.0.0 14 | - android-35 15 | - extra-android-support 16 | - extra-android-m2repository 17 | - extra-google-m2repository 18 | before_script: 19 | - chmod +x gradlew 20 | script: 21 | - ./gradlew build 22 | 23 | after_success: 24 | - ./gradlew generateJavadoc 25 | 26 | deploy: 27 | provider: pages 28 | token: $GITHUB_TOKEN 29 | edge: true 30 | keep_history: true 31 | local_dir: dynamic-locale/build/docs/javadoc/release 32 | on: 33 | branch: master 34 | tags: true 35 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | pranavpandey.org -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | support@pranavpandey.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series of 86 | actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or permanent 93 | ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within the 113 | community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.1, available at 119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 123 | 124 | For answers to common questions about this code of conduct, see the FAQ at 125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 126 | [https://www.contributor-covenant.org/translations][translations]. 127 | 128 | [homepage]: https://www.contributor-covenant.org 129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 130 | [Mozilla CoC]: https://github.com/mozilla/diversity 131 | [FAQ]: https://www.contributor-covenant.org/faq 132 | [translations]: https://www.contributor-covenant.org/translations 133 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2019-2024 Pranav Pandey 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Dynamic Locale 4 | 5 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?)](https://www.apache.org/licenses/LICENSE-2.0.html) 6 | [![Build Status](https://travis-ci.org/pranavpandey/dynamic-locale.svg?branch=master)](https://travis-ci.org/pranavpandey/dynamic-locale) 7 | [![Release](https://img.shields.io/maven-central/v/com.pranavpandey.android/dynamic-locale)](https://search.maven.org/artifact/com.pranavpandey.android/dynamic-locale) 8 | 9 | **A library to perform runtime locale changes on Android 4.1 (API 16) and above.** 10 | 11 | > [!IMPORTANT] 12 | > It uses [AndroidX][androidx] so, first [migrate][androidx-migrate] your project to AndroidX. 13 |
Since v2.1.0, it is dependent on Java 8 due to the dependency on 14 | [Dynamic Utils](https://github.com/pranavpandey/dynamic-utils). 15 |
Since v2.4.1, it is targeting Java 17 to provide maximum compatibility. 16 |
Since v2.5.0, the minimum SDK is Android 4.4 (API 19) to comply with the latest policies. 17 | 18 | --- 19 | 20 | ## Contents 21 | 22 | - [Installation](#installation) 23 | - [Usage](#usage) 24 | - [Application](#application) 25 | - [Activity](#activity) 26 | - [Dependency](#dependency) 27 | - [License](#license) 28 | 29 | --- 30 | 31 | ## Installation 32 | 33 | It can be installed by adding the following dependency to your `build.gradle` file: 34 | 35 | ```groovy 36 | dependencies { 37 | // For AndroidX enabled projects. 38 | implementation 'com.pranavpandey.android:dynamic-locale:2.5.0' 39 | } 40 | ``` 41 | 42 | --- 43 | 44 | ## Usage 45 | 46 | It provides an [interface][dynamic-locale] that can be implemented in the 47 | [application][dynamic-application] or [activity][dynamic-activity] class to provide the modified 48 | base `context`. It has optional feature to provide `font scale` to make the text smaller or larger. 49 | It would be beneficial for some specific locales and theme styles. 50 | 51 | > For a complete reference, please read the [documentation][documentation]. 52 | 53 | ### Application 54 | 55 | Implement the `DynamicLocale` interface for the `application` class by using the 56 | [helper][dynamic-locale-utils] class and register it in the `AndroidManifest` to apply 57 | the locale at runtime. 58 | 59 | > While using it for the application class, you should update the `context` when user 60 | > configuration changes as Android caches the application in the memory and the 61 | > `attachBaseContext(Context)` might not be called each time. 62 | > 63 | > Please check an example [here][dynamic-application-example]. 64 | 65 | ```java 66 | public class DynamicApp extends Application implements DynamicLocale { 67 | 68 | @Override 69 | public void attachBaseContext(@NonNull Context base) { 70 | // Set the dynamic locale. 71 | super.attachBaseContext(setLocale(base)); 72 | } 73 | 74 | @Override 75 | public @Nullable String[] getSupportedLocales() { 76 | // Returns an array of supported locales. 77 | return new String[] { 78 | Locale.ENGLISH.toString(), 79 | Locale.GERMAN.toString(), 80 | new Locale(DynamicLocaleUtils.ADS_LOCALE_SPANISH, "").toString(), 81 | new Locale(DynamicLocaleUtils.ADS_LOCALE_INDONESIA, "").toString(), 82 | Locale.ITALIAN.toString(), 83 | new Locale(DynamicLocaleUtils.ADS_LOCALE_TURKISH, "").toString(), 84 | Locale.CHINESE.toString() }; 85 | } 86 | 87 | @Override 88 | public @NonNull Locale getDefaultLocale(@NonNull Context context) { 89 | // Returns the default locale to be used if no dynamic locale support is provided. 90 | return DynamicLocaleUtils.getDefaultLocale(context, getSupportedLocales()); 91 | } 92 | 93 | @Override 94 | public @Nullable Locale getLocale() { 95 | // Returns the locale to be applied. 96 | return DynamicLocaleUtils.toLocale(DynamicLocaleUtils.ADS_LOCALE_HINDI); 97 | } 98 | 99 | @Override 100 | public @NonNull Context setLocale(@NonNull Context context) { 101 | // Apply the locale according to the configuration. 102 | return DynamicLocaleUtils.setLocale(context, 103 | DynamicLocaleUtils.getLocale(getLocale(), 104 | getDefaultLocale(context)), getFontScale()); 105 | } 106 | 107 | @Override 108 | public float getFontScale() { 109 | // Returns the font scale to be applied. 110 | // Use the default font scale. 111 | return 1f; 112 | } 113 | } 114 | ``` 115 | 116 | ### Activity 117 | 118 | Similarly, it can be used for the `activity` to apply locale at runtime. 119 | 120 | > You should `recreate()` the activity when user configuration changes. 121 | 122 | ```java 123 | public class DynamicActivity extends Activity implements DynamicLocale { 124 | 125 | @Override 126 | public void attachBaseContext(@NonNull Context base) { 127 | // Set the dynamic locale. 128 | super.attachBaseContext(setLocale(base)); 129 | } 130 | 131 | ... 132 | 133 | @Override 134 | public @NonNull Context setLocale(@NonNull Context context) { 135 | // Apply the locale according to the configuration. 136 | return DynamicLocaleUtils.setLocale(context, 137 | DynamicLocaleUtils.getLocale(getLocale(), 138 | getDefaultLocale(context)), getFontScale()); 139 | } 140 | 141 | ... 142 | } 143 | ``` 144 | 145 | ### Dependency 146 | 147 | It depends on the [dynamic-utils][dynamic-utils] to perform various internal operations. 148 | So, its functions can also be used to perform other useful operations. 149 | 150 | --- 151 | 152 | ## Author 153 | 154 | Pranav Pandey 155 | 156 | [![GitHub](https://img.shields.io/github/followers/pranavpandey?label=GitHub&style=social)](https://github.com/pranavpandey) 157 | [![Follow on Twitter](https://img.shields.io/twitter/follow/pranavpandeydev?label=Follow&style=social)](https://twitter.com/intent/follow?screen_name=pranavpandeydev) 158 | [![Donate via PayPal](https://img.shields.io/static/v1?label=Donate&message=PayPal&color=blue)](https://paypal.me/pranavpandeydev) 159 | 160 | --- 161 | 162 | ## License 163 | 164 | Copyright 2019-2024 Pranav Pandey 165 | 166 | Licensed under the Apache License, Version 2.0 (the "License"); 167 | you may not use this file except in compliance with the License. 168 | You may obtain a copy of the License at 169 | 170 | http://www.apache.org/licenses/LICENSE-2.0 171 | 172 | Unless required by applicable law or agreed to in writing, software 173 | distributed under the License is distributed on an "AS IS" BASIS, 174 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 175 | See the License for the specific language governing permissions and 176 | limitations under the License. 177 | 178 | 179 | [androidx]: https://developer.android.com/jetpack/androidx 180 | [androidx-migrate]: https://developer.android.com/jetpack/androidx/migrate 181 | [documentation]: https://pranavpandey.github.io/dynamic-locale 182 | [dynamic-locale]: https://github.com/pranavpandey/dynamic-locale/blob/master/dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocale.java 183 | [dynamic-application]: https://github.com/pranavpandey/dynamic-support/blob/master/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java 184 | [dynamic-application-example]: https://github.com/pranavpandey/dynamic-support/blob/5d94b3e700e49b55008069f42763965f6d3bf033/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java#L206 185 | [dynamic-activity]: https://github.com/pranavpandey/dynamic-support/blob/master/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java 186 | [dynamic-locale-utils]: https://github.com/pranavpandey/dynamic-locale/blob/master/dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocaleUtils.java 187 | [dynamic-utils]: https://github.com/pranavpandey/dynamic-utils 188 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2025 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | ext.versions = [ 19 | 'compileSdk': 35, 20 | 'minSdk' : 21, 21 | 'targetSdk' : 35, 22 | 'buildTools': '35.0.0', 23 | 'appcompat' : '1.7.1', 24 | 'dynamic' : '4.6.1', 25 | 'kotlin' : '1.9.24' 26 | ] 27 | 28 | repositories { 29 | mavenCentral() 30 | google() 31 | } 32 | 33 | dependencies { 34 | classpath 'com.android.tools.build:gradle:8.7.3' 35 | } 36 | } 37 | 38 | plugins { 39 | id("io.github.gradle-nexus.publish-plugin") version "2.0.0" 40 | } 41 | 42 | allprojects { 43 | repositories { 44 | mavenCentral() 45 | google() 46 | } 47 | } 48 | 49 | tasks.register('clean', Delete) { 50 | delete rootProject.layout.buildDirectory 51 | } 52 | 53 | ext { 54 | projectName = 'dynamic-locale' 55 | projectDesc = 'A library to perform runtime locale changes on Android.' 56 | versionDesc = 'A library to perform runtime locale changes on Android 4.1 (API 16) and above.' 57 | referenceTitle = 'Dynamic Locale API reference' 58 | 59 | siteUrl = 'https://github.com/pranavpandey/dynamic-locale' 60 | gitUrl = 'https://github.com/pranavpandey/dynamic-locale' 61 | issueUrl = 'https://github.com/pranavpandey/dynamic-locale/issues' 62 | githubUrl = 'pranavpandey/dynamic-locale' 63 | 64 | mavenRepo = 'android' 65 | mavenGroup = 'com.pranavpandey.android' 66 | mavenDir = 'com/pranavpandey/android' 67 | mavenArtifactId = 'dynamic-locale' 68 | mavenInceptionYear = '2019' 69 | mavenVersion = '2.5.0' 70 | mavenVersionCode = 16 71 | 72 | developerId = 'pranavpandey' 73 | developerName = 'Pranav Pandey' 74 | developerEmail = 'dynamic@pranavpandey.com' 75 | 76 | licenseName = 'The Apache Software License, Version 2.0' 77 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 78 | licenseDistribution = 'repo' 79 | allLicenses = ["Apache-2.0"] 80 | 81 | publication = 'local.properties' 82 | 83 | ext["signing.keyId"] = '' 84 | ext["signing.password"] = '' 85 | ext["signing.secretKeyRingFile"] = '' 86 | 87 | ossrhUsername = '' 88 | ossrhPassword = '' 89 | sonatypeStagingProfileId = '' 90 | } 91 | 92 | apply plugin: 'io.github.gradle-nexus.publish-plugin' 93 | 94 | File publish = project.rootProject.file("${publication}") 95 | if (publish.exists()) { 96 | Properties properties = new Properties() 97 | new FileInputStream(publish).withCloseable { is -> properties.load(is) } 98 | properties.each { name, value -> ext[name] = value } 99 | } 100 | 101 | nexusPublishing { 102 | repositories { 103 | sonatype { 104 | username = ossrhUsername 105 | password = ossrhPassword 106 | stagingProfileId = sonatypeStagingProfileId 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /dynamic-locale/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2024 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.library' 18 | 19 | android { 20 | compileSdkVersion versions.compileSdk 21 | buildToolsVersion versions.buildTools 22 | namespace 'com.pranavpandey.android.dynamic.locale' 23 | 24 | defaultConfig { 25 | minSdkVersion versions.minSdk 26 | targetSdkVersion versions.targetSdk 27 | } 28 | 29 | sourceSets { 30 | main.res.srcDirs 'res' 31 | } 32 | 33 | compileOptions { 34 | sourceCompatibility JavaVersion.VERSION_17 35 | targetCompatibility JavaVersion.VERSION_17 36 | } 37 | } 38 | 39 | dependencies { 40 | implementation(platform("org.jetbrains.kotlin:kotlin-bom:${versions.kotlin}")) 41 | 42 | api "com.pranavpandey.android:dynamic-utils:${versions.dynamic}" 43 | api "androidx.appcompat:appcompat:${versions.appcompat}" 44 | } 45 | 46 | if (project.rootProject.file("${publication}").exists()) { 47 | apply from: 'maven.gradle' 48 | } 49 | 50 | tasks.register('generateJavadoc') { 51 | description "Generates Javadoc." 52 | } 53 | 54 | project.afterEvaluate { 55 | android.libraryVariants.configureEach { variant -> 56 | def task = project.tasks.create( 57 | "generate${variant.name.capitalize()}Javadoc", Javadoc) { 58 | title "${referenceTitle}

${versionDesc}

${mavenVersion}
" 59 | description "Generates Javadoc for $variant.name." 60 | destinationDir = new File(destinationDir, variant.baseName) 61 | 62 | source = variant.sourceSets.collect { 63 | it.java.sourceFiles 64 | }.inject { 65 | m, i -> m + i 66 | } 67 | doFirst { 68 | classpath = project.files(variant.javaCompileProvider.get().classpath.files, 69 | project.android.getBootClasspath()) 70 | } 71 | 72 | if (JavaVersion.current().isJava8Compatible()) { 73 | options.addStringOption('Xdoclint:none', '-quiet') 74 | } 75 | 76 | options.memberLevel = JavadocMemberLevel.PROTECTED 77 | exclude "**/R", "**/R.**", "**/R\$**", "**/BuildConfig*" 78 | 79 | options.windowTitle = "${referenceTitle}" 80 | options.links('http://docs.oracle.com/javase/8/docs/api', 81 | 'http://docs.oracle.com/javase/17/docs/api') 82 | options.links('https://developer.android.com/reference') 83 | options.linksOffline('https://developer.android.com/reference', 84 | 'https://developer.android.com/reference/androidx') 85 | options.links('https://pranavpandey.org/dynamic-utils') 86 | 87 | failOnError false 88 | } 89 | 90 | task.dependsOn "assemble${variant.name.capitalize()}" 91 | generateJavadoc.dependsOn task 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /dynamic-locale/maven.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2024 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven-publish' 18 | apply plugin: 'signing' 19 | 20 | group = mavenGroup 21 | version = mavenVersion 22 | 23 | // Android libraries 24 | if (project.hasProperty("android")) { 25 | tasks.register('sourcesJar', Jar) { 26 | archiveClassifier.set("sources") 27 | from android.sourceSets.main.java.srcDirs 28 | } 29 | 30 | tasks.register('javadoc', Javadoc) { 31 | dependsOn "generateReleaseRFile" 32 | title "${referenceTitle}

${versionDesc}

${mavenVersion}
" 33 | failOnError = false 34 | 35 | source = android.sourceSets.main.java.sourceFiles 36 | doNotTrackState("Javadoc needs to be generated every time.") 37 | 38 | if (JavaVersion.current().isJava8Compatible()) { 39 | options.addStringOption('Xdoclint:none', '-quiet') 40 | } 41 | 42 | options.memberLevel = JavadocMemberLevel.PROTECTED 43 | exclude "**/R", "**/R.**", "**/R\$**", "**/BuildConfig*" 44 | 45 | options.windowTitle = "${referenceTitle}" 46 | options.links('http://docs.oracle.com/javase/8/docs/api', 47 | 'http://docs.oracle.com/javase/17/docs/api') 48 | options.links('https://developer.android.com/reference') 49 | options.linksOffline('https://developer.android.com/reference', 50 | 'https://developer.android.com/reference/androidx') 51 | options.links('https://pranavpandey.org/dynamic-utils') 52 | } 53 | } else { // Java libraries 54 | tasks.register('sourcesJar', Jar) { 55 | dependsOn classes 56 | 57 | archiveClassifier.set("sources") 58 | from sourceSets.main.allSource 59 | } 60 | } 61 | 62 | tasks.register('javadocJar', Jar) { 63 | dependsOn javadoc 64 | 65 | archiveClassifier.set("javadoc") 66 | from javadoc.destinationDir 67 | } 68 | 69 | artifacts { 70 | archives javadocJar 71 | archives sourcesJar 72 | } 73 | 74 | // Maven 75 | publishing { 76 | publications { 77 | library(MavenPublication) { 78 | groupId mavenGroup 79 | artifactId mavenArtifactId 80 | version mavenVersion 81 | 82 | artifact "$buildDir/outputs/aar/$mavenArtifactId-release.aar" 83 | artifact javadocJar 84 | artifact sourcesJar 85 | 86 | pom.withXml { 87 | // Project 88 | asNode().appendNode('name', projectName) 89 | asNode().appendNode('description', projectDesc) 90 | asNode().appendNode('url', siteUrl) 91 | asNode().appendNode('inceptionYear', mavenInceptionYear) 92 | 93 | // Licenses 94 | def license = asNode().appendNode('licenses').appendNode('license') 95 | license.appendNode('name', licenseName) 96 | license.appendNode('url', licenseUrl) 97 | license.appendNode('distribution', licenseDistribution) 98 | 99 | // Developers 100 | def developer = asNode().appendNode('developers').appendNode('developer') 101 | developer.appendNode('id', developerId) 102 | developer.appendNode('name', developerName) 103 | developer.appendNode('email', developerEmail) 104 | 105 | // SCM 106 | def scm = asNode().appendNode('scm') 107 | scm.appendNode('connection', "scm:git:${gitUrl}.git") 108 | scm.appendNode('developerConnection', gitUrl) 109 | scm.appendNode('url', siteUrl) 110 | 111 | // Dependencies 112 | def dependenciesNode = asNode()['dependencies'][0] 113 | if (dependenciesNode == null) { 114 | dependenciesNode = asNode().appendNode('dependencies') 115 | } 116 | 117 | // Add all that are 'compile' dependencies. 118 | configurations.api.allDependencies.each { 119 | def dependencyNode = dependenciesNode.appendNode('dependency') 120 | dependencyNode.appendNode('groupId', it.group) 121 | dependencyNode.appendNode('artifactId', it.name) 122 | dependencyNode.appendNode('version', it.version) 123 | } 124 | } 125 | } 126 | } 127 | } 128 | 129 | ext["signing.keyId"] = rootProject.ext["signing.keyId"] 130 | ext["signing.password"] = rootProject.ext["signing.password"] 131 | ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"] 132 | 133 | signing { 134 | sign publishing.publications 135 | } 136 | 137 | afterEvaluate { project -> 138 | // Fix javadoc generation. 139 | javadoc.classpath += files(android.libraryVariants.collect { variant -> 140 | variant.javaCompileProvider.get().classpath.files 141 | }) 142 | 143 | def pomTask = "generatePomFileForLibraryPublication" 144 | def dependencies = [javadocJar, sourcesJar, assembleRelease, pomTask] 145 | 146 | // Convenience task to prepare everything we need for releases. 147 | tasks.register('prepareArtifacts') { 148 | dependsOn dependencies 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /dynamic-locale/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /dynamic-locale/src/main/java/androidx/appcompat/app/DynamicLocaleDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package androidx.appcompat.app; 18 | 19 | import android.content.Context; 20 | import android.content.res.Configuration; 21 | import android.os.Build; 22 | import android.os.Bundle; 23 | import android.util.AttributeSet; 24 | import android.view.MenuInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | 28 | import androidx.annotation.IdRes; 29 | import androidx.annotation.LayoutRes; 30 | import androidx.annotation.NonNull; 31 | import androidx.annotation.Nullable; 32 | import androidx.annotation.RequiresApi; 33 | import androidx.annotation.StyleRes; 34 | import androidx.appcompat.view.ActionMode; 35 | import androidx.appcompat.widget.Toolbar; 36 | 37 | import com.pranavpandey.android.dynamic.locale.DynamicLocale; 38 | 39 | /** 40 | * An {@link AppCompatDelegate} to properly apply the locale configurations. 41 | * 42 | * @see More info 43 | */ 44 | public class DynamicLocaleDelegate extends AppCompatDelegate { 45 | 46 | /** 47 | * The super delegate used by this delegate. 48 | */ 49 | private final AppCompatDelegate mSuperDelegate; 50 | 51 | /** 52 | * The dynamic locale used by this delegate. 53 | */ 54 | private final DynamicLocale mDynamicLocale; 55 | 56 | /** 57 | * Constructor to initialize an object of this class. 58 | * 59 | * @param superDelegate The super delegate for this instance. 60 | * @param dynamicLocale The dynamic locale for this instance. 61 | */ 62 | public DynamicLocaleDelegate(@NonNull AppCompatDelegate superDelegate, 63 | @Nullable DynamicLocale dynamicLocale) { 64 | super(); 65 | 66 | this.mSuperDelegate = superDelegate; 67 | this.mDynamicLocale = dynamicLocale; 68 | } 69 | 70 | /** 71 | * Get the super delegate used by this delegate. 72 | * 73 | * @return The super delegate used by this delegate. 74 | */ 75 | public @NonNull AppCompatDelegate getSuperDelegate() { 76 | return mSuperDelegate; 77 | } 78 | 79 | /** 80 | * Get the dynamic locale used by this delegate. 81 | * 82 | * @return The dynamic locale used by this delegate. 83 | */ 84 | public @Nullable DynamicLocale getDynamicLocale() { 85 | return mDynamicLocale; 86 | } 87 | 88 | /** 89 | * Wrap the base context if required. 90 | * 91 | * @param context The base context to be wrapped. 92 | * 93 | * @return The wrapped base context. 94 | */ 95 | public @NonNull Context wrapBaseContext(@NonNull Context context) { 96 | if (getDynamicLocale() != null) { 97 | return getDynamicLocale().setLocale(context); 98 | } 99 | 100 | return context; 101 | } 102 | 103 | @Override 104 | public @Nullable ActionBar getSupportActionBar() { 105 | return getSuperDelegate().getSupportActionBar(); 106 | } 107 | 108 | @Override 109 | public void setSupportActionBar(@Nullable Toolbar toolbar) { 110 | getSuperDelegate().setSupportActionBar(toolbar); 111 | } 112 | 113 | @Override 114 | public MenuInflater getMenuInflater() { 115 | return getSuperDelegate().getMenuInflater(); 116 | } 117 | 118 | @Override 119 | public void onCreate(Bundle savedInstanceState) { 120 | getSuperDelegate().onCreate(savedInstanceState); 121 | 122 | removeActivityDelegate(getSuperDelegate()); 123 | addActiveDelegate(this); 124 | } 125 | 126 | @Override 127 | public void onPostCreate(Bundle savedInstanceState) { 128 | getSuperDelegate().onPostCreate(savedInstanceState); 129 | } 130 | 131 | @Override 132 | public void onConfigurationChanged(Configuration newConfig) { 133 | getSuperDelegate().onConfigurationChanged(newConfig); 134 | } 135 | 136 | @Override 137 | public void onStart() { 138 | getSuperDelegate().onStart(); 139 | } 140 | 141 | @Override 142 | public void onStop() { 143 | getSuperDelegate().onStop(); 144 | } 145 | 146 | @Override 147 | public void onPostResume() { 148 | getSuperDelegate().onPostResume(); 149 | } 150 | 151 | @Override 152 | public void setTheme(@StyleRes int themeResId) { 153 | getSuperDelegate().setTheme(themeResId); 154 | } 155 | 156 | @Override 157 | public @Nullable T findViewById(@IdRes int id) { 158 | return getSuperDelegate().findViewById(id); 159 | } 160 | 161 | @Override 162 | public void setContentView(View v) { 163 | getSuperDelegate().setContentView(v); 164 | } 165 | 166 | @Override 167 | public void setContentView(@LayoutRes int resId) { 168 | getSuperDelegate().setContentView(resId); 169 | } 170 | 171 | @Override 172 | public void setContentView(View v, ViewGroup.LayoutParams lp) { 173 | getSuperDelegate().setContentView(v, lp); 174 | } 175 | 176 | @Override 177 | public void addContentView(View v, ViewGroup.LayoutParams lp) { 178 | getSuperDelegate().addContentView(v, lp); 179 | } 180 | 181 | @Override 182 | public @NonNull Context attachBaseContext2(@NonNull Context context) { 183 | return wrapBaseContext(getSuperDelegate().attachBaseContext2( 184 | super.attachBaseContext2(context))); 185 | } 186 | 187 | @Override 188 | public void setTitle(@Nullable CharSequence title) { 189 | getSuperDelegate().setTitle(title); 190 | } 191 | 192 | @Override 193 | public void invalidateOptionsMenu() { 194 | getSuperDelegate().invalidateOptionsMenu(); 195 | } 196 | 197 | @Override 198 | public void onDestroy() { 199 | getSuperDelegate().onDestroy(); 200 | removeActivityDelegate(this); 201 | } 202 | 203 | @Override 204 | public @Nullable ActionBarDrawerToggle.Delegate getDrawerToggleDelegate() { 205 | return getSuperDelegate().getDrawerToggleDelegate(); 206 | } 207 | 208 | @Override 209 | public boolean requestWindowFeature(int featureId) { 210 | return getSuperDelegate().requestWindowFeature(featureId); 211 | } 212 | 213 | @Override 214 | public boolean hasWindowFeature(int featureId) { 215 | return getSuperDelegate().hasWindowFeature(featureId); 216 | } 217 | 218 | @Override 219 | public @Nullable ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback) { 220 | return getSuperDelegate().startSupportActionMode(callback); 221 | } 222 | 223 | @Override 224 | public void installViewFactory() { 225 | getSuperDelegate().installViewFactory(); 226 | } 227 | 228 | @Override 229 | public View createView(@Nullable View parent, String name, 230 | @NonNull Context context, @NonNull AttributeSet attrs) { 231 | return getSuperDelegate().createView(parent, name, context, attrs); 232 | } 233 | 234 | @Override 235 | public void setHandleNativeActionModesEnabled(boolean enabled) { 236 | getSuperDelegate().setHandleNativeActionModesEnabled(enabled); 237 | } 238 | 239 | @Override 240 | public boolean isHandleNativeActionModesEnabled() { 241 | return getSuperDelegate().isHandleNativeActionModesEnabled(); 242 | } 243 | 244 | @Override 245 | public void onSaveInstanceState(Bundle outState) { 246 | getSuperDelegate().onSaveInstanceState(outState); 247 | } 248 | 249 | @Override 250 | public boolean applyDayNight() { 251 | return getSuperDelegate().applyDayNight(); 252 | } 253 | 254 | @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 255 | @Override 256 | public void setLocalNightMode(@NightMode int mode) { 257 | getSuperDelegate().setLocalNightMode(mode); 258 | } 259 | 260 | @Override 261 | public @NightMode int getLocalNightMode() { 262 | return getSuperDelegate().getLocalNightMode(); 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocale.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pranavpandey.android.dynamic.locale; 18 | 19 | import android.content.Context; 20 | import android.content.res.Configuration; 21 | 22 | import androidx.annotation.NonNull; 23 | import androidx.annotation.Nullable; 24 | 25 | import java.util.Locale; 26 | 27 | /** 28 | * An interface to implement the dynamic locale throughout the app. 29 | */ 30 | public interface DynamicLocale { 31 | 32 | /** 33 | * Constant value for the system locale. 34 | */ 35 | String SYSTEM = "ads_locale_system"; 36 | 37 | /** 38 | * Constant value for the Spanish locale. 39 | */ 40 | String SPANISH = "es"; 41 | 42 | /** 43 | * Constant value for the Hindi locale. 44 | */ 45 | String HINDI = "hi"; 46 | 47 | /** 48 | * Constant value for the Indonesian locale. 49 | */ 50 | String INDONESIA = "in"; 51 | 52 | /** 53 | * Constant value for the Russian locale. 54 | */ 55 | String RUSSIAN = "ru"; 56 | 57 | /** 58 | * Constant value for the Portuguese locale. 59 | */ 60 | String PORTUGUESE = "pt"; 61 | 62 | /** 63 | * Constant value for the Turkish locale. 64 | */ 65 | String TURKISH = "tr"; 66 | 67 | /** 68 | * Dynamic locale splitter to separate language, country, etc. 69 | */ 70 | String SPLIT = ","; 71 | 72 | /** 73 | * Returns an array of supported locales. 74 | * 75 | * @return The array of supported locales. 76 | * 77 | * @see androidx.core.os.ConfigurationCompat#getLocales(Configuration) 78 | */ 79 | @Nullable String[] getSupportedLocales(); 80 | 81 | /** 82 | * Returns the default locale to be used if no dynamic locale support is provided. 83 | * 84 | * @param context The context to get configuration. 85 | * 86 | * @return The default locale to be used if no dynamic locale support is provided. 87 | * 88 | * @see #getLocale() 89 | */ 90 | @NonNull Locale getDefaultLocale(@NonNull Context context); 91 | 92 | /** 93 | * Returns the locale to be applied. 94 | * 95 | * @return The locale to be applied. 96 | * 97 | * @see Locale 98 | */ 99 | @Nullable Locale getLocale(); 100 | 101 | /** 102 | * Apply the locale according to the configuration. 103 | * 104 | * @param context The context to set the locale. 105 | * 106 | * @return The modified context after applying the locale. 107 | */ 108 | @NonNull Context setLocale(@NonNull Context context); 109 | 110 | /** 111 | * Returns the font scale to be applied. 112 | * 113 | * @return The font scale to be applied. 114 | */ 115 | float getFontScale(); 116 | } 117 | -------------------------------------------------------------------------------- /dynamic-locale/src/main/java/com/pranavpandey/android/dynamic/locale/DynamicLocaleUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pranavpandey.android.dynamic.locale; 18 | 19 | import android.annotation.TargetApi; 20 | import android.app.Activity; 21 | import android.app.LocaleManager; 22 | import android.content.Context; 23 | import android.content.res.Configuration; 24 | import android.content.res.Resources; 25 | import android.os.Build; 26 | import android.os.LocaleList; 27 | 28 | import androidx.annotation.NonNull; 29 | import androidx.annotation.Nullable; 30 | import androidx.core.content.ContextCompat; 31 | import androidx.core.os.ConfigurationCompat; 32 | import androidx.core.text.TextUtilsCompat; 33 | import androidx.core.view.ViewCompat; 34 | 35 | import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; 36 | 37 | import java.util.Locale; 38 | 39 | /** 40 | * Helper class to perform various locale operations. 41 | */ 42 | public class DynamicLocaleUtils { 43 | 44 | /** 45 | * Default value to set application locale on API 33 and above. 46 | */ 47 | private static final boolean ADL_SYSTEM = false; 48 | 49 | /** 50 | * Default value to update activity resources on legacy devices. 51 | */ 52 | private static final boolean ADL_ACTIVITY = true; 53 | 54 | /** 55 | * Returns the locale manager on API 33. 56 | * 57 | * @param context The context to be used. 58 | * 59 | * @return The locale manager on API 33. 60 | */ 61 | @TargetApi(Build.VERSION_CODES.TIRAMISU) 62 | public static @Nullable LocaleManager getLocaleManager(@Nullable Context context) { 63 | if (!DynamicSdkUtils.is33() || context == null) { 64 | return null; 65 | } 66 | 67 | return ContextCompat.getSystemService(context, LocaleManager.class); 68 | } 69 | 70 | /** 71 | * Returns the layout direction for the selected locale. 72 | * 73 | * @param context The context to be used. 74 | * 75 | * @return The layout direction for the selected locale. 76 | * 77 | * @see ViewCompat#LAYOUT_DIRECTION_LTR 78 | * @see ViewCompat#LAYOUT_DIRECTION_RTL 79 | * @see ViewCompat#LAYOUT_DIRECTION_INHERIT 80 | * @see ViewCompat#LAYOUT_DIRECTION_LOCALE 81 | */ 82 | public static int getLayoutDirection(@Nullable Context context) { 83 | return TextUtilsCompat.getLayoutDirectionFromLocale(context != null 84 | ? getCurrentLocale(context) : Locale.getDefault()); 85 | } 86 | 87 | /** 88 | * Checks whether the layout direction is RTL (right-to-left). 89 | * 90 | * @param context The context to be used. 91 | * 92 | * @return {@code true} if the layout direction is RTL (right-to-left). 93 | * 94 | * @see #getLayoutDirection(Context) 95 | * @see ViewCompat#LAYOUT_DIRECTION_RTL 96 | */ 97 | public static boolean isLayoutRtl(@Nullable Context context) { 98 | return DynamicSdkUtils.is17() && getLayoutDirection(context) 99 | == ViewCompat.LAYOUT_DIRECTION_RTL; 100 | } 101 | 102 | /** 103 | * Checks whether the layout direction is RTL (right-to-left). 104 | * 105 | * @return {@code true} if the layout direction is RTL (right-to-left). 106 | * 107 | * @see #isLayoutRtl(Context) 108 | */ 109 | public static boolean isLayoutRtl() { 110 | return isLayoutRtl(null); 111 | } 112 | 113 | /** 114 | * Get locale from the locale string in the format: {@code language,region}. 115 | * 116 | * @param locale The locale string to be converted. 117 | * 118 | * @return The converted locale from the locale string. 119 | *

Return {@code null} for the default locale value. 120 | * 121 | * @see DynamicLocale#SYSTEM 122 | */ 123 | public static @Nullable Locale toLocale(@Nullable String locale) { 124 | Locale localeWithRegion; 125 | if (locale == null || locale.equals(DynamicLocale.SYSTEM)) { 126 | localeWithRegion = null; 127 | } else { 128 | String[] localeFormat = locale.split(DynamicLocale.SPLIT); 129 | localeWithRegion = new Locale(localeFormat[0]); 130 | if (localeFormat.length > 1) { 131 | localeWithRegion = new Locale(localeFormat[0], localeFormat[1]); 132 | } 133 | } 134 | 135 | return localeWithRegion; 136 | } 137 | 138 | /** 139 | * Get the default locale language from the supported locales. 140 | * 141 | * @param context The context to get the configuration. 142 | * @param supportedLocales The supported locales. 143 | * 144 | * @return The default locale according to the supported locales. 145 | */ 146 | @TargetApi(Build.VERSION_CODES.TIRAMISU) 147 | public static @NonNull Locale getDefaultLocale( 148 | @Nullable Context context, @Nullable String[] supportedLocales) { 149 | if (DynamicSdkUtils.is33()) { 150 | LocaleManager localeManager; 151 | if ((localeManager = getLocaleManager(context)) != null 152 | && !localeManager.getApplicationLocales().isEmpty()) { 153 | return supportedLocales != null 154 | ? localeManager.getApplicationLocales().getFirstMatch(supportedLocales) 155 | : localeManager.getApplicationLocales().get(0); 156 | } 157 | } 158 | 159 | Locale defaultLocale = supportedLocales != null ? ConfigurationCompat.getLocales( 160 | Resources.getSystem().getConfiguration()).getFirstMatch(supportedLocales) 161 | : ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0); 162 | 163 | return defaultLocale != null ? defaultLocale : Locale.getDefault(); 164 | } 165 | 166 | /** 167 | * Returns the locale after performing safety checks. 168 | * 169 | * @param locale The locale to be checked. 170 | * @param defaultLocale The default locale if current locale does not passes checks. 171 | * 172 | * @return The locale after performing safety checks. 173 | */ 174 | public static @NonNull Locale getLocale(@Nullable Locale locale, 175 | @NonNull Locale defaultLocale) { 176 | return locale == null ? defaultLocale : locale; 177 | } 178 | 179 | /** 180 | * Set the locale for a given context. 181 | * 182 | * @param context The context to set the locale. 183 | * @param activity {@code true} if the context an instance of {@link Activity}. 184 | * @param locale The locale to be used for the context resources. 185 | * @param fontScale The font scale to be used for the context resources. 186 | * @param system {@code true} to set application locales on API 33 and above. 187 | * 188 | * @return The modified context after applying the locale. 189 | * 190 | * @see LocaleManager#setApplicationLocales(LocaleList) 191 | */ 192 | @TargetApi(Build.VERSION_CODES.TIRAMISU) 193 | public static @NonNull Context setLocale(@NonNull Context context, 194 | boolean activity, @Nullable Locale locale, float fontScale, boolean system) { 195 | if (locale == null) { 196 | return context; 197 | } 198 | 199 | if (DynamicSdkUtils.is17()) { 200 | if (system && DynamicSdkUtils.is33()) { 201 | LocaleManager localeManager; 202 | if ((localeManager = getLocaleManager(context)) != null) { 203 | localeManager.setApplicationLocales(new LocaleList(locale)); 204 | } 205 | } 206 | 207 | return updateResources(context, activity, locale, fontScale); 208 | } 209 | 210 | return updateResourcesLegacy(context, locale, fontScale); 211 | } 212 | 213 | /** 214 | * Set the locale for a given context. 215 | * 216 | * @param context The context to set the locale. 217 | * @param activity {@code true} if the context an instance of {@link Activity}. 218 | * @param locale The locale to be used for the context resources. 219 | * @param fontScale The font scale to be used for the context resources. 220 | * 221 | * @return The modified context after applying the locale. 222 | * 223 | * @see #setLocale(Context, boolean, Locale, float, boolean) 224 | */ 225 | @TargetApi(Build.VERSION_CODES.TIRAMISU) 226 | public static @NonNull Context setLocale(@NonNull Context context, 227 | boolean activity, @Nullable Locale locale, float fontScale) { 228 | return setLocale(context, activity, locale, fontScale, ADL_SYSTEM); 229 | } 230 | 231 | /** 232 | * Set the locale for a given context. 233 | * 234 | * @param context The context to set the locale. 235 | * @param locale The locale to be used for the context resources. 236 | * @param fontScale The font scale to be used for the context resources. 237 | * @param system {@code true} to set application locales on API 33 and above. 238 | * 239 | * @return The modified context after applying the locale. 240 | * 241 | * @see #setLocale(Context, boolean, Locale, float, boolean) 242 | */ 243 | public static @NonNull Context setLocale(@NonNull Context context, 244 | @Nullable Locale locale, float fontScale, boolean system) { 245 | return setLocale(context, ADL_ACTIVITY, locale, fontScale, system); 246 | } 247 | 248 | /** 249 | * Set the locale for a given context. 250 | * 251 | * @param context The context to set the locale. 252 | * @param locale The locale to be used for the context resources. 253 | * @param fontScale The font scale to be used for the context resources. 254 | * 255 | * @return The modified context after applying the locale. 256 | * 257 | * @see #setLocale(Context, Locale, float, boolean) 258 | */ 259 | public static @NonNull Context setLocale(@NonNull Context context, 260 | @Nullable Locale locale, float fontScale) { 261 | return setLocale(context, locale, fontScale, ADL_SYSTEM); 262 | } 263 | 264 | /** 265 | * Set the locale for a given configuration. 266 | * 267 | * @param config The config to set the locale. 268 | * @param locale The locale to be used for the context resources. 269 | * @param fontScale The font scale to be used for the context resources. 270 | * 271 | * @return The modified context after applying the locale. 272 | */ 273 | @SuppressWarnings("deprecation") 274 | @TargetApi(Build.VERSION_CODES.N) 275 | public static @NonNull Configuration setLocale(@NonNull Configuration config, 276 | @Nullable Locale locale, float fontScale) { 277 | config.fontScale = fontScale; 278 | 279 | if (locale != null) { 280 | if (DynamicSdkUtils.is17()) { 281 | config.setLocale(locale); 282 | } else { 283 | config.locale = locale; 284 | } 285 | } 286 | 287 | return config; 288 | } 289 | 290 | /** 291 | * Update resources for a given context after setting the locale on API 17 and above. 292 | * 293 | * @param context The context to set the updated resources. 294 | * @param activity {@code true} if the context an instance of {@link Activity}. 295 | * @param locale The locale to be used for the context resources. 296 | * @param fontScale The font scale to be used for the context resources. 297 | * 298 | * @return The modified context after applying the locale. 299 | */ 300 | @SuppressWarnings("deprecation") 301 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 302 | private static @NonNull Context updateResources(@NonNull Context context, 303 | boolean activity, @NonNull Locale locale, float fontScale) { 304 | Configuration configuration = new Configuration( 305 | context.getResources().getConfiguration()); 306 | configuration.fontScale = fontScale; 307 | configuration.setLocale(locale); 308 | configuration.setLayoutDirection(locale); 309 | 310 | if (activity) { 311 | // Fix for app compat 1.2.0. 312 | return context.createConfigurationContext(configuration); 313 | } else { 314 | // Fix for application font scale. 315 | context.createConfigurationContext(configuration); 316 | context.getResources().updateConfiguration(configuration, 317 | context.getResources().getDisplayMetrics()); 318 | 319 | return context; 320 | } 321 | } 322 | 323 | /** 324 | * Update resources for a given context after setting the locale on API 16 and below. 325 | * 326 | * @param context The context to set the updated resources. 327 | * @param locale The locale to be used for the context resources. 328 | * @param fontScale The font scale to be used for the context resources. 329 | * 330 | * @return The modified context after applying the locale. 331 | */ 332 | @SuppressWarnings("deprecation") 333 | private static @NonNull Context updateResourcesLegacy(@NonNull Context context, 334 | @NonNull Locale locale, float fontScale) { 335 | Resources res = context.getResources(); 336 | Configuration configuration = new Configuration(res.getConfiguration()); 337 | configuration.fontScale = fontScale; 338 | configuration.locale = locale; 339 | 340 | context.getResources().updateConfiguration(configuration, res.getDisplayMetrics()); 341 | return context; 342 | } 343 | 344 | /** 345 | * Returns the current locale for the supplied context. 346 | * 347 | * @param context The context to get the resources. 348 | * 349 | * @return The current locale for the supplied context. 350 | */ 351 | public static @NonNull Locale getCurrentLocale(@Nullable Context context) { 352 | Locale currentLocale; 353 | if ((currentLocale = ConfigurationCompat.getLocales(context != null 354 | ? context.getResources().getConfiguration() 355 | : Resources.getSystem().getConfiguration()).get(0)) != null) { 356 | return currentLocale; 357 | } 358 | 359 | return Locale.getDefault(); 360 | } 361 | } 362 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | android.nonTransitiveRClass=false 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavpandey/dynamic-locale/c705028b848e95f329c8ef19ed4f60ed9dd40418/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 29 17:16:21 IST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /graphics/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavpandey/dynamic-locale/c705028b848e95f329c8ef19ed4f60ed9dd40418/graphics/icon.png -------------------------------------------------------------------------------- /graphics/icon.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavpandey/dynamic-locale/c705028b848e95f329c8ef19ed4f60ed9dd40418/graphics/icon.psd -------------------------------------------------------------------------------- /graphics/legacy/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavpandey/dynamic-locale/c705028b848e95f329c8ef19ed4f60ed9dd40418/graphics/legacy/icon.png -------------------------------------------------------------------------------- /graphics/legacy/icon.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavpandey/dynamic-locale/c705028b848e95f329c8ef19ed4f60ed9dd40418/graphics/legacy/icon.psd -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Pranav Pandey 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':dynamic-locale' 18 | --------------------------------------------------------------------------------