Multi-Language Messaging

How to send messages in different languages with OneSignal.

You can send multi-language messages across all channels in OneSignal. Depending on the channel, there are different options available outlined here.

Set User's Language

The OneSignal SDK will automatically detect and set the user's Language property the first time based on the device settings. You can also override this property with the SDK or API.

SDK setLanguage Method

The Language property is set automatically by the OneSignal SDK based on the device settings when the subscription is created. You can override this by passing in the ISO 639-1 language code to the SDK setLanguage method.

Update User API

Update the User's language with the Update user endpoint using an ISO 639-1 language code.

request.body = "{\"properties\":{\"language\":\"fr\"}"

Self-Managed Language and Content (API only)

If you store / manage the language of your users outside of OneSignal, you can create already-translated versions of messages and send them individually to each customer. You can send a translated message through the Create notification endpoint.

API custom_data Property

Using Templatesand the Create notification endpoint, you can pass in the user's language via the custom_data parameter and reference it in the template via Liquid syntax. The below example shows how you can setup the template and pass the customer's custom_data language and conditionally check for the language using Liquid syntax.

{% if message.custom_data.language == "en" %}
  Hello, {{ first_name }}!
{% elsif message.custom_data.language == "fr" %}
  Bonjour {{ first_name }}!
{% else %}
  Hi, {{ first_name }}!
{% endif %}
request.body = "{\"custom_data\":{\"language\":\"fr\"}"
Bonjour George!

Push

Send push notifications in different languages using the options below. Variable substitution using properties and tags is also available. See Message Personalization for details on variable substitution.

Dashboard Sending

The OneSignal dashboard and API makes "English" the default language, but use any language you need in this field. Think of "English" as Default. For example, if you enter a Spanish message into the "Any/English" field, then all users will get the notification in Spanish.

To send a message in multiple languages, select Add Languages or Edit Language.

Add Languages to a Push Notification

Add Languages to a Push Notification

Edit Languages and Content for a Push Notification

Edit Languages and Content for a Push Notification

You must provide the translation for each message you want to include.

📘

Note on RTL languages like Arabic and Hebrew

The dashboard uses a very standard HTML text area form field for this input.

Certain punctuation and special characters like % are handled in a unique way and may require RLM marks after these characters to fix any issues you may see.

There are two methods for language selection:

  1. Checkboxes: Best for sending in 1-3 languages. Select the languages you want to use in the push. Any languages you do not select will get the "Any/English" message.
  1. Import Language Content: Best for populating the editor with 2+ or many languages. Fill out the template provided with content for each language, copy and paste the content back into the "Add Languages" pop-up, preview content to double check, insert content, and new tabs will appear in the editor with the designated content filled out.
Modal to copy and paste data from spreadsheet.

Modal to copy and paste data from spreadsheet.

Modal with example data.

Modal with example data.

Content preview.

Content preview.

Troubleshooting Language Uploader

Default language or English Required

When copying and pasting languages into the text field, English (which acts as default) must be included as a row in order to proceed.

Formatting Issue

If met with an error, ensure you've included the header properties as the first line (copy and paste from the template). Another common reason is if the contents are not formatted properly. Ensure there is a comma between each of the header properties ("language_code","title","subtitle","message").

Unsupported Languages

While we support many languages, there are some we don't support yet. If the language code is not included in the pop-up and CSV template, then this language is not supported. We recommend using the next best language and sending us a product request to our support team.

Google Sheets Extension

Google Sheets Extension allows you to store message templates as a spreadsheet to send the message directly from the Google sheet.

Follow the steps outlined in Google Sheets Extension to compose and send your message.

Spreadsheet

API

The API headings and contents properties both allow multiple language codes to be set. If a device is set to a language that is not present in the contents property, then the content in en will be used.

For example, if the receiving device's language is de and you send the notification with only en and fr language codes for contents and headings, the notification the device receives will use the values of contents and headings in the en language code.

// Devices with "de" language code will receive "en" for contents and headings 
// because "de" is not specified

{
  "contents": {"en": "English content", "fr": "French content"},
  "headings": {"en": "English heading", "fr": "French heading"}
}

Note: Make sure that you are including the same set of language codes for each field.

If the language code set in contents is not present in headings, then the title ("heading") will not display.

For example, if the receiving device's language is de and you send the notification with en, ru and de for contents, but send only en for headings, then the titles for that notification will not display for any device with a language code of de and ru.

// Devices with "de" & "ru" language code will not display headings
// because "de" & "ru" are not specified

{
  "contents": {"en": "English content", "ru": "Russian content", "de": "German content"},
  "headings": {"en": "English content"}
}

Email

To send multi-language Emails via the dashboard, you will need to choose one of the following approaches:

  • Use Segments with Language and send messages to each segment, or
  • Use property substitution with Liquid syntax to create conditional statements in a message

📘

Right-to-Left Text Support in Email

Because text alignment is set in the email styling, sending right-to-left text and left-to-right messages using the same template may be challenging to accomplish, though not impossible.

You might want to either rely on the the recipient's computer to manage right-to-left text display, segment users who need to receive right-to-left messages, or conditionally change the styling through custom HTML & CSS.

Dashboard - Segment Audience

To send a language-specific Email to each language you need to support:

  1. Create a Segment for each language.
  2. Create an Email template for each language.
  3. Send your Email for each language by selecting the Segment and template for that language.

Dashboard - Conditionally Check Language with Liquid

Use Liquid Syntax to add conditional logic in the body of a message to render content in several languages. You can use the language code {{ user.language }}, or set a Data Tag on the user to provide the language value.

When using an if/else statement for multi-language messages, always include your default language last in the final else statement.

For example, if you want to use English as your default language, use an if statement to check if the user's language matches all defined languages before defaulting to English. This template example will render into three languages depending on the recipient's language code or Data Tag for {{ language }}.

{% assign userLang = user.language %}
{% if userLang  == 'es' %}
  Hola {{ first_name }}!
{% elsif userLang  == 'fr' %}
  Bonjour {{ first_name }}!
{% else %}
  Hello {{ first_name }}!
{% endif %}

API

When calling the Create notification API endpoint, you can specify custom_data to use in Liquid syntax. You can use data added to the notification to show conditional multi-language content as demonstrated above in "Dashboard - Conditionally Check Language with Liquid".

Make sure to accurately reference the source of your data in your Liquid tags.

{% if message.custom_data.language == "fr" %}
  Bonjour {{ name }}
{% elsif message.custom_data.language == "en" %}
  Hola {{ name }}
{% else %}
  Hello {{ name }}
{% endif %}

{
  "app_id": "5eb5a37e-b458-11e3-ac11-000c2940e62c", 
  "template_id": "45d24a11-f739-4878-a15c-f32535547e90",
  "include_email_tokens": ["[email protected]", "[email protected]"],
  "custom_data": {
    "language": "fr",
    "cart_items": [
      {"item_name": "sweater", "img_url": "https://.."},
      {"item_name": "socks", "img_url": "https://.."}
    ]
  }
}
  
Bonjour George

In-App Messages

Send in-app messages in different languages using segments or tag variable substitution. If using tag variable substitution, you will need to set the language as a data tag. See Message Personalization for details on variable substitution.

Variable substitution using properties is coming soon. Reach out to [email protected] to request this feature.

Dashboard - Segment Audience

To send a language-specific In-App Message to each language you need to support:

  1. Create a Segment for each language.
  2. Create an In-App Message for each language.
  3. Send your In-App Message for each language by selecting the Segment for that language.

Tag Variable Substitution

In this example, we set the tag key language to a specific language like german, spanish, french and default to English with if-else statements Using Liquid Syntax.

{% if language == "spanish" %}
  ¡Buenos días {{ first_name}}!
{% elsif language == "german" %}
  Guten Tag {{ first_name }}!
{% elsif language == "french" %}
  Bonne journée {{ first_name }}!
{% else %}
  Good day, {{ first_name }}!
{% endif %}
language : german
first_name : Jon
Guten Tag Jon!

Supported Languages

When Sending Push Notifications you can add the following languages.

LanguageLanguage Code
Englishen
Arabicar
Azerbaijaniaz
Bosnianbs
Catalanca
Chinese (Simplified)zh-Hans
Chinese (Traditional)zh-Hant
Croatianhr
Czechcs
Danishda
Dutchnl
Estonianet
Finnishfi
Frenchfr
Georgianka
Bulgarianbg
Germande
Greekel
Hindihi
Hebrewhe
Hungarianhu
Indonesianid
Italianit
Japaneseja
Koreanko
Latvianlv
Lithuanianlt
Malayms
Norwegiannb
Persianfa
Polishpl
Portuguesept
Punjabipa
Romanianro
Russianru
Serbiansr
Slovaksk
Spanishes
Swedishsv
Thaith
Turkishtr
Ukrainianuk
Vietnamesevi