Skip to content

Commit

Permalink
Merge pull request #1 from Kunstmaan/prePublish
Browse files Browse the repository at this point in the history
Pre publish
  • Loading branch information
krispypen committed Mar 26, 2018
2 parents 8236123 + ce32baf commit 7a846ae
Show file tree
Hide file tree
Showing 75 changed files with 3,039 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .idea/misc.xml

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

10 changes: 10 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

Empty file added CHANGELOG.md
Empty file.
157 changes: 157 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Kunstmaan Translations Editor

## Features
- [x] Edit your String.xml of specified Locales directly in the application
- [x] Share the modified values (xml or json)
- [x] Custom json and xml format
- [x] Add patterns to be ignored in the translations window (Strings from libraries, ...)
- [x] See the strings in 3 categories :
- `Current` : Strings from the current view
- `In memory` : Strings present in memory
- `All` : All Strings of the application


<img src="images/gif.gif" width="30%"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/mainscreen.png" width="30%"/>

Example project integrating this in the Android build process can be found here

## Installation

in the `build.gradle` of your app, put:

```groovy
implementation 'be.kunstmaan.android:kunstmaan-translations-editor:1.0.0'
// implementationDebug if needed only for debugging purposes
```

## Usage

### 1. Build the Kunstmaan Translations Editor

```java
new KunstmaanTranslationUtil.Builder(application, R.string.class.getFields())
.build();
```

### 2. Show the Editor

with `KunstmaanTranslationUtil.showTranslationsWindow();`

In this example we use a button to show the Editor but we recommend the library [KunstmaanShakerMenu](https://github.com/Kunstmaan/KunstmaanShakerMenu) to show the Editor after shaking the phone.

## Customization


### Add additional Locales files to be considered by the Editor

The default file is considered automatically.

- use the same prefix as your additionnal xml file : `new Locale("nl")`

```java
List<Locale> localeList = new ArrayList<>();
localeList.add(new Locale("nl"));
localeList.add(new Locale("de"));


new KunstmaanTranslationUtil.Builder(application, R.string.class.getFields())
.addLocales(localeList)
.build();

```


### Add a `Pattern` to be ignored by the Editor

Use a [regex] (https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) to specify which keys from strings.xml should be ignored by the Editor.

```java
.addIgnorePattern(Pattern.compile("regexOfPatternToBeIgnored"))
```

### Set a custom Json format

The default Json format of the shared changes is :

```json
[
{
"key": "key_of_string",
"locale": "localeOfTheString",
"newValue": "new value",
"oldValue": "old value"
}
]
```

you can provide your own format to be used.
Use this place holders where you want the value to appear :

- `${key}`
- `${locale}`
- `${newValue}`
- `${oldValue}`

```java
.addCustomJsonFormat("{\n" +
" \"myCustomNameForTheKey\": \"${key}\",\n" +
" \"myCustomNameForTheNewValue\": \"${newValue}\",\n" +
"}")
```

will give you
```json
[
{
"myCustomNameForTheKey": "key_of_the_string",
"myCustomNameForTheNewValue": "new value",
}
]
```

### Set a custom Xml format

The default Xml format of the shared changes is :

```xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<Translations>
<translation>
<locale>locale</locale>
<key>key_of_the_string</key>
<oldValue>old value</oldValue>
<newValue>new value</newValue>
</translation>
</Translations>
```

you can provide your own format.
Use this place holders where you want the value to appear :

- `${key}`
- `${locale}`
- `${newValue}`
- `${oldValue}`

```java
.addCustomXmlFormat("myNewRootTag",
"<myName>\n" +
" <myLocaleTag>${locale}</myLocaleTag>\n" +
" <myKeyTag>${key}</myKeyTag>\n" +
" <myOldValueTag>${oldValue}</myOldValueTag>\n" +
" <myNewValueTag>${newValue}</myNewValueTag>\n" +
"</myName>")
```

will give
```xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<myNewRootTag>
<myName>
<myLocaleTag>locale</myLocaleTag>
<myKeyTag>string_key</myKeyTag>
<myOldValueTag>old value</myOldValueTag>
<myNewValueTag>new value</myNewValueTag>
</myName>
</myNewRootTag>
```
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "kunstmaan.be.kunstmaantranslationseditor"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile project(path: ':kunstmaan-translations-editor')
}
apply plugin: 'android-maven'
apply plugin: 'com.jfrog.bintray'
apply from: '../publish.gradle'
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package be.kunstmaan.translationseditor;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("be.kunstmaan.translationseditor", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package be.kunstmaan.translationseditor;

import android.app.Application;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import kunstmaan.be.kunstmaantranslationseditor.R;

public class TranslationUtils {
public static void initTranlsationsEditor(Application application) {

List<Locale> localeList = new ArrayList<>();
localeList.add(new Locale("nl"));

new KunstmaanTranslationUtil.Builder(application, R.string.class.getFields())
.addLocales(localeList)
.addCustomJsonFormat("{\n" +
" \"myCustomNameForTheKey\": \"${key}\",\n" +
" \"myCustomNameForTheNewValue\": \"${newValue}\",\n" +
"}")
.addCustomXmlFormat("myNewRootTag",
"<myName>\n" +
" <myLocaleTag>${locale}</myLocaleTag>\n" +
" <myKeyTag>${key}</myKeyTag>\n" +
" <myOldValueTag>${oldValue}</myOldValueTag>\n" +
" <myNewValueTag>${newValue}</myNewValueTag>\n" +
"</myName>")
.build();

}

}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kunstmaan.be.kunstmaantranslationseditor">

<application
android:name="be.kunstmaan.translationseditor.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="be.kunstmaan.translationseditor.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package be.kunstmaan.translationseditor;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import kunstmaan.be.kunstmaantranslationseditor.R;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button showEditorButton = findViewById(R.id.show_button);
showEditorButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
KunstmaanTranslationUtil.showTranslationsWindow();
}
});
}

}
Loading

0 comments on commit 7a846ae

Please sign in to comment.