{"id":16391498,"url":"https://github.com/rclement/flask-language","last_synced_at":"2025-03-23T04:31:42.683Z","repository":{"id":50214042,"uuid":"124261701","full_name":"rclement/flask-language","owner":"rclement","description":"Flask extension handling client-side language cookie","archived":false,"fork":false,"pushed_at":"2022-12-08T00:50:44.000Z","size":58,"stargazers_count":2,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:51:37.412Z","etag":null,"topics":["cookie","flask","flask-extension","language","python","web"],"latest_commit_sha":null,"homepage":"https://flask-language.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rclement.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T16:14:33.000Z","updated_at":"2020-02-01T18:01:04.000Z","dependencies_parsed_at":"2023-01-24T01:25:12.601Z","dependency_job_id":null,"html_url":"https://github.com/rclement/flask-language","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rclement%2Fflask-language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rclement%2Fflask-language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rclement%2Fflask-language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rclement%2Fflask-language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rclement","download_url":"https://codeload.github.com/rclement/flask-language/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245056889,"owners_count":20553855,"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","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":["cookie","flask","flask-extension","language","python","web"],"created_at":"2024-10-11T04:46:26.076Z","updated_at":"2025-03-23T04:31:42.338Z","avatar_url":"https://github.com/rclement.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Flask-Language\n==============\n\n|PyPI Version| |PyPI License| |PyPI Versions| |Build Status| |Coverage\nStatus| |Documentation Status|\n\nFlask-Language is a Flask_ extension providing a\nsimple mechanism to handle a client-side language cookie.\n\nIt is somewhat loosely based on this snippet: `\u003chttp://flask.pocoo.org/snippets/128\u003e`__\n\n.. _Flask: http://flask.pocoo.org\n\nInstallation\n------------\n\nInstall the extension with with pipenv_ (recommended):\n\n::\n\n    $ pipenv install flask-language\n\nOr with pip_:\n\n::\n\n    $ pip install flask-language\n\n.. _pip: https://pip.pypa.io\n.. _pipenv: https://docs.pipenv.org\n\nUsage\n-----\n\nInitialize the Flask-Language extension (also compatible with the `Application Factories`_ pattern):\n\n::\n\n        from flask import Flask, jsonify\n        from flask_language import Language, current_language\n\n        app = Flask(__name__)\n        lang = Language(app)\n\nDefine the language hooks:\n\n::\n\n        @lang.allowed_languages\n        def get_allowed_languages():\n            return ['en', 'fr']\n\n        @lang.default_language\n        def get_default_language():\n            return 'en'\n\nDefine the desired end-points to retrieve and manipulate the current language:\n\n::\n\n        @app.route('/api/language')\n        def get_language():\n            return jsonify({\n                'language': str(current_language),\n            })\n\n        @app.route('/api/language', methods=['POST'])\n        def set_language():\n            req = request.get_json()\n            language = req.get('language', None)\n\n            lang.change_language(language)\n\n            return jsonify({\n                'language': str(current_language),\n            })\n\nBefore each request, Flask-Language will automatically determine the current\nlanguage in the following order:\n\n1. The language cookie (if any and matching the allowed languages)\n2. The ``Accept-Language`` HTTP header (if any and matching the allowed languages)\n3. The provided default language\n\nDuring each request context, the current language can be accessed using\n``current_language``.\n\nAfter each request, the current language will be stored in the language cookie.\n\n.. _Application Factories: http://flask.pocoo.org/docs/0.12/patterns/appfactories/\n\nConfiguration\n-------------\n\nFlask-Language is configurable via the following configuration variables:\n\n- ``LANGUAGE_COOKIE_NAME``: name for the cookie language (default: ``'lang'``)\n- ``LANGUAGE_COOKIE_TIMEOUT``: validity duration of the cookie language (default: ``datetime.timedelta(days=365)``)\n- ``LANGUAGE_COOKIE_DOMAIN``: domain for the cookie language (default: ``None``)\n- ``LANGUAGE_COOKIE_SECURE``: set secure option for the cookie language (default: ``False``)\n- ``LANGUAGE_COOKIE_HTTPONLY``: set HTTP-only for the cookie language (default: ``False``)\n\nDocumentation\n-------------\n\nThe Sphinx-compiled documentation is available on\n`ReadTheDocs \u003chttp://flask-language.readthedocs.io/en/latest/\u003e`__.\n\nLicense\n-------\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 Romain Clement\n\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/flask-language.svg\n   :target: https://pypi.python.org/pypi/flask-language\n.. |PyPI License| image:: https://img.shields.io/pypi/l/flask-language.svg\n   :target: https://pypi.python.org/pypi/flask-language\n.. |PyPI Versions| image:: https://img.shields.io/pypi/pyversions/flask-language.svg\n   :target: https://pypi.python.org/pypi/flask-language\n.. |Build Status| image:: https://travis-ci.org/rclement/flask-language.svg?branch=master\n   :target: https://travis-ci.org/rclement/flask-language\n.. |Coverage Status| image:: https://coveralls.io/repos/github/rclement/flask-language/badge.svg?branch=master\n   :target: https://coveralls.io/github/rclement/flask-language?branch=master\n.. |Documentation Status| image:: https://readthedocs.org/projects/flask-language/badge/?version=master\n   :target: http://flask-language.readthedocs.io/en/master/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frclement%2Fflask-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frclement%2Fflask-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frclement%2Fflask-language/lists"}