Replace bundled Strings dynamically, or provide new translations, for Android
Clone or download
Latest commit 3b7c5a7 May 1, 2018

Android Arsenal

Restring 1.0

An easy way to replace bundled Strings dynamically, or provide new translations in Android

1. Add dependency

implementation ''

2. Initialize

Initialize Restring in your Application class:


or if you want more configurations:

              new RestringConfig.Builder()
                  .stringsLoader(new SampleStringsLoader())

3. Inject into Context

if you have a BaseActivity you can add this there, otherwise you have to add it to all of your activities!

protected void attachBaseContext(Context newBase) {

4. Provide new Strings

There're two ways to provide new Strings. You can use either way or both.

First way: You can implement Restring.StringsLoader like this:

public class MyStringsLoader implements Restring.StringsLoader {

    //This will be called on background thread.
    public List<String> getLanguages() {
        //return your supported languages(e.g. "en", ...)

    //This will be called on background thread.
    public Map<String, String> getStrings(String language) {
        Map<String, String> map = new HashMap<>();
        // Load your strings here into a map of (key,value)s for this language!
        return map;

and initialize Restring like this:

              new RestringConfig.Builder()
                  .stringsLoader(new MyStringsLoader())

Second way: Load your Strings in any way / any time / any place and just call this:

// e.g. language="en" newStrings=map of (key-value)s
Restring.setStrings(language, newStrings);

5. Done!

Now all strings in your app will be overriden by new strings provided to Restring.


  1. Please note that Restring works with current locale, so if you change locale with

Restring will start using strings of the new locale.

  1. By default, Restring will use shared preferences to save all strings provided to. So if you set a StringsLoader or call .setString() to set the strings into Restring, the strings will be there on the next application launch. In case you don't want Restring saves strings into shared preferences, you can set it in initialization, like this:
              new RestringConfig.Builder()
                  .persist(false) //Set this to false to prevent saving into shared preferences.
  1. For displaying a string, Restring tries to find that in dynamic strings, and will use bundled version as fallback. In the other words, Only the new provided strings will be overriden and for the rest the bundled version will be used.


  1. Plurals are not supported yet.
  2. String arrays are not supported yet.



Copyright 2018 Hamid Gharehdaghi

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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.