Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MomenZaq/LanguageHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

LanguageHelper

Change your application language for any language and support LTR and RTL

How to use this class?

This class is built with dagger2 and used as a Singleton class.

1- copy the class to your project

2- in Applicatoin class add

   @Override
    protected void attachBaseContext(Context base) {

// dagger not work here, so I have to create my own
   // dagger not work here, so I have to create my own
     base = new LanguageHelper(base, sharedPreferencesHelper).wrapContext(base);
        super.attachBaseContext(base);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // setup the languages
        languageHelper.overrideLocal(this);
    }

3- in each Activity

   @Override
    protected void attachBaseContext(Context base) {

// dagger not work here, so I have to create my own
        base = new LanguageHelper(base,sharedPreferencesHelper).wrapContext(base);
        super.attachBaseContext(base);
    }

in onCreate method

after super.onCreate

 languageHelper.wrapContext(this);

4- in each activity and dialog

before super.onCreate

 languageHelper.setDirection(getWindow().getDecorView());

5- to change the app language

// new language = "en" or "ar"
languageHelper.setNewLanguage(newLanguage,launcherActivity)

That's it!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages