Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.1

* Android - Migrate to build-in Kotlin

## 0.4.0

* Add support for **JSON Asset** file locale
Expand Down
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SDK [flutter_localizations](https://api.flutter.dev/flutter/flutter_localization
itself. Follow the steps below to use the package, or you can check out a
small [example](https://pub.dev/packages/flutter_localization/example) project of the package.

<a href="https://www.buymeacoffee.com/eamchanndara" target="_blank"><img height='40' style='border:0px;height:40px;' src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me a Coffee" style="height: 60px !important;width: 217px !important;" ></a>
<a href='https://ko-fi.com/J3J3POSKS' target='_blank'><img height='40' style='border:0px;height:40px;' src='https://storage.ko-fi.com/cdn/kofi5.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
<a href="https://www.buymeacoffee.com/eamchanndara" target="_blank"><img height='40' width='145' style='border:0px;height:40px;' src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me a Coffee" style="height: 60px !important;width: 217px !important;" ></a>
<a href='https://ko-fi.com/J3J3POSKS' target='_blank'><img height='40' width='160' style='border:0px;height:40px;' src='https://storage.ko-fi.com/cdn/kofi5.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

# Breaking Changes

Expand Down Expand Up @@ -89,12 +89,18 @@ final FlutterLocalization localization = FlutterLocalization.instance;
@override
void initState() {
localization.onTranslatedLanguage = _onTranslatedLanguage;
_initializeLocalization();

/// Initialize with map-based
_initializeLocalizationMapBased();

/// or JSON asset base on your language source
_initializeLocalizationJsonAsset();

/// make sure to use only 1 type of source
super.initState();
}

Future<void> _initializeLocalization() async {
// Map-based configuration
Future<void> _initializeLocalizationMapBased() async {
await localization.init(
initLanguageCode: 'en',
source: LocalizationSource.map,
Expand All @@ -104,17 +110,18 @@ Future<void> _initializeLocalization() async {
MapLocale('ja', AppLocale.JA),
],
);
}

// Or JSON-based configuration using JsonLocale:
// await localization.init(
// initLanguageCode: 'en',
// source: LocalizationSource.jsonAsset,
// jsonLocales: const [
// JsonLocale('en', 'assets/i18n/en.json'),
// JsonLocale('km', 'assets/i18n/km.json'),
// JsonLocale('ja', 'assets/i18n/ja.json'),
// ],
// );
Future<void> _initializeLocalizationJsonAsset() async {
await localization.init(
initLanguageCode: 'en',
source: LocalizationSource.jsonAsset,
jsonLocales: const [
JsonLocale('en', 'assets/i18n/en.json'),
JsonLocale('km', 'assets/i18n/km.json'),
JsonLocale('ja', 'assets/i18n/ja.json'),
],
);
}

// The setState call here is required to rebuild the app after language changes.
Expand Down
47 changes: 0 additions & 47 deletions android/build.gradle

This file was deleted.

52 changes: 52 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
group = "com.mastertipsy.flutter_localization"
version = "1.0-SNAPSHOT"

buildscript {
val kotlinVersion = "2.3.20"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:9.0.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

plugins {
id("com.android.library")
}

android {
namespace = "com.mastertipsy.flutter_localization"
compileSdk = 36

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

sourceSets {
getByName("main") {
java.srcDirs("src/main/kotlin")
}
}

defaultConfig {
minSdk = 21
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}
6 changes: 0 additions & 6 deletions android/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

1 change: 0 additions & 1 deletion android/settings.gradle

This file was deleted.

1 change: 1 addition & 0 deletions android/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "flutter_localization"
4 changes: 2 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mastertipsy.flutter_localization">
</manifest>
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package com.mastertipsy.flutter_localization

import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** FlutterLocalizationPlugin */
class FlutterLocalizationPlugin: FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel
class FlutterLocalizationPlugin :
FlutterPlugin,
MethodCallHandler {
// The MethodChannel that will the communication between Flutter and native Android
//
// This local reference serves to register the plugin with the Flutter Engine and unregister it
// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_localization")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
override fun onMethodCall(
call: MethodCall,
result: Result
) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
69 changes: 0 additions & 69 deletions example/android/app/build.gradle

This file was deleted.

45 changes: 45 additions & 0 deletions example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}

android {
namespace = "com.mastertipsy.flutter_localization_example"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.mastertipsy.flutter_localization_example"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

flutter {
source = "../.."
}
Loading