Skip to content
A tool to live edit translations in an Android application.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
app
gradle/wrapper
images
kunstmaan-translations-editor
.gitignore
CHANGELOG.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
publish.gradle
settings.gradle

README.md

Kunstmaan Translations Editor

Features

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

                  

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

Installation

in the build.gradle of your app, put:

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

Usage

1. Build the Kunstmaan Translations Editor

// locales to be considered by the Translations Editor
List<Locale> localeList = new ArrayList<>();
                localeList.add(new Locale("nl"));
                localeList.add(new Locale("en", "US"));
                
new KunstmaanTranslationUtil.Builder(application, R.string.class.getFields(), locales, new Locale("en", "US"))
                            .build();

The builder needs the application context, the fields from the string class, the locales to be used in the Editor and the application's default locale

2. Show the Editor

with KunstmaanTranslationUtil.showTranslationsWindow();

In this example we use a button to show the Editor but we recommend the library KunstmaanShakerMenu to show the Editor after shaking the phone.

Customization

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.

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

Set a custom Json format

The default Json format of the shared changes is :

[
  {
    "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}
.addCustomJsonFormat("{\n" +
                     "  \"myCustomNameForTheKey\": \"${key}\",\n" +
                     "  \"myCustomNameForTheNewValue\": \"${newValue}\",\n" +
                     "}")

will give you

[
{
  "myCustomNameForTheKey": "key_of_the_string",
  "myCustomNameForTheNewValue": "new value",
}
]

Set a custom Xml format

The default Xml format of the shared changes is :

<?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}
.addCustomXmlFormat("myNewRootTag",
	"<myName>\n" +
	"    <myLocaleTag>${locale}</myLocaleTag>\n" +
	"    <myKeyTag>${key}</myKeyTag>\n" +
	"    <myOldValueTag>${oldValue}</myOldValueTag>\n" +
	"    <myNewValueTag>${newValue}</myNewValueTag>\n" +
	"</myName>")

will give

<?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>
You can’t perform that action at this time.