- 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 viewIn memory
: Strings present in memoryAll
: All Strings of the application
Example project integrating this in the Android build process can be found here
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
// 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
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.
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"))
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",
}
]
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>