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

Internalization: Add your local language #57

Open
aboullaite opened this issue Jul 28, 2020 · 33 comments
Open

Internalization: Add your local language #57

aboullaite opened this issue Jul 28, 2020 · 33 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@aboullaite
Copy link
Contributor

aboullaite commented Jul 28, 2020

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
@aboullaite aboullaite added enhancement New feature or request good first issue Good for newcomers labels Jul 28, 2020
@ChiragTutlani
Copy link
Contributor

I will take up of translating it to hindi (ISO 639-1 code: hi).

@aboullaite
Copy link
Contributor Author

Awesome @ChiragTutlani 🎉 please do not hesitate to reach oit if you need any assistance 👌

@elinguiuriel
Copy link
Contributor

elinguiuriel commented Jul 29, 2020

@ChiragTutlani I made an update to describe how to translate GREETINGS and PERSISTANT_MENU take a look here

@prilcool
Copy link
Contributor

prilcool commented 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
Copy link
Contributor

SrilalS commented Aug 2, 2020

Hi! I Would like to Take Translation to Sinhala (Code: si).

@vj-codes
Copy link
Contributor

vj-codes commented Aug 2, 2020

I would like to add German (code:de) translation!

@elinguiuriel
Copy link
Contributor

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 :)

Are you a chinesse speaker ? Please only add a language if you are a native speaker.

@elinguiuriel
Copy link
Contributor

elinguiuriel commented Aug 2, 2020

I would like to add German (code:de) translation!

Are you a german speaker or do you know a good german speaker willing to help you ?

@elinguiuriel
Copy link
Contributor

Hi! I Would like to Take Translation to Sinhala (Code: si).

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
Copy link
Contributor Author

@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
Copy link
Contributor

vj-codes commented Aug 2, 2020

I would like to add German (code:de) translation!

Are you a german speaker or do you know a good german speaker willing to help you ?

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
Copy link
Contributor

SrilalS commented 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
Copy link
Contributor

SrilalS commented Aug 2, 2020

Hi! I Would like to Take Translation to Sinhala (Code: si).

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 ?

I'm a Native Speaker.
Edit : Sinhala Is Supported.

@aboullaite
Copy link
Contributor Author

@vj-codes please continue your amazing work 🙏
@SrilalS the goal is to be understandable, easy to use and help users. I think modern Sinhala is better base on what you described

@elinguiuriel
Copy link
Contributor

@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

Just we have to make sure to not sacrifice on quality when pushing translation in production. Because we have no way of controling translation quality ! If someone is not fluent enough in a language I prefer that his translation should be validate by a fluent speakers before being merged.

@elinguiuriel
Copy link
Contributor

I would like to add German (code:de) translation!

Are you a german speaker or do you know a good german speaker willing to help you ?

I'm a speaker , I know german as an additional language.If required I can ask a native speaker for PR review too. @elinguiuriel

I am a german speaker too, but a very bad speaker. If you can find someone fluent to validate the first version, it will be great.
I ask this question because it is a lot of work, there is a lot of content in the app and being fluent help a lot.

@aboullaite
Copy link
Contributor Author

@elinguiurie, faor enough,l we could require review from devc community before merging! But bring a native speaker should not be the only criteria to suggest a PR 👍

@elinguiuriel
Copy link
Contributor

elinguiuriel commented Aug 2, 2020

@elinguiurie, faor enough,l we could require review from devc community before merging! But bring a native speaker should not be the only criteria to suggest a PR 👍

Fluent or Native Speaker. Flask-Babel can refuse bad translation, that is what I want to avoid!

@Yannix
Copy link

Yannix commented Aug 2, 2020

@ChiragTutlani I made an update to describe how to translate GREETINGS and PERSISTANT_MENU take a look here

French translation working for the menu but not working inside the bot. Seems that the translation process not applied while in the chat.

@elinguiuriel
Copy link
Contributor

elinguiuriel commented Aug 2, 2020

@ChiragTutlani I made an update to describe how to translate GREETINGS and PERSISTANT_MENU take a look here

French translation working for the menu but not working inside the bot. Seems that the translation process not applied while in the chat.

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

Screenshot_20200802-182652_Messenger.jpg

@prilcool
Copy link
Contributor

prilcool commented Aug 4, 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

Just we have to make sure to not sacrifice on quality when pushing translation in production. Because we have no way of controling translation quality ! If someone is not fluent enough in a language I prefer that his translation should be validate by a fluent speakers before being merged.

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
Copy link
Contributor

elinguiuriel commented Aug 4, 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

Just we have to make sure to not sacrifice on quality when pushing translation in production. Because we have no way of controling translation quality ! If someone is not fluent enough in a language I prefer that his translation should be validate by a fluent speakers before being merged.

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.

@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
Copy link
Contributor Author

@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
Copy link
Contributor

prilcool commented 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
Copy link
Contributor

I would like to add Kinyarwanda (code:rw) translation!

@ashish11chawda
Copy link
Contributor

I would like to translate it to Gujarati (India) ISO 639-1 code: gu

@LuisFerTR
Copy link

Hi, I would like to add spanish (code: es) translation!

@elinguiuriel
Copy link
Contributor

Hi, I would like to add spanish (code: es) translation!

@LuisFerTR please yourself 👍

@shah78677
Copy link
Contributor

I would like to add Urdu language. ur_PK

@stonefix
Copy link
Contributor

Hi! I am a native Russian speaker and I would like to add Russian language.

@elinguiuriel
Copy link
Contributor

Hi! I am a native Russian speaker and I would like to add Russian language.

Please yourself @stonefix the russian code is ru_RU according to this

@shubhankarsharma876
Copy link

I will add Kannada (INDIA) transcript with code kn_IN according to this

@shubhankarsharma876
Copy link

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'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests