Skip to main content

Braze

Localize your Braze campaigns with Transifex.

Written by Transifex
Updated over 2 weeks ago

Through Transifex’s integration with Braze, you can pull translations from Transifex into Braze directly and launch multilingual engagement campaigns.


Connecting your Transifex account to Braze

You’ll need to connect your Transifex account to Braze to pull translations back into Braze. To do this:

  1. From the left navigation, head to Settings-> Workspace Seetings -> Connected Content.


  2. Go to the Connected Content tab and click +Add Credential near the top right corner.

  3. In the popup modal, select Token Autentication and follow the template and provide the token from Transifex. You can save that with something like transifex_token.




Adding content to Transifex

For now, the integration does not support pushing content from Braze to Transifex. You’ll have to manually create a JSON file with the content you want to translate and upload it to Transifex. Here's how you can do this:

  1. Open up a new file in a text editor such as Atom.

  2. Type in your source content following the structure in the example below. Be sure to include the source content on both sides of the colon since the key and value are identical in the source language.

    {
    "Your source content":"Your source content",
    "Another source string":"Another source string"
    }

  3. Save the file as a JSON file with the extension .json.

  4. Head to the project you created earlier in Transifex and upload your file as a Key-value JSON file.

Now, your content is ready to be translated!


Getting translations into Braze

This example code snippet utilizes the Transifex resource translations API and the user’s language attribute. Based on your needs, you can then loop through the string objects and pull in the relevant content using the following Liquid:

{% assign organization = "<organization_name>" %}
{% assign project = "<project_name>" %}
{% assign resource = "<resource_name>" %}
{% assign language = "<langua>" %}

{% if {{${language}}} == "en" or {{${language}}} == "it" or {{${language}}} == "de" or {{${language}}} == "another_language_you_support" %}
{% connected_content

https://rest.api.transifex.com/resource_translations?filter[resource]=o:{{organization}}:p:{{project}}:r:{{resource}}&filter[language]=l:{{language}}
:auth_credentials transifex_token
:headers {
"Content-Type": "application/vnd.api+json"
}
:save strings
%}
{% endif %}
{% if {{strings}} != null and {{strings.data[0].attributes.strings.other}} != "" and {{${language}}} != null %}
{{strings.data[0].attributes.strings.other}}
{% else %}
{% abort_message('null or blank') %}
{% endif %}


Tweaking the snippet

Let's say you've followed the previous steps in the guide and now have the following:

  • A string in the JSON file you uploaded that says Your source content

  • A Transifex organization with the slug my_org

  • A Transifex project with the slug braze

  • A resource with the slug pushnotification

  • English as your source language, and German (de) and French (fr) as your target languages

Your project and resource slugs can be found in your browser's URL bar after selecting a resource in Transifex. The URL follows this structure:


For example, if your Transifex project is located at https://app.transifex.com/my_org/braze/pushnotification/, the project_name will be “braze” and the resource_name will be “pushnotification”.


Then your tweaked snippet would look like this:

{% assign organization = "my_org" %}
{% assign project = "braze" %}
{% assign resource = "pushnotification" %}
{% assign language = "de" %}

{% if {{${language}}} == "en" or {{${language}}} == "it" or {{${language}}} == "es" or {{${language}}} == "another_language_you_support" %}
{% connected_content
https://rest.api.transifex.com/resource_translations?filter[resource]=o:{{organization}}:p:{{project}}:r:{{resource}}&filter[language]=l:{{language}}
:method GET
:auth_credentials transifex_token
:headers {
"Integration": "Braze"
}
:accept application/vnd.api+json
:save strings
%}
{% endif %}
{% if {{strings}} != null and {{strings.data[0].attributes.strings.other}} != "" and {{${language}}} != null %}
{{strings.data[0].attributes.strings.other}}
{% else %}
{% abort_message('null or blank') %}
{% endif %}

Note : In the example above we are bringing a translation for one single string. We need to use the hash value of the string that can be found from Transifex editor. If we bring a list of translations we can use some loop logic and select only the specific hash values for the strings we want in order to have the translations picked from the json response. See the example below.



{% comment %}
Iterate through the list to find your specific strings
{% endcomment %}

{% for item in strings.data %}

{% comment %}

Note: 'item' refers to the current item in the loop.

If your connected_content was saved as 'strings', the loop variable is 'item'.

{% endcomment %}

{% if item.id contains "hash_value_1" %}

{% assign email_header = item.attributes.strings.other %}

{% elsif item.id contains "hash_value_2" %}

{% assign email_body = item.attributes.strings.other %}

{% elsif item.id contains "hash_value_3" %}

{% assign email_footer = item.attributes.strings.other %}

{% endif %}

{% endfor %}

In the above example we consider three variables email_ header,body,footer to be the three parts in the email we will replace if we find translations. Notice in he following example we use |default so that if for some reason we do not get a translation we have the original text on the email.

In Braze this would look something like this:

<html>

<h1>{{ email_header | default: "My header text"}}</h1>

<p>{{ email_body | default: 'My body text' }}</p>

<div class="footer">{{ email_footer | default: 'My footer text' }}</div>

</html>

Using the snippet

Once you've tweaked the snippet, you can paste it into fields you want to be translated, such as the campaign title and message body.

{% assign organization = "my_org" %}
{% assign project = "braze" %}
{% assign resource = "pushnotification" %}
{% assign language = "de" %}

{% if {{${language}}} == "en" or {{${language}}} == "it" or {{${language}}} == "es" or {{${language}}} == "another_language_you_support" %}
{% connected_content
https://rest.api.transifex.com/resource_translations/o:{{organization}}:p:{{project}}:r:{{resource}}:s:{{source_hash}}:l:{{language}}
:method GET
:headers {
"Authorization": "Bearer <transifex_bearer_token>",
"Integration": "Braze"
}
:accept application/vnd.api+json
:save strings
%}

And that's it! Now, you can continue setting up your campaign.


Your next campaign

Let's say you've run one campaign and are ready to run another. Instead of repeating all of the steps above, you only need to do a few things:

  1. Add your new content as additional lines in your source JSON file:

    {
    "Your source content":"Your source content",
    "Another source string":"Another source string",
    "Campaign 2 source string":"Campaign 2 source string"
    }

  2. Update your existing source file in Transifex. You can learn how to do this in this article.

  3. ​​Update Line 1 of the snippet with the updated source string. Everything else in the snippet can remain the same if you use the same project, resource, and target languages as before for the new campaign.

    {% assign key = "Campaign 2 source string" %}

From here, you'll be able to use the snippet like before.


💡Tip

Looking for more help? Get support from our Transifex Community Forum!

Find answers or post to get help from Transifex Support and our Community.

Did this answer your question?