• Stars
    star
    319
  • Rank 131,491 (Top 3 %)
  • Language
    Java
  • Created over 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

android multi language support (support android O+)

Android multi-language(support android O+) 中文

support third library multi-language( if there is a corresponding language resource file) ,in version 2.0.

version 2.0

Uses the Transform API to compile instrumentation to achieve attachBaseContext method auto insert of Activity and Service (code is in plugin)

  • support androidx
  • support kotlin
  • Not support Instant Run

Uses

Lastest version

modlue multi-language.plugin multi-languages
version Download Download

import

  • Import gradle plugin

    classpath 'com.github.jokar:multi-languages.plugin:<latest-version>'
    
  • apply plugin in app buidle.gradle file

    apply plugin: 'multi-languages'
    

    gradle configuration

    multiLanguages {
        //set plugin is enable( default)
        enable = true 
    }
    
  • import Library

    implementation 'com.github.jokar:multi-languages:<latest-version>'
    
  • application init

    public class MultiLanguagesApp extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        //Save the system language selection when entering the app for the first time.
        LocalManageUtil.saveSystemCurrentLanguage(base);
        super.attachBaseContext(MultiLanguage.setLocal(base));
    }
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        /**
        The user saves the system selection language when switching languages on the system settings page (in order to select when the system language is used, if it is not saved, it will not be available after switching languages)
        **/
        LocalManageUtil.saveSystemCurrentLanguage(getApplicationContext(), newConfig);
        MultiLanguage.onConfigurationChanged(getApplicationContext());
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        MultiLanguage.init(new LanguageLocalListener() {
            @Override
            public Locale getSetLanguageLocale(Context context) {
                //return your local settings
                return LocalManageUtil.getSetLanguageLocale(context);
            }
        });
        MultiLanguage.setApplicationLanguage(this);
    }
    }
    

    sample of save multi-language select LocalManageUtil

then is done

Other: locales list


sample image

sample-image