All Projects → hamidness → Restring

hamidness / Restring

Replace bundled Strings dynamically, or provide new translations, for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Restring

Springview
🔥 A custom view pull to refresh,support ScrollView,ListView,RecyclerView,WebView and all another views, easy to use
Stars: ✭ 1,936 (+792.17%)
Mutual labels:  android-ui
Wiggle
An Android helper library for delayed scrolling
Stars: ✭ 179 (-17.51%)
Mutual labels:  android-ui
Droidmotion
🏂 Implementation of a simple android motion
Stars: ✭ 200 (-7.83%)
Mutual labels:  android-ui
Krumbsview
🍞 The ultimate breadcrumbs view for Android!
Stars: ✭ 170 (-21.66%)
Mutual labels:  android-ui
Slidingintroscreen
An Android library designed to simplify the creation of introduction screens.
Stars: ✭ 174 (-19.82%)
Mutual labels:  android-ui
Textsurface
A little animation framework which could help you to show message in a nice looking way
Stars: ✭ 2,264 (+943.32%)
Mutual labels:  android-ui
Android About Page
Create an awesome About Page for your Android App in 2 minutes
Stars: ✭ 1,980 (+812.44%)
Mutual labels:  android-ui
Jackknife
⚔️ 金轮法王,哦不,是轮子大师带你玩转Android,是时候尝试下MVVM了。这是一个Android应用开发全家桶库,支持Kotlin+MVVM+Dagger2+Retrofit架构。
Stars: ✭ 215 (-0.92%)
Mutual labels:  android-ui
Jetquotes
🔖 A Quotes Application built to Demonstrate the Jetpack Compose UI
Stars: ✭ 179 (-17.51%)
Mutual labels:  android-ui
Tristatetogglebutton
Customizable tri-state toggle button (with three states, three state toggle) for Android
Stars: ✭ 198 (-8.76%)
Mutual labels:  android-ui
Android library
android_library
Stars: ✭ 170 (-21.66%)
Mutual labels:  android-ui
Hollowkit
自己常用的一些工具的合集
Stars: ✭ 173 (-20.28%)
Mutual labels:  android-ui
Qmui android
提高 Android UI 开发效率的 UI 库
Stars: ✭ 13,341 (+6047.93%)
Mutual labels:  android-ui
Composecookbook
A Collection on all Jetpack compose UI elements, Layouts, Widgets and Demo screens to see it's potential
Stars: ✭ 3,516 (+1520.28%)
Mutual labels:  android-ui
Slideshowtoolbar
Slideshow Imageview for Android
Stars: ✭ 204 (-5.99%)
Mutual labels:  android-ui
Awesomedialog
A Beautiful Dialog Library for Kotlin Android
Stars: ✭ 163 (-24.88%)
Mutual labels:  android-ui
Konfetti
Celebrate more with this lightweight confetti particle system 🎊
Stars: ✭ 2,278 (+949.77%)
Mutual labels:  android-ui
Blitz
Android Library: Set self-updating string with relative time in TextView (e.g. 5 minutes ago)
Stars: ✭ 217 (+0%)
Mutual labels:  android-ui
Folivora
An android library that supports set various drawables to view directly in your layout.xml
Stars: ✭ 207 (-4.61%)
Mutual labels:  android-ui
Elegantdialog
A beautiful, customizable and interactive dialog for Android written in Kotlin/Java 😍
Stars: ✭ 189 (-12.9%)
Mutual labels:  android-ui

Android Arsenal

Please use this version instead, if you're going to use thie library.

Restring 1.0

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

1. Add dependency

implementation 'com.ice.restring:restring:1.0.0'

2. Initialize

Initialize Restring in your Application class:

Restring.init(context);

or if you want more configurations:

Restring.init(context,
              new RestringConfig.Builder()
                  .persist(true)
                  .stringsLoader(new SampleStringsLoader())
                  .build()
        );

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!

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(Restring.wrapContext(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.
    @Override
    public List<String> getLanguages() {
        //return your supported languages(e.g. "en", ...)
    }

    //This will be called on background thread.
    @Override
    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:

Restring.init(context,
              new RestringConfig.Builder()
                  .persist(true)
                  .stringsLoader(new MyStringsLoader())
                  .build()
        );

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.

Notes:

  1. Please note that Restring works with current locale, so if you change locale with
Locale.setDefault(newLocale);

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:
Restring.init(context,
              new RestringConfig.Builder()
                  .persist(false) //Set this to false to prevent saving into shared preferences.
                  .build()
        );
  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.

Limitations

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

Docs

License

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

   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].