{"id":19617628,"url":"https://github.com/macagua/python_i18n_babel_jinja2","last_synced_at":"2026-04-19T05:34:29.453Z","repository":{"id":137264622,"uuid":"129997897","full_name":"macagua/python_i18n_babel_jinja2","owner":"macagua","description":"i18n Python Web Application by Babel and Jinja2","archived":false,"fork":false,"pushed_at":"2018-04-18T15:00:43.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T18:17:22.807Z","etag":null,"topics":["babel","i18n","jinja2","python","webapp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/macagua.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-18T03:21:07.000Z","updated_at":"2022-03-06T20:31:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"71699701-5cf4-4df4-87fc-ac396c2cb1e2","html_url":"https://github.com/macagua/python_i18n_babel_jinja2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/macagua/python_i18n_babel_jinja2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macagua%2Fpython_i18n_babel_jinja2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macagua%2Fpython_i18n_babel_jinja2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macagua%2Fpython_i18n_babel_jinja2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macagua%2Fpython_i18n_babel_jinja2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macagua","download_url":"https://codeload.github.com/macagua/python_i18n_babel_jinja2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macagua%2Fpython_i18n_babel_jinja2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000781,"owners_count":26082906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","i18n","jinja2","python","webapp"],"created_at":"2024-11-11T11:04:59.420Z","updated_at":"2025-10-09T02:21:25.826Z","avatar_url":"https://github.com/macagua.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"i18n Python Web Application by Babel and Jinja2\n===============================================\n\nHow to enable i18n support for Python Web Application using Babel and Jinja2.\n\n\nDownload\n--------\n\nFor download the source code, please execute the follow command:\n\n.. code:: bash\n\n    $ git clone https://github.com/macagua/python_i18n_babel_jinja2.git\n    $ cd python_i18n_babel_jinja2\n\nInstallation\n------------\n\nFor install the source code, please execute the following commands:\n\n.. code:: bash\n\n    $ virtualenv .\n    $ source ./bin/activate\n    $ pip install -r requirements.txt --timeout 120\n\nAt the moment just compile message catalogs to MO files for finish the installation,\nexecuting the following command:\n\n.. code:: bash\n\n    $ pybabel compile -f -d ./locale\n    compiling catalog ./locale/pt_BR/LC_MESSAGES/messages.po to ./locale/pt_BR/LC_MESSAGES/messages.mo\n    compiling catalog ./locale/en/LC_MESSAGES/messages.po to ./locale/en/LC_MESSAGES/messages.mo\n    compiling catalog ./locale/es/LC_MESSAGES/messages.po to ./locale/es/LC_MESSAGES/messages.mo\n\nConfiguration\n=============\n\nFor enable the *Internationalization and Localization* for this Sphinx Theme, you will need checkout \nthe following configurations:\n\nTranslations files\n------------------\n\nThe translations files are based on ``gettext`` format and they are placed at the \n``python_i18n_babel_jinja2/locale/`` directory, like it showing the following structure:\n\n.. code:: bash\n\n    python_i18n_babel_jinja2/locale/\n    ├── en\n    │   └── LC_MESSAGES\n    │       ├── messages.mo\n    │       └── messages.po\n    ├── es\n    │   └── LC_MESSAGES\n    │       ├── messages.mo\n    │       └── messages.po\n    ├── pt_BR\n    │   └── LC_MESSAGES\n    │       ├── messages.mo\n    │       └── messages.po\n    ├── babel.cfg\n    └── messages.pot\n\n``python_i18n_babel_jinja2/locale/\u003cLANG\u003e/LC_MESSAGES/``\n    This folder contains a specific language is the **Gettext format**.\n\n``babel.cfg``\n    This file is the **babel** configurations.\n\n``messages.pot``\n    This file is the **Portable Object Template** Gettext format.\n\n``messages.po``\n    This file is the **Portable Object** Gettext format to translate.\n\n``messages.mo``\n    This file is the **Machine Object** Gettext format generated later of translate \n    your ``messages.po`` file via the catalog compilation.\n\nBabel extraction configurations\n-------------------------------\n\nFirst of all you have to get into the folder where you have your project and create a mapping file \ncalled ``babel.cfg`` into ``python_i18n_babel_jinja2/locale/`` directory that contains the \n**extraction from Jinja2 HTML templates** configurations. For typical Sphinx extensions, this is what \nyou want in there:\n\n.. code:: cfg\n\n    # Extraction from Jinja2 HTML templates\n    [jinja2: **/**.html]\n    encoding = utf-8\n    ignore_tags = script,style\n    include_attrs = alt title summary placeholder\n\n\n.. note::\n\n    More details check out the following links:\n\n    - `How setup this file \u003chttp://babel.pocoo.org/en/latest/setup.html\u003e`_\n    - `A previous file example description \u003chttp://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration\u003e`_\n\nWeb Application\n===============\n\nThe struture directory for the Web Application is like the following:\n\n``view/index.html``\n    This is a HTML template based jinja2 engine.\n\n``demo.py``\n    This Python module is a Gettext demostration application.\n\n``i18n.py``\n    This Python module is an app for find out and print all supported languages available \n    in ``locale`` directory.\n\n``jj2.py``\n    This Python module is the main application.\n\nLocales Python script\n---------------------\n\nFor running the a Python script called ``i18n.py``, for show the languages available \nexecuting the following command:\n\n.. code:: bash\n\n    $ python ./i18n.py\n    pt_BR\n    en\n    es\n\nRunning Python script\n---------------------\n\nFor running the Python script called ``demo.py``, execute the following command:\n\n.. code:: bash\n\n    $ python ./demo.py \n    Home\n    Canon\n    About\n    Setting\n    Translation\n\n    -----\n\n    Inicio\n    Canon\n    Acerca de\n    Configuración\n    Traducción\n\n    -----\n\n    Home\n    Canon\n    Sobre\n    Configuração\n    Tradução\n\n.. note::\n\n    You can notice that the script prints by console each messages in each supported\n    translated language, in this case *English*, *Spanish* and *Brazilian Portuguese*.\n\nRunning Web Application script\n------------------------------\n\nFor running the Python Web Application script called ``jj2.py``, execute the following command:\n\n.. code:: bash\n\n    $ python ./jj2.py\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n        \u003chead\u003e\n            \u003ctitle\u003ei18n Python Web Application by Babel and Jinja2\u003c/title\u003e\n        \u003c/head\u003e\n        \u003cbody\u003e\n            \u003cdiv\u003eHome\u003c/div\u003e\n            \u003cdiv\u003eNews\u003c/div\u003e\n            \u003cdiv\u003eAbout\u003c/div\u003e\n            \u003cdiv\u003eSetting\u003c/div\u003e\n            \u003cdiv\u003eTranslation\u003c/div\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n\n    -----\n\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n        \u003chead\u003e\n            \u003ctitle\u003eInternacionalización y localización de Aplicación Web Python con Babel y Jinja2\u003c/title\u003e\n        \u003c/head\u003e\n        \u003cbody\u003e\n            \u003cdiv\u003eInicio\u003c/div\u003e\n            \u003cdiv\u003eNoticias\u003c/div\u003e\n            \u003cdiv\u003eAcerca de\u003c/div\u003e\n            \u003cdiv\u003eConfiguración\u003c/div\u003e\n            \u003cdiv\u003eTraducción\u003c/div\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n\n    -----\n\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n        \u003chead\u003e\n            \u003ctitle\u003eInternacionalização e Localização do aplicativo da Web em Python por Babel e Jinja2\u003c/title\u003e\n        \u003c/head\u003e\n        \u003cbody\u003e\n            \u003cdiv\u003eHome\u003c/div\u003e\n            \u003cdiv\u003eNotícia\u003c/div\u003e\n            \u003cdiv\u003eSobre\u003c/div\u003e\n            \u003cdiv\u003eConfiguração\u003c/div\u003e\n            \u003cdiv\u003eTradução\u003c/div\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n\n\n.. note::\n\n    You can notice that the script prints by console each HTML templates in each\n    supported translated language, in this case *English*, *Spanish* and *Brazilian Portuguese*.\n\nWorking with Babel\n------------------\n\nIf the command has been correctly installed ``babel`` package, a command should allow you to use \nthe following command:\n\n.. code:: bash\n\n    $ pybabel subcommand options\n\nExecute the follow command for more options and follow these instructions to get details:\n\n.. code:: bash\n\n    $  pybabel --help\n    Usage: pybabel command [options] [args]\n\n    Options:\n      --version       show program's version number and exit\n      -h, --help      show this help message and exit\n      --list-locales  print all known locales and exit\n      -v, --verbose   print as much as possible\n      -q, --quiet     print as little as possible\n\n    commands:\n      compile  compile message catalogs to MO files\n      extract  extract messages from source files and generate a POT file\n      init     create new message catalogs from a POT file\n      update   update existing message catalogs from a POT file\n\nIf you need extract new string to translate from the source code, execute the following command:\n\n.. code:: bash\n\n    $ pybabel extract -F ./locale/babel.cfg -o ./locale/messages.pot .\n\nIf you need initialize new language to translate from the POT file, execute the following command:\n\n.. code:: bash\n\n    $ pybabel init -l \u003cLANG\u003e -i ./locale/messages.pot -o ./locale/\u003cLANG\u003e/LC_MESSAGES/messages.po\n\nIf you update the new language or a language existing to translate from the POT file to PO file, execute the following command:\n\n.. code:: bash\n\n    $ pybabel update -l \u003cLANG\u003e -d ./locale -i ./locale/messages.pot\n\nIf you need compile compile message catalogs to binary MO files, execute the following command:\n\n.. code:: bash\n\n    $ pybabel compile -f -d ./locale\n\nReferences\n----------\n\n- `i18n Python Web Application by gettext and Jinja2 \u003chttps://siongui.github.io/2016/01/17/i18n-python-web-application-by-gettext-jinja2/\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacagua%2Fpython_i18n_babel_jinja2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacagua%2Fpython_i18n_babel_jinja2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacagua%2Fpython_i18n_babel_jinja2/lists"}