Skip to content

Commit 09331a2

Browse files
committed
add code library for develop
1 parent bb6ba3f commit 09331a2

File tree

31 files changed

+412
-206
lines changed

31 files changed

+412
-206
lines changed

README.md

+2-74
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,2 @@
1-
<a href="https://github.com/nisit15/KotlinMultiLanguage"><img src="https://camo.githubusercontent.com/b8444ae133e24073026aaac5f84b23a896fa8dd2/68747470733a2f2f7472617669732d63692e6f72672f6b697474696e756e662f6675656c2e7376673f6272616e63683d6d6173746572" alt="Build Status" style="max-width:100%;"></a> <a href="https://www.ninenox.com"><img src="https://camo.githubusercontent.com/eb54d63dadf4ca40382d1b11f736ec31a24e0aff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616e64726f69642d737570706f72742d677265656e2e737667" alt="Android" style="max-width:100%;"></a>
2-
3-
# KotlinLocalization
4-
Android kotlin library for change ui language in android application on runtime.
5-
6-
![Alt Text](https://media.giphy.com/media/VEcDJtSPLjQ6X3NRbs/giphy.gif)
7-
8-
9-
# Installation
10-
On your module app `build.gradle` add
11-
```
12-
dependencies {
13-
implementation 'com.ninenox.kotlinlocalemanager:kotlin-locale-manager:1.0.0'
14-
}
15-
```
16-
17-
# Getting Started
18-
19-
1. Create class and extend `ApplicationLocale`.
20-
21-
```
22-
class App : ApplicationLocale() {
23-
24-
}
25-
```
26-
27-
2. In `AndroidManifest.xml`
28-
```
29-
<application
30-
android:name=".App"
31-
...
32-
/>
33-
```
34-
35-
3. In folder `res` add new locale.
36-
37-
```
38-
values-th
39-
- strings.xml
40-
values-en
41-
- strings.xml
42-
```
43-
44-
4. In any `Activity` extend `AppCompatActivityBase` on it.
45-
46-
```
47-
class MainActivity : AppCompatActivityBase() {
48-
49-
override fun onCreate(savedInstanceState: Bundle?) {
50-
super.onCreate(savedInstanceState)
51-
setContentView(R.layout.activity_main)
52-
53-
...
54-
55-
}
56-
57-
}
58-
```
59-
5. Call funtion `setNewLocale("...")` for set current language and refresh UI.
60-
```
61-
62-
setNewLocale("EN") // Sample "EN","TH","DE"...
63-
64-
```
65-
66-
6. Get current code language string.
67-
```
68-
LocaleManager(this).language.toString() // "EN"
69-
```
70-
71-
72-
73-
![Alt Text](https://media.giphy.com/media/vFKqnCdLPNOKc/giphy.gif)
74-
1+
# KotlinMultiLanguage
2+
Android Kotlin Multi Language With Locale.

app/build.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ apply plugin: 'kotlin-android'
44

55
apply plugin: 'kotlin-android-extensions'
66

7+
8+
79
android {
810
compileSdkVersion 29
911
buildToolsVersion "29.0.2"
1012
defaultConfig {
11-
applicationId "com.ninenox.demokotlinlocalemanager"
13+
applicationId "com.ninenox.kotlinmultilanguage"
1214
minSdkVersion 15
1315
targetSdkVersion 29
1416
versionCode 1
@@ -24,16 +26,14 @@ android {
2426
}
2527

2628
dependencies {
29+
2730
implementation fileTree(dir: 'libs', include: ['*.jar'])
2831
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2932
implementation 'androidx.appcompat:appcompat:1.1.0'
3033
implementation 'androidx.core:core-ktx:1.1.0'
3134
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
32-
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
3335
testImplementation 'junit:junit:4.12'
3436
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3537
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
36-
37-
implementation 'com.ninenox.kotlinlocalemanager:kotlin-locale-manager:1.0.0'
38-
38+
implementation project(path: ':kotlinlocalemanager')
3939
}

app/src/androidTest/java/com/ninenox/demokotlinlocalemanager/ExampleInstrumentedTest.kt renamed to app/src/androidTest/java/com/ninenox/kotlinmultilanguage/ExampleInstrumentedTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ninenox.demokotlinlocalemanager
1+
package com.ninenox.kotlinmultilanguage
22

33
import androidx.test.platform.app.InstrumentationRegistry
44
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
1919
fun useAppContext() {
2020
// Context of the app under test.
2121
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22-
assertEquals("com.ninenox.demokotlinlocalemanager", appContext.packageName)
22+
assertEquals("com.ninenox.kotlinmultilanguage", appContext.packageName)
2323
}
2424
}

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.ninenox.demokotlinlocalemanager">
3+
package="com.ninenox.kotlinmultilanguage">
44

55
<application
6-
android:name=".MyApplication"
6+
android:name=".App"
77
android:allowBackup="true"
88
android:icon="@mipmap/ic_launcher"
99
android:label="@string/app_name"

app/src/main/java/com/ninenox/demokotlinlocalemanager/BlankFragment.kt

-36
This file was deleted.

app/src/main/java/com/ninenox/demokotlinlocalemanager/MainActivity.kt

-33
This file was deleted.

app/src/main/java/com/ninenox/demokotlinlocalemanager/MyApplication.kt

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ninenox.kotlinmultilanguage
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import android.content.res.Configuration
6+
import com.ninenox.kotlinlocalemanager.ApplicationLocale
7+
import com.ninenox.kotlinlocalemanager.LocaleManager
8+
9+
class App : ApplicationLocale() {
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.ninenox.kotlinmultilanguage
2+
3+
import android.os.Bundle
4+
import com.ninenox.kotlinlocalemanager.AppCompatActivityBase
5+
import com.ninenox.kotlinlocalemanager.ApplicationLocale.Companion.localeManager
6+
import kotlinx.android.synthetic.main.activity_main.*
7+
8+
class MainActivity : AppCompatActivityBase() {
9+
10+
override fun onCreate(savedInstanceState: Bundle?) {
11+
super.onCreate(savedInstanceState)
12+
setContentView(R.layout.activity_main)
13+
14+
initView()
15+
16+
}
17+
18+
private fun initView() {
19+
change_language_th_button.setOnClickListener {
20+
setNewLocale("TH")
21+
}
22+
change_language_en_button.setOnClickListener {
23+
setNewLocale("EN")
24+
}
25+
}
26+
27+
28+
}

app/src/main/res/layout/activity_main.xml

+7-18
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
<FrameLayout
10-
android:id="@+id/fragment_frame_layout"
11-
android:layout_width="match_parent"
12-
android:layout_height="0dp"
13-
android:layout_marginTop="16dp"
14-
android:layout_marginBottom="16dp"
15-
app:layout_constraintBottom_toTopOf="@+id/textView"
16-
app:layout_constraintEnd_toEndOf="parent"
17-
app:layout_constraintStart_toStartOf="parent"
18-
app:layout_constraintTop_toTopOf="parent" />
19-
209
<TextView
2110
android:id="@+id/textView"
2211
android:layout_width="wrap_content"
@@ -28,25 +17,25 @@
2817
app:layout_constraintTop_toTopOf="parent" />
2918

3019
<Button
31-
android:id="@+id/th_button"
20+
android:id="@+id/change_language_th_button"
3221
android:layout_width="wrap_content"
3322
android:layout_height="wrap_content"
34-
android:layout_marginTop="44dp"
35-
android:text="TH"
23+
android:layout_marginTop="37dp"
24+
android:text="Thai"
3625
app:layout_constraintEnd_toEndOf="parent"
3726
app:layout_constraintHorizontal_bias="0.5"
3827
app:layout_constraintStart_toStartOf="parent"
3928
app:layout_constraintTop_toBottomOf="@+id/textView" />
4029

4130
<Button
42-
android:id="@+id/en_button"
31+
android:id="@+id/change_language_en_button"
4332
android:layout_width="wrap_content"
4433
android:layout_height="wrap_content"
45-
android:layout_marginTop="35dp"
46-
android:text="EN"
34+
android:layout_marginTop="29dp"
35+
android:text="English"
4736
app:layout_constraintEnd_toEndOf="parent"
4837
app:layout_constraintHorizontal_bias="0.5"
4938
app:layout_constraintStart_toStartOf="parent"
50-
app:layout_constraintTop_toBottomOf="@+id/th_button" />
39+
app:layout_constraintTop_toBottomOf="@+id/change_language_th_button" />
5140

5241
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/fragment_blank.xml

-14
This file was deleted.
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">DemoKotlinLocaleManager</string>
3+
<string name="app_name">KotlinMultiLanguage</string>
44
<string name="hello_world">Hello World!</string>
5-
<string name="hello_blank_fragment">Hello blank fragment</string>
65
</resources>
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">DemoKotlinLocaleManager</string>
3+
<string name="app_name">KotlinMultiLanguage</string>
44
<string name="hello_world">สวัสดีโลก!</string>
5-
<string name="hello_blank_fragment">สวัสดี fragment</string>
65
</resources>

app/src/main/res/values/strings.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<resources>
2-
<string name="app_name">DemoKotlinLocaleManager</string>
3-
<string name="hello_world">Hello World!</string>
4-
5-
<!-- TODO: Remove or change this placeholder text -->
6-
<string name="hello_blank_fragment">Hello blank fragment</string>
2+
<string name="app_name">KotlinMultiLanguage</string>
3+
<string name="hello_world">-</string>
74
</resources>

app/src/test/java/com/ninenox/demokotlinlocalemanager/ExampleUnitTest.kt renamed to app/src/test/java/com/ninenox/kotlinmultilanguage/ExampleUnitTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ninenox.demokotlinlocalemanager
1+
package com.ninenox.kotlinmultilanguage
22

33
import org.junit.Test
44

build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ buildscript {
55
repositories {
66
google()
77
jcenter()
8-
8+
99
}
1010
dependencies {
11+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
12+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13+
1114
classpath 'com.android.tools.build:gradle:3.5.3'
1215
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1316
// NOTE: Do not place your application dependencies here; they belong
@@ -19,7 +22,7 @@ allprojects {
1922
repositories {
2023
google()
2124
jcenter()
22-
25+
2326
}
2427
}
2528

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Mon Dec 16 10:24:30 ICT 2019
1+
#Sun Dec 15 09:41:21 ICT 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

kotlinlocalemanager/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

0 commit comments

Comments
 (0)