Translation in demo app for java android

I don’t know how to use the translation can you please tell me how can i translate how can i set up the translation i need this in order to can you please be specific where to add the code and how to set up that the customer could pick up the language

Hi @alexbets,

Please refer to the following post to see how to add message translation in your app.

1 Like

@darshan.bhanushali can please tell me?

@darshan.bhanushali where i chould add this code? HashMap<String, String> translationsMap = new HashMap<String, String>();
try {
JSONObject metadata = Message.getMetadata();
if (metadata != null) {
JSONObject injectedObject = metadata.getJSONObject("@injected");
if (injectedObject != null && injectedObject.has(“extensions”)) {
JSONObject extensionsObject = injectedObject.getJSONObject(“extensions”);
if (extensionsObject != null && extensionsObject.has(“message-translation”)) {
JSONObject messageTranslationObject = extensionsObject.getJSONObject(“message-translation”);
JSONArray translations = messageTranslationObject.getJSONArray(“translations”);
for (int i = 0; i < translations.length(); i++) {
JSONObject translation = translations.getJSONObject(i);
String translatedText = translation.getString(“message_translated”);
String translatedLanguage = translation.getString(“language_translated”);
translationsMap.put(translatedLanguage, translatedText);
String translated_message = translationsMap.size() > 0 ? “-\n”+translationsMap.values().toString() : “”;
message = ((TextMessage) baseMessage).getText()+translated_message;

        Log.e(((TextMessage) Message).getText()+translated_message);

    } catch (Exception e) {
        Log.e(TAG, "Exception: " + e.getMessage()); 

below what sentence please be more specific

@darshan.bhanushali can i have a reponse.

Hi @alexbets,

You need to add this code in an adapter where you check whether the message is TextMessage or not.
If you are using our sample app then you can add above code in the line mentioned in link.

i have this problem @darshan.bhanushali please help me!

getMatada(); can not resolved the symbol.

Hi @alexbets,

Can you replace “Message” with “baseMessage”.

`JSONObject metadata = baseMessage.getMetadata();`
1 Like

Hi @darshan.bhanushali It is not working it is not translating me anything and also it is duplicating the messages

@darshan.bhanushali hi brother it is not working it is not translating i dont know why

Hi @alexbets,

We checked at our end and it is working fine. Please check that you have enabled Message Transation Extension from dashboard.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.