All Projects β†’ franmontiel β†’ Localechanger

franmontiel / Localechanger

Licence: apache-2.0
An Android library to programmatically set the Locale of an app and persist the configuration.

Programming Languages

java
68154 projects - #9 most used programming language
language
365 projects

Projects that are alternatives of or similar to Localechanger

Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+867%)
Mutual labels:  i18n, localization
Atom I18n
:atom: One Atom i18n Package for Any Locale 🌏 🌎 🌍
Stars: ✭ 56 (-44%)
Mutual labels:  i18n, localization
Parse Decimal Number
🏧 Parse a decimal number with i18n format support (localized decimal points and comma separators)
Stars: ✭ 33 (-67%)
Mutual labels:  i18n, localization
Keys Translations Manager
KTM, a locale management web app built on MERN stack, lets you manage and control locales in one place. It's particularly useful for someone who needs to manage multiple internationalization/localization projects.
Stars: ✭ 81 (-19%)
Mutual labels:  i18n, localization
Locale2
πŸ’ͺ Try as hard as possible to detect the client's language tag ("locale") in node or the browser. Browserify and Webpack friendly!
Stars: ✭ 65 (-35%)
Mutual labels:  i18n, localization
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+676%)
Mutual labels:  i18n, localization
Goloc
A flexible tool for application localization using Google Sheets.
Stars: ✭ 42 (-58%)
Mutual labels:  i18n, localization
Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+351%)
Mutual labels:  i18n, localization
Laravel Lang
🌏 75 languages support for Laravel application.
Stars: ✭ 1,134 (+1034%)
Mutual labels:  i18n, localization
Redux React I18n
An i18n solution for React/Redux and React Native projects
Stars: ✭ 64 (-36%)
Mutual labels:  i18n, localization
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+544%)
Mutual labels:  i18n, localization
Angular I18next
angular v2.0+ integration with i18next v8.4+
Stars: ✭ 69 (-31%)
Mutual labels:  i18n, localization
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+522%)
Mutual labels:  i18n, localization
Next Translate
Next.js plugin + i18n API for Next.js 10 🌍 - Load page translations and use them in an easy way!
Stars: ✭ 867 (+767%)
Mutual labels:  i18n, localization
Fluent Rs
Rust implementation of Project Fluent
Stars: ✭ 503 (+403%)
Mutual labels:  i18n, localization
Texterify
The localization management system.
Stars: ✭ 37 (-63%)
Mutual labels:  i18n, localization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+307%)
Mutual labels:  i18n, localization
Juliazh.jl
Julia语言中文文摣
Stars: ✭ 425 (+325%)
Mutual labels:  i18n, localization
React Intl Hooks
React hooks for internationalization without the hassle βš›οΈπŸŒ
Stars: ✭ 64 (-36%)
Mutual labels:  i18n, localization
I18n plural
I18n module for grammatically correct plural inflections, and maybe even some extra features related to i18n.
Stars: ✭ 68 (-32%)
Mutual labels:  i18n, localization

LocaleChanger

An Android library to programmatically set the Locale of an app and persist the configuration.

Download

Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.franmontiel:LocaleChanger:1.1'
}

Usage

Basic usage

Initialize the library from your Application class with a list of your app supported Locales:

LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);

The first time that is invoked it will automatically set a Locale taking into account the system configuration. The first element of the supported Locale list will be used as default if no match with the system configured Locales is found.

You also need to call onConfigurationChange from the same named method in your Application class:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    LocaleChanger.onConfigurationChanged();
}

And create a new Locale configured Context for all your Activities overriding the AppCompatDelegate:

private LocaleChangerAppCompatDelegate localeChangerAppCompatDelegate;

@NonNull
@Override
public AppCompatDelegate getDelegate() {
    if (localeChangerAppCompatDelegate == null) {
            localeChangerAppCompatDelegate = new LocaleChangerAppCompatDelegate(super.getDelegate());
    }

    return localeChangerAppCompatDelegate;
}

To change the Locale just make the following call:

LocaleChanger.setLocale(newLocale);

Activity recreation

You need to recreate the Activities once the Locale is changed to reload your resources. You can do it by simply calling the replace method of the Activity.

Additionally there is a ActivityRecreationHelper class that is intended for assisting you with the recreation of the Activity.

It can be used to detect when the Locale has changed and reload automatically the Activity when resumed, for that you must call to the onResume and onDestroy methods of the helper class from the Activity methods.

In concrete terms:

  • On the Activity in which you change the language you need to recreate it calling ActivityRecreationHelper.recreate.
  • For having the rest of the Activities on the Back Stack recreated automatically when resumed, call ActivityRecreationHelper.onResume and ActivityRecreationHelper.onDestroy on all your Activities onResume and onDestroy methods respectively.

Advanced usage

The default behavior of the library can be changed providing a MatchingAlgorithm and a LocalePreference

  • The MatchingAlgorithm is used when the library is initialized and when the Locale is changed to find a match between your supported Locales and the system Locales. One of those matching Locales will be set by the library. There are two classes that implements this interface:

    • LanguageMatchingAlgorithm will match the first two Locales with the same language. This is the default algorithm used if no one is defined.
    • ClosestMatchingAlgorithm will match the two Locales with most attributes in common (language, country and variation).
  • The LocalePreference is used to select witch one of the two matching Locales will be set. The default behavior is to prefer a supported locales if no preference is provided.

Quick configuration (not recommended)

If you want to start really quick and it is not a problem for you to depend on inheritance for this library to work just follow those steps:

  • Make all your Activities inherit from LocaleChangerBaseActivity
  • Make your Application class inherit from LocaleChangerBaseApplication

Known issues

  • The ActionBar title is not affected by the Locale change if it is defined in the Manifest label attribute. A valid workaround is to set the title programmatically. More info on Issue #1.

License

Copyright (C) 2017 Francisco JosΓ© Montiel Navarro

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].