Repository navigation
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
Activity
ChiragTutlani commentedon Jul 29, 2020
I will take up of translating it to hindi (ISO 639-1 code: hi).
aboullaite commentedon Jul 29, 2020
Awesome @ChiragTutlani 🎉 please do not hesitate to reach oit if you need any assistance 👌
elinguiuriel commentedon Jul 29, 2020
@ChiragTutlani I made an update to describe how to translate
GREETINGSandPERSISTANT_MENUtake a look hereprilcool commentedon Aug 2, 2020
I added Simplified Chinese (zh-Hans) work in progress in the locales folder ,
Welcome to do a pull and continue translation while i'm asleep lol :)
SrilalS commentedon Aug 2, 2020
Hi! I Would like to Take Translation to Sinhala (Code: si).
vj-codes commentedon Aug 2, 2020
I would like to add German (code:de) translation!
elinguiuriel commentedon Aug 2, 2020
Are you a chinesse speaker ? Please only add a language if you are a native speaker.
elinguiuriel commentedon Aug 2, 2020
Are you a german speaker or do you know a good german speaker willing to help you ?
elinguiuriel commentedon Aug 2, 2020
Great, first make sure the langage is supporter https://developers.facebook.com/docs/messenger-platform/messenger-profile/supported-locales
are you a native speaker or that language, or Can you have help from a native speaker ?
aboullaite commentedon Aug 2, 2020
@elinguiuriel being a native speaker is not necessary IMHO! Anyone who can correctly translate the messages is welcomed to open a PR as far is he's capable of completing it! Anyone who find issues on translation can submit improvements afterwards
vj-codes commentedon Aug 2, 2020
I'm a speaker , I know german as an additional language.If required I can ask a native speaker for PR review too. @elinguiuriel
SrilalS commentedon Aug 2, 2020
@aboullaite I Began the translation process for the Sinhala (Si). I have one question. there are some English words that have native words but those are less used and not understood by General Public. Should I made the translations in Pure Sinhala or Can I do it in Modern Sinhala?
SrilalS commentedon Aug 2, 2020
I'm a Native Speaker.
Edit : Sinhala Is Supported.
5 remaining items
Yannix commentedon Aug 2, 2020
French translation working for the menu but not working inside the bot. Seems that the translation process not applied while in the chat.
elinguiuriel commentedon Aug 2, 2020
I suspect that your Facebook language is not "Français (France)" or any other version or french, and your phone is localized in french. Make sure you have french everywhere
prilcool commentedon Aug 4, 2020
This is not all or nothing situation .
You can control the quality of what's being merged into the production branch .
You should accept submissions on the development branch
Than next invite the Global Devc community to vet and correct the translations and have a vote on it , after all thats what the Devc Community is about .
I believe that would be a formal ,fun and democratic way of doing things.
elinguiuriel commentedon Aug 4, 2020
@prilcool you have a great point here! Please feel free to translate any language you are fluent in. The translation is a small part of the project, and it is not the easiest, it's quite a time-consuming and error-prone. Because we are a large global community as you said, what do you think about letting such specialized tasks to people most able to understand their translation even if they use Google Translate as a helper?
Google Translate gives a good result, but some texts in the app are challenging and informal, and some word must be kept in English. These precautions are taken to avoid wasting contributor's precious time and the frustration of doing work that will not be merged or will required too many corrections. It is easier to do it at the beginning than when the work is already started. But if you or anyone are confident about translating a language, please go ahead! Or we will rather redirect contributors to quick wins amongst issues
aboullaite commentedon Aug 4, 2020
@prilcool if you read carefully the discussion here, you should mention that exactly what I was advocating for and what we agreed to do from now on. Relying solely on GT for translating to other languages will generate a negative experience as mentioned by @elinguiuriel
prilcool commentedon Aug 4, 2020
@aboullaite @elinguiuriel Ah i see now, after testing with other language apart from Chinese, for some language gt translate is not so good and funny ok we leave translation to native speakers .
Emile-Nsengimana commentedon Aug 7, 2020
I would like to add Kinyarwanda (code:rw) translation!
ashish11chawda commentedon Aug 14, 2020
I would like to translate it to Gujarati (India)
ISO 639-1 code: guLuisFerTR commentedon Aug 20, 2020
Hi, I would like to add spanish (code: es) translation!
elinguiuriel commentedon Aug 20, 2020
@LuisFerTR please yourself 👍
shah78677 commentedon Oct 6, 2020
I would like to add Urdu language. ur_PK
stonefix commentedon Jan 22, 2021
Hi! I am a native Russian speaker and I would like to add Russian language.
elinguiuriel commentedon Jan 22, 2021
Please yourself @stonefix the russian code is
ru_RUaccording to thisshubhankarsharma876 commentedon Jan 17, 2022
I will add Kannada (INDIA) transcript with code
kn_INaccording to thisshubhankarsharma876 commentedon Jan 18, 2022
I ran this code [ (venv) $ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot .] in my git but showed the below error.
Please provide me some fixes: I installed the anaconda and python 3.10.2 properly with the path. But still getting this error
$ pybabel extract -F babel.cfg -k lazy_gettext -o locales/messages.pot . Traceback (most recent call last):
File "C:\Users\shubh\anaconda3\Scripts\pybabel-script.py", line 9, in
sys.exit(main())
File "C:\Users\shubh\anaconda3\lib\site-packages\babel\messages\frontend.py", line 929, in main
return CommandLineInterface().run(sys.argv)
File "C:\Users\shubh\anaconda3\lib\site-packages\babel\messages\frontend.py", line 853, in run
return cmdinst.run()
File "C:\Users\shubh\anaconda3\lib\site-packages\babel\messages\frontend.py", line 438, in run
mappings = self._get_mappings()
File "C:\Users\shubh\anaconda3\lib\site-packages\babel\messages\frontend.py", line 502, in _get_mappings
with open(self.mapping_file, po_file_read_mode) as fileobj:
FileNotFoundError: [Errno 2] No such file or directory: 'babel.cfg'