title: How to use Calligraphy with multi-language support Oreo
body: <p>I'm developing an app that need to support multiple languages and if the language is RTL I have to apply a custom font. For the requirement I have created my Class that <code>extends Application</code>. Everything was perfect till I got <strong>Oreo</strong> version device (Before I have Marshmellow enabled device). In Oreo if we want to change the language we have to create a custom <code>ContextWrapper</code> class, here problem come in.  </p>
  
  <ol>
  <li>To use <code>Calligraphy</code> we need to <code>Override</code> the <code>attachBaseContext</code>
  method. And</li>
  <li>To change language we need to <code>Override</code> the <code>attachBaseContext</code> too</li>
  </ol>
  
  <p>I tried to call <code>super.attachBaseContext</code> in the <code>Overrided</code> method twice <strong>One</strong> for the Calligraphy and <strong>Other</strong> for the Language code like below.</p>
  
  <pre><code>@Override
  protected void attachBaseContext(Context newBase) {
  
      // create or get your new Locale object here.
      String lang = Preferences
              .getSharedPreferenceString(appContext, LANGUAGE_KEY, "ar");
  
      Context context = MyContextWrapper.wrap(newBase, lang);
      super.attachBaseContext(context);
      super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
  }
  </code></pre>
  
  <p>It give IllegalStateException as we can attach base context once.</p>
  
  <ul>
  <li>If I use <code>super.attachBaseContext(context);</code> the language change works But Calligraphy does not. </li>
  <li>If I use <code>super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));</code> Calligraphy works But Language change does not.</li>
  </ul>
  
  <p>In such case how can I make all working (Calligraphy + Multi-language). I have viewed many posts/tutorials but I'm stuck in this for three days now.</p>
  
  <p>Please help me complete this. Thanks</p>
  
  <p><strong>Edit:</strong> References </p>
  
  <ol>
  <li><a href="https://github.com/chrisjenx/Calligraphy/tree/master/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy" rel="noreferrer">CalligraphyContextWrapper.java</a></li>
  <li><a href="https://stackoverflow.com/questions/39705739/android-n-change-language-programmatically">ContextWrapper</a> Class Accepted answer in link.</li>
  </ol>
  
  <p>Looking for a solution to be able to use custom font with Calligraphy and Change Language Functionality. Alternatively provide a way so that I may be able to change Language and Apply Font to the whole app.</p>
  
  <p><strong>Note:</strong> The solution must be compatible with API 17 to the latest 27. I'm using <code>AppCompat</code>.</p>