@@ -6,11 +6,13 @@ Android-LocalizationActivity
66
77![ Header image] ( https://raw.githubusercontent.com/akexorcist/Android-LocalizationActivity/master/image/01-header.jpg )
88
9- Keep calm and stay easy with multiple language supported in your android application.
9+ You can now chill out on supporting multiple languages on your android application.
1010
11- It's basic for android application to be supported multiple languages. Yeah! It's very easy because android has String Resource. Developer just had to prepare the text for different languages then android system will use itself.
12- But frequently problem is "On-time Language Changing". Because the String Resource was designed to be depending on current device language. but if we want to change the language by click some button. It will be difficult to handle it.
13- This problem will solved because I have created a new library to handle application language. It called "Localization Activity" library.
11+ It is normal for your Android application to support multiple languages. And it is very easy because you can do them by putting each language in different String Resource folders. That is the only thing that developers has to do. The rest will be handled by Android system.
12+
13+
14+ Its easiness comes with a limitation. The language of your application follows your Android System language. Life is hard when you change your application language on-the-fly. E.g., you have a language switcher button in your application. If you have this problem, you come to the right place. I have created a library to handle language changing at application level.
15+ It is called "Localization Activity".
1416
1517
1618Demo
@@ -27,19 +29,28 @@ Maven
2729<dependency>
2830 <groupId>com.akexorcist</groupId>
2931 <artifactId>localizationactivity</artifactId>
30- <version>1.2.0 </version>
32+ <version>1.2.1 </version>
3133</dependency>
3234```
3335
3436Gradle
3537```
36- compile 'com.akexorcist:localizationactivity:1.2.0 '
38+ compile 'com.akexorcist:localizationactivity:1.2.1 '
3739```
3840
3941(Optional) You can exclude ` com.android.support:appcompat-v7 ` , if your project doens't use AppCompat v7 and declare this library with delegate way.
4042
41- Update 1.2.0
43+
44+ Update
4245===========================
46+ 1.2.1
47+ ---------------------------
48+ • Support string resource from getApplicationContext()
49+ • Add LocalizationApplicationDelegate. So you need to custom application class in your app
50+ • LocalizationDelegate was deprecated, replace by LocalizationActivityDelegate
51+
52+ 1.2.0
53+ ---------------------------
4354* [ bug] Bug fixed : Android 7.0 language [ #14 ] ( https://github.com/akexorcist/Android-LocalizationActivity/issues/14 )
4455* [ bug] Language and country support [ #5 ] ( https://github.com/akexorcist/Android-LocalizationActivity/issues/5 )
4556* [ bug] RTL on orientation changes [ #15 ] ( https://github.com/akexorcist/Android-LocalizationActivity/issues/15 ) [ #9 ] ( https://github.com/akexorcist/Android-LocalizationActivity/issues/9 )
@@ -50,13 +61,13 @@ Feature
5061===========================
5162* On-time language changing supported.
5263* Auto setup when activity was created.
53- * Current language config will saved to SharedPreference automatically .
64+ * Current language config will save to ` SharedPreference ` automagically .
5465* Very easy to use it.
5566
5667
5768LocalizationActivity extends from AppCompatActivity
5869===========================
59- LocalizationActivity is extend from AppCompatActivity class. So you still can use all method from AppCompatActivity class.
70+ LocalizationActivity is extended from AppCompatActivity class. So you still can use all methods from AppCompatActivity class.
6071
6172![ Header image] ( https://raw.githubusercontent.com/akexorcist/Android-LocalizationActivity/master/image/03-extend.jpg )
6273
@@ -67,19 +78,17 @@ Don't like AppCompat v7? Try delegate way
6778``` java
6879import android.app.Activity ;
6980import android.content.Context ;
81+ import android.content.res.Resources ;
7082import android.os.Bundle ;
7183
72- import com.akexorcist.localizationactivity.LocalizationDelegate ;
73- import com.akexorcist.localizationactivity.OnLocaleChangedListener ;
84+ import com.akexorcist.localizationactivity.core.LocalizationActivityDelegate ;
85+ import com.akexorcist.localizationactivity.core. OnLocaleChangedListener ;
7486
7587import java.util.Locale ;
7688
77- /**
78- * Created by Akexorcist on 6/23/16 AD.
79- */
8089public abstract class CustomActivity extends Activity implements OnLocaleChangedListener {
8190
82- private LocalizationDelegate localizationDelegate = new LocalizationDelegate (this );
91+ private LocalizationActivityDelegate localizationDelegate = new LocalizationActivityDelegate (this );
8392
8493 @Override
8594 public void onCreate (Bundle savedInstanceState ) {
@@ -91,42 +100,45 @@ public abstract class CustomActivity extends Activity implements OnLocaleChanged
91100 @Override
92101 public void onResume () {
93102 super . onResume();
94- localizationDelegate. onResume();
103+ localizationDelegate. onResume(this );
95104 }
96105
97106 @Override
98107 protected void attachBaseContext (Context newBase ) {
99108 super . attachBaseContext(localizationDelegate. attachBaseContext(newBase));
100109 }
101110
102- public final void setLanguage (String language ) {
103- localizationDelegate. setLanguage(language);
111+ @Override
112+ public Context getApplicationContext () {
113+ return localizationDelegate. getApplicationContext(super . getApplicationContext());
114+ }
115+
116+ @Override
117+ public Resources getResources () {
118+ return localizationDelegate. getResources(super . getResources());
104119 }
105120
106- public final void setLanguage (String language , String country ) {
107- localizationDelegate. setLanguage(language, country );
121+ public final void setLanguage (String language ) {
122+ localizationDelegate. setLanguage(this , language );
108123 }
109124
110125 public final void setLanguage (Locale locale ) {
111- localizationDelegate. setLanguage(locale);
126+ localizationDelegate. setLanguage(this , locale);
112127 }
113128
114129 public final void setDefaultLanguage (String language ) {
115130 localizationDelegate. setDefaultLanguage(language);
116131 }
117132
118- public final void setDefaultLanguage (String language , String country ) {
119- localizationDelegate. setDefaultLanguage(language, country);
120- }
121-
122133 public final void setDefaultLanguage (Locale locale ) {
123134 localizationDelegate. setDefaultLanguage(locale);
124135 }
125136
126- public final Locale getLanguage () {
127- return localizationDelegate. getLanguage();
137+ public final Locale getCurrentLanguage () {
138+ return localizationDelegate. getLanguage(this );
128139 }
129140
141+ // Just override method locale change event
130142 @Override
131143 public void onBeforeLocaleChanged () {
132144 }
@@ -140,13 +152,42 @@ public abstract class CustomActivity extends Activity implements OnLocaleChanged
140152
141153Usage
142154===========================
143- This is an example.
155+ You need to use custom application class in your project that implemented the LocalizationApplicationDelegate class.
156+ ``` java
157+ import android.app.Application ;
158+ import android.content.Context ;
159+ import android.content.res.Configuration ;
160+
161+ import com.akexorcist.localizationactivity.core.LocalizationApplicationDelegate ;
162+
163+ public class MainApplication extends Application {
164+ LocalizationApplicationDelegate localizationDelegate = new LocalizationApplicationDelegate (this );
165+
166+ @Override
167+ protected void attachBaseContext (Context base ) {
168+ super . attachBaseContext(localizationDelegate. attachBaseContext(base));
169+ }
170+
171+ @Override
172+ public void onConfigurationChanged (Configuration newConfig ) {
173+ super . onConfigurationChanged(newConfig);
174+ localizationDelegate. onConfigurationChanged(this );
175+ }
176+
177+ @Override
178+ public Context getApplicationContext () {
179+ return localizationDelegate. getApplicationContext(super . getApplicationContext());
180+ }
181+ }
182+ ```
183+
184+ In your activity, just extends from LocalizationActivity class or your custom class.
144185
145186``` java
146187import android.os.Bundle ;
147188import android.view.View ;
148189
149- import com.akexorcist.localizationactivity.LocalizationActivity ;
190+ import com.akexorcist.localizationactivity.ui. LocalizationActivity ;
150191
151192public class MainActivity extends LocalizationActivity implements View .OnClickListener {
152193
@@ -171,15 +212,15 @@ public class MainActivity extends LocalizationActivity implements View.OnClickLi
171212}
172213```
173214
174- In the example above, when user click on a button. It will change to English or Thai language. That's It! Localization Activity Library example.
215+ In the example above, when a user clicks on a button. It will change to English or Thai language. That's it!
175216
176- ** It's very easy, right?** You barely have to do anything.
217+ ** It's very easy, right?** You barely do anything.
177218
178219Then just build up some String Resource for English and Thai language.
179220
180221![ Header image] ( https://raw.githubusercontent.com/akexorcist/Android-LocalizationActivity/master/image/02-string_resource.jpg )
181222
182- Complete! Your application support with multiple language now.
223+ Complete! Your application now supports multiple languages now.
183224
184225
185226Public method on LocalizationActivity
@@ -197,7 +238,7 @@ void setDefaultLanguage(String language, String country)
197238void setDefaultLanguage(Locale locale)
198239```
199240
200- ** setLanguage** Set the language that you needs to change. The string value given will be use for setup Locale class later.
241+ ** setLanguage** Set the language that you need to change. The string value given will be use for setup Locale class later.
201242
202243Example
203244
@@ -258,13 +299,13 @@ But no problem for this library when application getback to previous activity. I
258299Action Bar or Toolbar's title
259300---------------------------
260301You have to call
261- ```
302+ ``` java
262303setTitle(String title)
263304// or
264305getActionBar(). setTitle(String title)
265306 ```
266307 in on activity create (onCreate) every time
267- ```
308+ ``` java
268309 public class MainActivity extends Localization {
269310 @Override
270311 public void onCreate (Bundle onSavedInstanceState ) {
0 commit comments