Giter Club home page Giter Club logo

localization's Introduction

Android Arsenal Maven Central Minimum SDK Version Workflow Status

Discontinued

Since Google announced Android 13 with per-app language preferences supports. This feature also backport to older Android version with AndroidX. So there's no reason to contribute this library anymore. For more stability, compatibility, and longer supports from Google team, please migrate to AndroidX. See Migrate to AndroidX guide.

Localization Library

Header image Android library for in-app language changes support in your application

Feature

  • In-app language changing
  • Default language when first launch
  • Work with string resource in XML and programmatically
  • RTL language support
  • Align on platform behavior

Demo

Try it at Google Play

Download

Since version 1.2.9 will move from JCenter to MavenCentral

// build.gradle (project)
allprojects {
    repositories {
        mavenCentral()
        /* ... */
    }
}

Gradle

implementation 'com.akexorcist:localization:1.2.11'

(Optional) You can exclude androidx.appcompat:appcompat, if your project does not use AppCompat.

implementation ('com.akexorcist:localization:1.2.11') {
    exclude group: 'androidx.core', module: 'core'
}

Usage

Custom application class which extends from LocalizationApplication is require.

class MainApplication: LocalizationApplication() {
    /* ... */
    override fun getDefaultLanguage(context: Context) = Locale.ENGLISH
}

Either not, using LocalizationApplicationDelegate with additional code as below

class MainApplication: Application() {
    private val localizationDelegate = LocalizationApplicationDelegate()
    
    override fun attachBaseContext(base: Context) {
        localizationDelegate.setDefaultLanguage(base, Locale.ENGLISH)
        super.attachBaseContext(localizationDelegate.attachBaseContext(base))
    }
    
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        localizationDelegate.onConfigurationChanged(this)
    }
    
    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }
    
    override fun getResources(): Resources {
        return localizationDelegate.getResources(baseContext, super.getResources())
    }
}

For the activities, extends from LocalizationActivity.

class MainActivity: LocalizationActivity() {
    /* ... */
}

Or using LocalizationActivityDelegate with additional code

open class CustomActivity : Activity(), OnLocaleChangedListener {
    private val localizationDelegate = LocalizationActivityDelegate(this)

    public override fun onCreate(savedInstanceState: Bundle?) {
        localizationDelegate.addOnLocaleChangedListener(this)
        localizationDelegate.onCreate()
        super.onCreate(savedInstanceState)
    }

    public override fun onResume() {
        super.onResume()
        localizationDelegate.onResume(this)
    }

    override fun attachBaseContext(newBase: Context) {
        applyOverrideConfiguration(localizationDelegate.updateConfigurationLocale(newBase))
        super.attachBaseContext(newBase)
    }

    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }

    override fun getResources(): Resources {
        return localizationDelegate.getResources(super.getResources())
    }

    fun setLanguage(language: String?) {
        localizationDelegate.setLanguage(this, language!!)
    }

    fun setLanguage(locale: Locale?) {
        localizationDelegate.setLanguage(this, locale!!)
    }

    val currentLanguage: Locale
        get() = localizationDelegate.getLanguage(this)

    // Just override method locale change event
    override fun onBeforeLocaleChanged() {}
    override fun onAfterLocaleChanged() {}
}

Then prepare your multilingual content in string resource.

Multilingual Content

Public method on LocalizationActivity

It have only 4 public methods.

fun setLanguage(language: String)
fun setLanguage(language: String, country: Strinng)
fun setLanguage(locale: Locale)
fun getCurrentLanguage(): String

setLanguage Set the language that you need to change.

For example

setLanguage("th")                             // Language : Thailand
setLanguage("th", "TH")                       // Language : Thailand, Country : Thai
setLanguage(Locale("th", "TH"))               // Language : Thailand, Country : Thai
setLanguage("en")                             // Language : English
setLanguage("en", "GB")                       // Language : English,  Country : Great Britain
setLanguage("en", "US")                       // Language : English,  Country : United States
setLanguage(Locale("en", "US"))               // Language : English,  Country : United States
setLanguage(Locale.KOREA)                     // Language : Korean,   Country : Korea
setLanguage(Locale.KOREAN)                    // Language : Korean
setLanguage(Locale.CANADA_FRENCH)             // Language : French,   Country : Canada

getLanguage Get current language as string locale.

And 2 optional override methods.

fun onBeforeLocaleChanged()
fun onAfterLocaleChanged()

This override method will be useful when you need to know when language has changed.

Back Stack 1

When setLanguage was called. Current active activity will be recreated to apply the new language.

Back Stack 2

Previous activities in back stack does not change to new language immediately. Until it back to active activity again.

Back Stack 3

Back Stack 4

Back Stack 5

Action Bar or Toolbar's title

You have to call setTitle(resId) or getActionBar().setTitle(resId) in onCreate(onSavedInstanceState: Bundle) to apply the new language.

class MainActivity: LocalizationActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        /* ... */
        setTitle(R.string.main_activity_title)
    }
}

Handle state changes

Activity will be recreate when language has changed as common behavior for configuration changes in Android. Any Activities or Fragments which hold the data should handle the state changes.

Change the language in Fragment

Language in fragment will depends on activity. So no need for additional code in Fragment.

Service

For normally usage, just extends from LocalizationService

class SimpleService : LocalizationService() {
    /* ... */
}

Or using LocalizationServiceDelegate with additional code

abstract class CustomService : Service() {
    private val localizationDelegate: LocalizationServiceDelegate by lazy {
        LocalizationServiceDelegate(this)
    }

    override fun getBaseContext(): Context {
        return localizationDelegate.getBaseContext(super.getBaseContext())
    }

    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }

    override fun getResources(): Resources {
        return localizationDelegate.getResources(super.getResources())
    }
}

BroadcastReceiver

BroadcastReceiver is abstract class. So we cannot create LocalizationBroadcastReceiver fot you.

In this case, you need to convert the context in onReceive(context: Context, intent: Intent) to localized context with Context.toLocalizedContext() before using.

class SimpleBroadcastReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val localizedContext = context.toLocalizedContext()
        /* ... */
    }
}

Language resources optimization in Android App Bundle

Change the language by library can cause a crash to your app when you publishing your app with Android App Bundle with language resources optimization enabled.

To fix this, Using the Additional Languages API in Play Core library to download the additional language before.

For more information about Additional Language API : https://android-developers.googleblog.com/2019/03/the-latest-android-app-bundle-updates.html

If you don't want to implement this feature in your code, just ignore the language resources optimization by adding the Android App Bundle configuration in your app's build.gradle

android {
    /* ... */ 
    bundle { 
        language { 
            enableSplit = false 
        } 
    } 
}

ProGuard

Normally, there's no require the ProGuard rules for this library.

But if you want to exclude this library from obfuscate and shrinking. You also can add these code to proguard-rules.pro

-keep class com.akexorcist.localizationactivity.** { *; }
-dontwarn com.akexorcist.localizationactivity.**

Change Log

See CHANGELOG.md

Licence

Copyright 2021 Akexorcist

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or 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.

localization's People

Contributors

akexorcist avatar aleksandermielczarek avatar alouanemed avatar askarsyzdykov avatar first087 avatar hantrungkien avatar iammitsuo avatar iamriajul avatar ionull avatar lloydblv avatar mr-nent avatar sgallego avatar tiborviktorpasztor avatar vhiribarren avatar yunusemrecetin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

localization's Issues

App language is not change when change device language

I have used three languages in my app and those are French, Dutch and English. When I change language from app at that time it is working fine but when I change device language then app language is not change. For eg. If my device language is french then app should be in french.

Failed to integrate latest version

My current compile version is 25 and build tool version is 25.0.2. while integrating latest library version(com.akexorcist:localizationactivity:1.2.2), I am getting below error.

Error:Could not find com.android.support:appcompat-v7:26.1.0.
Required by:
project :app
project :app > com.android.support:design:25.3.1
project :app > project :cropper

Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager

Slow activity transition

Does anyone found the transition between activity is a bit slower after extend Activity by LocalizationActivity?

Release Android X version

last release is Oct 31, 2017 . after that updated the master branch with androidx support code. can you make a release for androidx ?

Crash on Android 7.1.1 - SDK = 25

Only happens on: Android Emulator Android 7.1.1 - SDK = 25

implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha06'

Simple layout: main_activity.xml:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:padding="10dp">

        <WebView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/input_current_password_layout"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/input_current_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="@android:color/black"
                android:textSize="15sp" />
        </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>

Log crash:

 Process: com.akexorcist.localizationapp, PID: 31750
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.akexorcist.localizationapp/com.akexorcist.localizationapp.MainActivity}: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class com.google.android.material.textfield.TextInputLayout
...
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
        at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
        at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
        at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)

[Urgent] Not support `Locale.KOREAN`

Lib Version: com.akexorcist:localization:1.2.4
Android Version: android 9

  • Can set other languages (Locale.TRADITIONAL_CHINESE, Locale.US, Locale.SIMPLIFIED_CHINESE).
  • But cannot display korean language for Locale.KOREAN: I have added values-ko folder and strings.xml, and locale is correctly set to ko in coding.
  • Also tested Locale.KOREA and values-ko-rKR, still not work.

Any idea on it ?
Thanks for help !

Using with Fragment

Thank you for library. I have a problem. I'm trying to use with fragment. I implemented with OnLocaleChangedListener but i got an error like below.

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference

setDefaultLanguage does not work properly

setDefaultLanguage added on top of super.onCreate() but it does not change to the language i wanted at first time launch of the app ( it is still english), until i kill it and relaunch it again.

Support Api version 15

First, thank you for your work. I tested this library and it works great. But the library minSdkVersion is set to 16. I am working on an application that has millions of user supporting minSdkVersion 15. I tried to override this in manifest but as I expected, I got runtime error in an emulator on Api version 15.

NoSuchMethodError: android.content.res.Configuration.setLocale

This happens in your LocalizationContext Class. Configuration.setLocale() is added in Api 17 and previously this had been done with Configuration.locale = .... If this is the only reason to set minSdk to 17, could you consider supporting Api version 15?

Also a question, if setLocale is defined in Api 17, how your library supports Api 16?

Compatability with Android Hilt

My application started crashing after I started using Hilt for dependency injection every time I change the language. I think the problem is coming when the application tries to recreate the activity.
I dont know if this is a problem on my side or maybe the library doesn't have dependency injection support.

Not working for new AndroidX appcompat versions

Recently I upgraded my AndroidX dependency versions (from 1.1.0 to 1.2.0-beta01) and some users started reporting that the app's locale changing feature stopped working.
I was using the 1.2.2 version at the time now I changed upgraded it 1.2.4 but it didn't fix it.

It was working fine on my Pixel 3 XL and Android emulator (different Android versions) but I've seen at least 2 complaints in reviews.
So after some digging, I was finally able to reproduce it by using appetize.io emulator. I reverted AndroidX version back to 1.1.0 and it worked properly as before (diff).

When it's not working, it uses the system language. It changes only when the system language changes.

Any ideas on what might be wrong?

"nds" doesnt work on API Level 18+19

hi there,

thanks for this wonderful lib.

Right now I just want to name an issue, which I was able to solve myself.

I am developing an German app, so our default language is German, the locale is DE, the folder is values-de.

I want to use a German dialect, and therefor I need your lib.

The problem is that I need a language identifier to be used.

I do NOT want to use English (EN) or French (FR) as the app may be translated into English or French in the future.

So I used "nds". Everything works fine except for API level 18 and 19.

So I switched back to Tai (TH).

The only price I pay is that any German which has its device set to Thai language gets our German dialect.

Cheers,
DaRolla

ltr and rtl

in version 1.0.9 when change language to rtl language all activities swiped automatically but in recent releases versions until change language to rtl language all activity keep ltr design why last version dont swap all activity like version 1.0.9 , thanks in advanced

Can't integrate with the Latest Version

I keep getting the following error when trying to use the latest version

14:07:57.268 [INFO] [com.android.build.gradle.internal.ApplicationTaskManager] processing com/akexorcist/localizationactivity/BlankDummyActivity.class...
14:07:57.271 [ERROR] [org.gradle.api.Project] Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
UNEXPECTED TOP-LEVEL EXCEPTION:

I currently have the following in my Grade file:

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

Selected language is ignored after app restart on AppCompat 1.3.0-alpha01

Bug: App starts with default / phone language A, I change the language to B, force close the app from recent apps, open the app again, app's language is back to A. Language is retained if the app is minimized and restored.

I had this issue for a while in my app, but couldn't figure out why. Today I noticed the same behavior on my other app while I was upgrading dependencies. Confirmed the bug in the sample app by changing AppCompat version to 1.3.0-alpha01. The bug is not present in both 1.1.0 and 1.2.0-alpha01.

Wrong behaviour in Oreo

Hi! Thank you for your job! Awesome work!
I've tried the same approach for my app and I had a problem with createConfigurationContext. It doesn't keep backstack. My activities just ignores all intent keys. I've tried your demo application for play store. It also has a problem with backstack.
I wonder how to fix that. In case I find some solution, I'll let you know.

Unsupported language

Suppose I choose the language which is unavailable in the system, I have defined the strings.xml. How will it work?

App launch in Gujarati language instead of English in some devices(Moto G6,Mi A1).

I have used three languages in my app and those are English, Hindi and Gujarati. In some devices(Moto G6 Android os 8.0 & Mi A1 os 9.0) app launched in Gujarati language instead of English. I want to launch app in English after installation.

Current device language is English.
This function return Gujarati language.
getCurrentLanguage().getLanguage();

App Bundle Issue

In case if you are using app bundle to publish your application on Play Store, then locale change won't work for certain languages. App Bundle splits the resources for languages as well based on device requirements. I was facing this issue and later solved it by adding the following to app's build.gradle file.

android { bundle { language { enableSplit = false } } }

Please mention this for people who are using your library so they do not face the problem.

Good work with the library.

Dark Mode Problem With MODE_NIGHT_FOLLOW_SYSTEM Selected

There is an error on the library where if user want to use Dark Mode with flag MODE_NIGHT_FOLLOW_SYSTEM.

MODE_NIGHT_NO, MODE_NIGHT_YES or MODE_NIGHT_AUTO_BATTERY works fine and only problem occurs due to the selection of MODE_NIGHT_FOLLOW_SYSTEM.

Once system dark mode is changed, the application did not restarted with proper dark mode theme in MODE_NIGHT_FOLLOW_SYSTEM selected.

The problem caused due to the Application class method overriding.

Causes Error:

    @Override
    protected void attachBaseContext(Context base) {
        deviceLanguage = Util.getDeviceLanguage();
        super.attachBaseContext(localizationDelegate.attachBaseContext(base));
    }

Not Causes Error, but Language changing doesn't work in this way:

    @Override
    protected void attachBaseContext(Context base) {
        localizationDelegate.setDefaultLanguage(base, MainApp.getDeviceLanguage());
        localizationDelegate.attachBaseContext(base);
        super.attachBaseContext(base);
    }

Version: 1.2.4

ListPreference + v1.2.4 bug

Hello, I found a bug using v1.2.4 wih Preference dialog.
After changing language from selecting it from ListPreference dialog activity is recreated but language of the UI stays previous.
As I understand the reason is that in this case method Activity.getResources() is being called before Activity.attachBaseContext().
So LocalizationActivityDelegate.getResources() method change language in Resources object, then in subsequent attachBaseContext() method call next condition is not met:
if (!baseLocale.toString().equals(currentLocale.toString(), ignoreCase = true)) {

100% reproducing on Android 10 Pixel 2
v1.2.3 works fine.

To reproduce add next code in sample application:
SettingsActivity.java

package com.akexorcist.localizationapp.settingsactivity;

import android.os.Bundle;
import android.preference.PreferenceFragment;

import com.akexorcist.localizationactivity.ui.LocalizationActivity;
import com.akexorcist.localizationapp.R;

public class SettingsActivity extends LocalizationActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_activity);
        getFragmentManager().beginTransaction().replace(R.id.main_content, new GeneralPreferenceFragment()).commit();
    }

    public static class GeneralPreferenceFragment extends PreferenceFragment {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.settings);
            setHasOptionsMenu(false);
            findPreference("language").setOnPreferenceChangeListener((preference, newValue) -> {
                String lang = newValue.toString();
                ((LocalizationActivity)getActivity()).setLanguage(lang);
                return true;
            });
        }
    }
}

settings_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".settingsactivity.SettingsActivity">
    <FrameLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="?attr/actionBarSize" />
</FrameLayout>

settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="@string/hello_world">
        <ListPreference
            android:defaultValue="en"
            android:entries="@array/pref_language_list_titles"
            android:entryValues="@array/pref_language_list_values"
            android:key="language"
            android:negativeButtonText="@null"
            android:positiveButtonText="@null"
            android:title="language" />
    </PreferenceCategory>
</PreferenceScreen>

strings_settings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="pref_language_list_titles" translatable="false">
        <item>America</item>
        <item>China</item>
        <item>Italy</item>
        <item>Japan</item>
        <item>Korea</item>
        <item>Portugal</item>
        <item>Thai</item>
    </string-array>
    <string-array name="pref_language_list_values" translatable="false">
        <item>en</item>
        <item>zh</item>
        <item>it</item>
        <item>ja</item>
        <item>ko</item>
        <item>pt</item>
        <item>th</item>
    </string-array>
</resources>

Not work for Toolbar title

Hi, tnx for job!

Toolbar title not changed after new language setup. It's changed only if put code
setTitle(R.string.title);

Any variants?

view ยังใช้ค่า resource จากภาษาในตอนที่เปิดแอป

phone : Huawei P10 plus (android 9), Huawei nova5t (android 10)
หลังจากเปลี่ยนภาษาแล้ว view ยังใช้ค่า resource จากภาษาในตอนที่เปิดแอปครับ
ต้อง kill แอปพลิเคชันแล้วเข้าใหม่จึงจะได้ค่าจาก resource ของภาษาที่เลือก
ผมได้ลองเช็คจาก getCurrentLanguage แล้ว ได้ return ภาษาที่ถูกต้องนะครับ และอาการนี้ไม่ได้เป็นกับโทรศัพท์ทุกเครื่องซะด้วย

Correct in Read Me

change
override fun getApplicationContext(){ return localizationDelegate.getApplicationContext(super.getApplicationContext()) }
to
override fun getApplicationContext(): Context { return localizationDelegate.getApplicationContext(super.getApplicationContext()) }

Pull logic from LocalizationActivity...

...into LocalizationDelegate which will hold all the state. LocalizationActivity would then delegate all the work to this object.

See how AppCompatActivity and AppCompatDelegate works.

The goal is to be able to leverage this library while avoiding the use of AppCompatActivity or the appcompat-v7 dependency altogether.

Support for API 16

Is it possible that this library can support API 16 (4.2.2) which is about 2.2%?

Error เมื่อใช้กับ Data Binding บน DialogFragment

ใช้กับ Android Version 7.1

ในโค๊ด localizationDelegate.getResources หากไม่มีการ new Resource แต่ส่ง Resource ตัวเก่ากลับไปแทน จะไม่ error ครับ แต่ ภาษาเพี้ยนครับ ไทยบ้างอังกฤษบ้างในหน้าเดียวกัน

https://www.facebook.com/groups/thaidroiddev/2743817052365429/?comment_id=2743827012364433&reply_comment_id=2743847089029092&notif_id=1581070274019551&notif_t=group_comment_mention

currency value multiplies by 100 times

When I am changing the language from English to Cambodian Khmer language,the currency value increases by 100 times. When Send 1USD then showing 100USD in post method.
screen shot 2018-07-31 at 5 02 54 pm
img_4254

Library Not Working Using Kotlin Programming Language

I don't understand, I try using Java and it worked well. But when I try using Kotlin nothing happened

`

class MainActivity : LocalizationActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    lblTitleMain.setOnClickListener(View.OnClickListener {
        setLanguage("in")
    })
}

}`

Am I do something wrong? I just want to change TextView when it clicked

Locale Code with Country

Hi. Great library.

For locale code with country, I found that it is not success to change the language if the locale code is embedded with country. I tested by modifying your sample app.

...
} else if (id == R.id.btn_china) {
setLanguage("zh_TW");
....

And then I rename the folder under res folder from "values-zh" to "values-zh-rTW"

Run the app. And the test result is the language wont change.

ClassCastException: LocalizationContext cannot be cast to android.app.ContextImpl on API 16

Hi! On android API 16 I get such exception (and crash):

java.lang.RuntimeException: Unable to start receiver com.xxx.InactivityHandler: java.lang.ClassCastException: com.akexorcist.localizationactivity.core.LocalizationContext cannot be cast to android.app.ContextImpl
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236)
        at android.app.ActivityThread.access$1500(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: com.akexorcist.localizationactivity.core.LocalizationContext cannot be cast to android.app.ContextImpl
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2226)
        at android.app.ActivityThread.access$1500(ActivityThread.java:130) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:4745) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:511) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
        at dalvik.system.NativeStart.main(Native Method)

InactivityHandler is defined in AndroidManifest as

BlankDummyActivity don't find nim.animation_localization_activity_transition_out

ava.lang.NoClassDefFoundError: Failed resolution of: Lcom/akexorcist/localizationactivity/R$anim;
at com.akexorcist.localizationactivity.ui.BlankDummyActivity.onCreate(BlankDummyActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.akexorcist.localizationactivity.R$anim" on path: DexPathList[[zip file "/data/app/com.my.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.myapp-2/lib/arm, /data/app/com.my.myapp-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]

Before this, my app was working fine, but after some changes on my code, my app began to crash when i'm trying to change App's language

Doesn't Work when Using with Activity of Nested Fragments

I have 'MainActivity' which have Fragment A within it , and Fragment A have Fragment B within it .
like this:
-MainActivity
--Fragment A (replaced in frame layout with ID: R.id.frame1)
--Fragment B (replaced within fragment A xml frame layout with iD: R.id.frame2)

Now When i change language from Fragment B , it gives exception that no view found with id R.id.frame1 in Fragment B ?

How to fix this issue ?

Unsupported RTL in API 23

I've used it in API 29 and it work very well, but when i use it with API 23 to change application language into Arabic it change the language but not the display direction
I guess it's all about this

    @Suppress("DEPRECATION")
    fun getResources(resources: Resources): Resources {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val locale = LanguageSetting.getLanguage(activity)
            val config = resources.configuration
            config.setLocale(locale)
            val localeList = LocaleList(locale)
            LocaleList.setDefault(localeList)
            config.setLocales(localeList)
            resources
        } else {
            val config = resources.configuration
            config.locale = LanguageSetting.getLanguage(activity)
            val metrics = resources.displayMetrics
            Resources(activity.assets, metrics, config)
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.