Skip to content

Commit

Permalink
Merge pull request #10 from lsaudon/save-pub-get
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
lsaudon authored Nov 2, 2022
2 parents 8cf51ee + da0749f commit e431cf2
Show file tree
Hide file tree
Showing 47 changed files with 553 additions and 24 deletions.
17 changes: 7 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
# Changelog

## [0.3.2]
## [0.4.0]

- Saved all modified files
- Delete Added or Changed subtitles in Changelog
- Run flutter pub get after change arb files

### Added
## [0.3.2]

- Fix extension on Windows
- Bump node, eslint

## [0.3.1]

### Added

- Flutter project can be in a sub-folder
- Extract text in right project for multi-project

## [0.2.0]

### Added

- Add setting `l10nization.appLocalizationsVariable`
- Enable Open VSX

## [0.1.1]

### Changed

- Disable Open VSX

## [0.1.0]

### Added

- Add string to all arb files.

[0.4.0]: https://github.com/lsaudon/l10nization/releases/tag/release-0.4.0
[0.3.2]: https://github.com/lsaudon/l10nization/releases/tag/release-0.3.2
[0.3.1]: https://github.com/lsaudon/l10nization/releases/tag/release-0.3.1
[0.2.0]: https://github.com/lsaudon/l10nization/releases/tag/release-0.2.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ By default, the variable used for AppLocalizations is `l10n` you can change it i
"l10nization.appLocalizationsVariable": "yourVariable"
```

By default, the extension launches `flutter pub get` via the [Dart extension](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code). You can disable it in the settings.

## Release Notes

For full release notes, see the [changelog](CHANGELOG.md).
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"icon": "images/logo.png",
"name": "l10nization",
"displayName": "L10nization",
"version": "0.3.2",
"version": "0.4.0",
"publisher": "lsaudon",
"description": "A tool for extracting text to arb files in a Flutter application.",
"author": {
Expand Down Expand Up @@ -41,6 +41,11 @@
"type": "string",
"default": "l10n",
"description": "Set the variable name for AppLocalizations."
},
"l10nization.flutterPubGetEnabled": {
"type": "bool",
"default": "true",
"description": "If enabled, run the `flutter.packages.get` command of the `Dart` extension."
}
}
}
Expand Down
39 changes: 32 additions & 7 deletions src/localizationInputBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import * as yaml from 'yaml';
import { ReplaceParameters } from './replaceParameters';

const parentSection = 'l10nization';

const appLocalizationsVariableSection = 'appLocalizationsVariable';
const defaultVariable = 'l10n';

const flutterPubGetEnabledSection = 'flutterPubGetEnabled';
const defaultPubGet = true;

const first = 0;

async function getArbFiles(projectName: string) {
Expand Down Expand Up @@ -41,13 +46,13 @@ async function getChangesForArbFiles(
): Promise<vscode.WorkspaceEdit> {
const projectName = getProjectName(replaceParameters.documentUri);
const files = await getArbFiles(projectName);
const results: Thenable<vscode.TextDocument>[] = [];
const openTextDocuments: Thenable<vscode.TextDocument>[] = [];
files.forEach((file) => {
results.push(vscode.workspace.openTextDocument(file));
openTextDocuments.push(vscode.workspace.openTextDocument(file));
});
const workspaceEdit = new vscode.WorkspaceEdit(),
{ value } = replaceParameters.keyValuePair;
(await Promise.all(results)).forEach((content, index) => {
const workspaceEdit = new vscode.WorkspaceEdit();
const { value } = replaceParameters.keyValuePair;
(await Promise.all(openTextDocuments)).forEach((content, index) => {
workspaceEdit.replace(
files[index],
new vscode.Range(
Expand All @@ -71,16 +76,36 @@ async function getChangesForArbFiles(
return workspaceEdit;
}

async function runIfExist(flutterPackagesGetCommand: string) {
const commands = await vscode.commands.getCommands();
if (commands.some((command) => command === flutterPackagesGetCommand)) {
await vscode.commands.executeCommand(flutterPackagesGetCommand);
}
}

export function localizationInputBox(
replaceParameters: ReplaceParameters
): void {
const inputBox = vscode.window.createInputBox();
inputBox.value = replaceParameters.keyValuePair.key;
inputBox.onDidAccept(async () => {
const edit = await getChangesForArbFiles(inputBox.value, replaceParameters);
inputBox.hide();
return vscode.workspace.applyEdit(edit);
const edit = await getChangesForArbFiles(inputBox.value, replaceParameters);
await vscode.workspace.applyEdit(edit);
await new Promise((f) => {
setTimeout(f, 1000);
});
await vscode.workspace.saveAll(true);
const flutterPubGetEnabled =
vscode.workspace
.getConfiguration(parentSection)
.get<string>(flutterPubGetEnabledSection) ?? defaultPubGet;
if (flutterPubGetEnabled) {
await runIfExist('flutter.packages.get');
}
return vscode.Disposable;
});

inputBox.onDidHide(() => inputBox.dispose());
inputBox.show();
}
13 changes: 13 additions & 0 deletions src/test/suite/my_app/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
71 changes: 71 additions & 0 deletions src/test/suite/my_app/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.my_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

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.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_app">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
34 changes: 34 additions & 0 deletions src/test/suite/my_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_app">
<application
android:label="my_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.my_app

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
18 changes: 18 additions & 0 deletions src/test/suite/my_app/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_app">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Loading

0 comments on commit e431cf2

Please sign in to comment.