-
Notifications
You must be signed in to change notification settings - Fork 79
Internalization: Add your local language #57
Description
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
-
Get your supported
YOUR_LANGUAGE_CODEhere -
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'.....'
}
]
}- 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
- 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/- Extract all the text in the chatbot
(venv) $ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot .- 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>-
Add your translation manually or by using software like poedit
got to the newly generated file and start i18n process. you can get inspired fromsrc/locales/fr/LC_MESSAGES/messages.po -
Compile .po file to .mo
Compile your .po translation file by doing:
pybabel compile -d locales- 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
- Extract all the text in the chatbot
(venv) $ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot .- Update the message.po files
(venv) $ pybabel update -i locales/messages.pot -d locales- 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
- how to compile your new translation
(venv) $ pybabel compile -d locales- 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