Setup your Multilingual Email templates and User-Facing pages

Irena Russeva

Multilingual communication is a powerful tool, whether you want to become an insider in another culture market or create higher value and be more efficient in your business. Therefore in order to successfully speak to the world without losing the true meaning behind your message, it is important to do it in the languages most familiar to your audience. For that reason, we decided to expand your options and get you to the next level. Now with SashiDo, you have the opportunity to send multilingual emails and multilingual user-facing pages to your users.

Setup the Multilingual Email Templates

1. Configure Users Locale

If you wish to address your customers in their own language, first you need to add a column named localeIdentifier to your application’s User class in the DB Browser. The localeIdentifier field should be of type String. In this column, you will add the respective language for communication to the current user. To minimize the chance of mistakes we decided to use a primary sub-code that identifies the language (e.g., "en"), and a sub-code in capital letters that specifies the national variety (e.g., "GB" or "US" according to ISO 3166-2). The sub-codes should be linked with a hyphen(eg. en-GB). Implementing the logic how you will collect this data is up to you :) If the field is empty or contains invalid language, the default templates will be sent to this user.

add-localeIdentifier--2-

2. Manage multilingual Email Templates

To manage your multilingual email templates, you should go to the Dashboard -> Your App -> App Settings -> Emails & Hosting. At the Email Templates section, you now have the option to choose Country and Language and Add template. Hereafter choosing Country and language, please pay attention to the code displayed in the Locale field, as this is how the selected language should be entered in the localeIdentifier field. Later on, the same code should be used again when you set the user-facing pages.

MMT_locale-1

As soon as you press the add button Email templates for verification and password reset are created and opened for you to customize. Just change the text by your preferences, to give your users the best experience and press Save changes button in the lower right corner.

MM-Add-final-1

You can edit each template's text whenever you wish, from the Manage button. Just remember to press the Save changes after you finish editing.

To delete a certain template, also first you need to go to Manage -> Delete these templates -> Save changes.

Delete-final-1

Another great feature we find of use is the ability to choose the default language for your customers. Deciding which will be the default language is of great importance since if there no valid entry in the localeIdentifier field, the default email template will be sent. Therefore you need to choose wisely :) The default language is of note regarding the User-Facing pages too, but we will get to that later.

You can simply select the default language from the slide bar in the Default field before each language. Again press Save changes and it is set!

default-1

Setup the Multilingual User-Facing Pages

Well, multilingual email templates are a great feature, but probably you want the page that displays next to be also in your customer's language. Don't worry, we now support Multilingual User-Facing Pages too!

We know dealing with new features may be at times challenging and I will try to simplify the process for you.

1. Start with Cloud Code

As you know, the multilingual email templates that you configured earlier for your users contain some link to a respective page. Basically, there are four essential pages, that the emailed link can lead to: Successful verification, Choose password, Successfully changed password, and of course Invalid link.

Each of these four pages can be presented in your customers' language. All you have to do is write the desired HTML and CSS files in your GitHub repo. And of course, few lines of cloud code logic should be implemented in the Advanced Cloud Code.

Here I am offering a sample code, which you can put in the app.js file of your cloud code.

const path = require('path');

/**
 * Folder structure
 * public/
 * ├── pages/
 * │   ├── choose_password.html // default 
 * │   └── en-US/
 * │       └── choose_password.html // en-US template
 */

function getUserFacingTemplate(templateName) {
    return async (req, res) => {
        const { username } = req.query;

        const user = await new Parse.Query(Parse.User)
            .equalTo(‘username’, username)
            .first(
                { useMasterKey: true }
            );
        
        if (!user) {
            throw new Error('unauthorized');
        }

        let templatePath = path.join(__dirname, '../public/pages/');
        const locale = user.get('localeIdentifier');
        
        if (locale) {
            templatePath += locale + '/';
        }
        
        templatePath += templateName;

        return res.sendFile(templatePath);
    }
}

app.get(
    '/localized-choose-password',
    getUserFacingTemplate('choose_password.html')
);
app.get(
    '/localized-password-changed',
    getUserFacingTemplate('password_reset_success.html')
);
app.get(
    '/localized-email-verified',
    getUserFacingTemplate('email_verification.html')
);

2. Continue with User-Facing Templates

Have in mind that the folder structure is of great importance!

Invalid_link

Here I can offer some guidance on how to add your User Facing Templates to your cloud code:

In the public directory in your cloud code repo, you will need to create a new folder, named pages.
Then in pages create a separate folder for each different language you would like to use. Every folder should be named as the value of the locale field in the multilingual email section in your application’s Dashboard. These folders will hold all the HTML and CSS files for the respective language. You can even have different CSS for each language if you wish.
With this folder structure, the user-facing pages for the default language should be placed right into the pages folder. Therefore if the content of the localeIdentifier field is unidentified or different from the languages you chose for communication, the default templates will be sent.

If you haven't had the chance to look at our previous tutorial on the topic, you can check it out here.

3. Finalize by configuring Localized User-Facing pages in SashiDo’s Dashboard

Last, but not least is telling SashiDo you want to render the localized User-facing pages. For that just go one more time to the App Settings -> Emails & Hosting. There in the User-Facing Pages section add the path for the localized templates as shown below. Actually, these will be the routes you defined earlier in the cloud code, with Express.js.

localized-MUFP

I believe that's all you need to know to get started with multilingual emails and user-facing pages. And I am sure that the users will appreciate such distinctive communication.

That’s it, you are all set now :)

Happy coding!

Irena Russeva

Customer Success Superstar @ SashiDo.

Find answers to all your questions

Our Frequently Asked Questions section is here to help.







Latests news

How to make your Mobile Application GDPR Ready

At SashiDo we certainly care about our customers and we strive to be up-to-date on the horizon of the novelties coming up. We’re all working on GDPR these days and we want to help people understand what it is. What does GDPR mean? In February we announced that GDPR is coming and SashiDo.io is getting ready and now we will be more specific on how to make sure your mobile app is prepared for the upcoming changes in the European Union region.

Read More

SashiDo Acquires Octobas

SashiDo is pleased to announce its recent acquisition of all the assets of Octobas.com, a robust and scalable backend for mobile and web apps based on Parse Open Source. For the past 2 years our mission has been to become a leading Parse Server hosting provider in the mobile and web apps development world as well as to continue improving our service, launching new features and providing quality and security to our customers.

Read More