. . .

Localisation Module

images/download/thumbnails/61479145/modules-localization.png

Introduction

The Localisation Module takes a Json file, flattens its hierarchy and writes it into a String as well as a key value map.

It is possible to manipulate the map via Frontend code, which will also be written back into the original Json file.

Key Capabilities

Capability

Description

Flattening Json hierarchy

The Localisation module basically converts a Json object taken from a Json file to a String and a Key value Map.

Manipulating Json map and file (via frontend code)

Give possibility to manipulate a Json object taken from a Json file via a Map.

Module Setup and Configuration

No configuration necessary.

Limitations

The manipulation of the map and therefore the modification of the Json file are only available via Frontend code.

It does not work for Backend code or the dashboard.

Example (Quick Guide)

Follow the quick guide steps provided below in order to create the desired Translation object.

  1. Create an instance of the Translation class.

  2. Set the language attribute

  3. Upload the Json file.

  4. Change the Json object. (optional and only via frontend code)

  5. Use the generated flat hierarchy for further workflow.

Example (Detailed Guide)

First of all, make sure the Localisation module is attached to your Backend app (see My Modules) so your ApiOmat instance looks like this:

images/download/attachments/61479145/Screenshot1.png

1. Create Translation object and set language

Simply go to the dashboard data editor, select the class Translation, create a new instance and set the "language" attribute.

The language will be formatted automatically to all lower cases and whitespaces will be deleted.

images/download/attachments/61479145/8.png

2. Upload Json file

Upload a Json file into the attribute "jsonFile".

It does not matter if the language or the Json file is uploaded first.

Sample json file
{
"boolean": true,
"color": "#82b92c",
"object": {
"a": "b",
"c": "d",
"e": "f"
}
}

images/download/attachments/61479145/9.png

The flattened hierarchy of the uploaded Json can be found in the "jsonString" attribute as a String value.

The uploaded Json is also available as a key value Map in the attribute "wording".

Generate Translation object via native module code

The generation of a Translation object can also be d by creating the needed class instances (as described above) via native module code :one

generating Translation object via nativemodule
r.setHooksInUsedModulesEnabled( true );
final Translation trans = this.model.createObject( Translation.class, r );
trans.save( );
trans.setLanguage( "de" );
 
try (InputStream jsonFileData = getClass( ).getClassLoader( ).getResourceAsStream( "src/META-INF/imports/test.json" ))
{
trans.postJsonFile( jsonFileData, "test", "json" );
trans.save( );
if ( trans.getWording( ) != null )
{
obj.setJsonMap( trans.getWording( ) );
}
}

Generate Translation object via SDK

The generation of an instance of Translation can also be executed via a SDK of your choice. In the following example the Java SDK is used. This example show a successful manipulation of a Map object generated from a Json file :

creating Translation object via SDK
/* creating Translation object & setting language */
Translation translation = new Translation( );
translation.setLanguage( "english" );
 
/* uploading json file */
final byte[ ] data = getResourceFileAsBytes( "imports/test.json" );
translation.postJsonFile( data, "imports/test.json", "json" );
translation.load( );
 
/*manipulating generated map & json file */
final Map<String, String> existingWordings = translation.getWording( );
existingWordings.put( "say_hello", "Hallo" );
translation.setWording( existingWordings );

Module Classes Overview

The following table contains information about the Localisation classes, their attributes and their meaning :

Class Name

Class Description

Class Attribute

Class Attribute Description

Translation

An object of this class takes a json file, flattens its hierarchy

and can be specified by a (custom) language identifier.

jsonFile

a Json File object to convert (It can be modified back by manipulating the Map object to which its content was converted)

jsonString

a String that gets generated dynamically after the content value of "jsonFile"

wording

a Map that gets generated dynamically after the content value of "jsonFile" (It can be manipulated via frontend code)

language

a String identifier to specify the object