Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Internalization: Add your local language #57

@aboullaite

Description

@aboullaite

Is your feature request related to a problem? Please describe.

For more information about the translation process look at the official Flask-Babel documentation

By default, the bot interact with users with English. We can customize the user experience by adding support for i18n. If you're interested in adding support for a language, please follow the steps below:

Translate Greeting and Persistant Menu

  1. Get your supported YOUR_LANGUAGE_CODE here

  2. In the file profile.py add a new object related to your language in GREETINGS

GREETING = {
    "greeting": [
        {
            "locale": "default",
            "text": u'🙋🏽 Hi {{user_first_name}}! Click on the Get Started'
            ' button bellow to access Facebook DevC curated resources related'
            ' to Open Source 🔓.'
        },
        ...
        {
            "locale": "YOUR_LANGUAGE_CODE",
            "text": u'.....'
        }
    ]
}
  1. then add a new entry for PERSISTENT_MENU
PERSISTENT_MENU = {
    "persistent_menu": [
        {
            "locale": "default",
            "composer_input_disabled": False,
            "call_to_actions": [
                {
                    "type": "postback",
                    "title": "🏁 Start Over",
                    "payload": "START"
                },
                {
                    "type": "postback",
                    "title": "🗄️ Main Menu",
                    "payload": "MAIN_MENU"
                },
                {
                    "type": "postback",
                    "title": "🔓 FB Open Source",
                    "payload": "FB_OS"
                }
            ]
        },
       ...
        {
            "locale": "YOUR_LANGUAGE_CODE",
            "composer_input_disabled": False,
            "call_to_actions": [
                {
                    "type": "postback",
                    "title": " 🏁 ....",
                    "payload": "START"
                },
                {
                    "type": "postback",
                    "title": "🗄️ ....",
                    "payload": "MAIN_MENU"
                },
                {
                    "type": "postback",
                    "title": "🔓 ....",
                    "payload": "FB_OS"
                }
            ]
        }
    ]
}

Update GREETINGS and PERSISTENT_MENU

For that use cURL like this

(venv) $ curl -X GET "<YOUR HOST>/webhook?hub.verify_token=<YOUR VERIFY TOKEN>&hub.challenge=CHALLENGE_ACCEPTED&hub.mode=subscribe&init_bot=true"

after that check the logs to see if all the request return success

Adding a new language

  1. Determine the language code

The ISO 639-1 standard defines two-letter codes for languages. Find the two-letter codes of the language you want to add here.

Make sure your language is not already supported

(venv) $ ls src/locales/
  1. Extract all the text in the chatbot
(venv) $ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot .
  1. Create .po file for your language (One-time only)
    .po translation files are generated from .pot template files using pybabel init.
(venv) $ pybabel init -i locales/messages.pot -d locales -l <LANGUAGE_CODE>
  1. Add your translation manually or by using software like poedit
    got to the newly generated file and start i18n process. you can get inspired from src/locales/fr/LC_MESSAGES/messages.po

  2. Compile .po file to .mo
    Compile your .po translation file by doing:

pybabel compile -d locales
  1. Verify
    Make sure your Facebook account develop language is set to <LANGAUGE_CODE>. Run the app in your test environment, and verify that the bot answers you in your selected language

Updating an existing language

After a change in the code that affect the text, you have to do this process

  1. Extract all the text in the chatbot
(venv) $ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot .
  1. Update the message.po files
(venv) $ pybabel update -i locales/messages.pot -d locales
  1. Add your translation manually or by using software like poedit

After this you will have to translate the ../src/locales/<LANGUAGE_CODE>/LC_MESSAGES/messages.po

  1. how to compile your new translation
(venv) $ pybabel compile -d locales
  1. Verify
    Make sure your Facebook account develop language is set to <LANGAUGE_CODE>. Run the app in your test environment, and verify that the bot answers you in your selected language

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions