{ "info": { "author": "Maksym Sichkaruk", "author_email": "maxim.18.08.1997@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Django Base Locale\n## Simple way to create multi language Django app.\n\n#### 1. Install package:\n```text\npip install django-base-locale\n```\n\n#### 2. Register app in INSTALLED_APPS is your settings.py:\n```text\nINSTALLED_APPS = [\n ...\n 'base_locale.apps.BaseLocaleConfig',\n ...\n]\n```\n\n#### 3. Create your model with model locale:\n```python\nfrom base_locale.models import BaseModel, BaseModelLocale\n\n\nclass Example(BaseModel):\n pass\n\n\nclass ExampleLocale(BaseModelLocale):\n pass\n```\n\n#### Your base urls.py file:\n```text\nfrom base_locale.urls import include_locale_urls\n\nfrom example.urls import urlpatterns as example_urls\n\n\napp_urls = [\n *example_urls,\n]\n\nurlpatterns = [\n ...,\n path('', include_locale_urls(app_urls)),\n \"\"\"\n # In base_locale/urls.py\n def include_locale_urls(urls):\n return include([ \n re_path(r'^(?P[a-z]{2})/', include(urls)),\n path('', include(urls)),\n ])\n \"\"\"\n]\n```\n\n#### How to use\n##### views.py\nWe create class BaseLocaleContext(ContextMixin).\n```text\nfrom django.views.generic import DetailView\n\nfrom base_locale.views import BaseLocaleContext\n\n\nclass ExampleView(BaseLocaleContext, DetailView):\n model = Example\n template_name = 'template.html'\n context_object_name = 'example'\n\n def get_context_data(self, **kwargs):\n context = super().get_context_data(**kwargs)\n \"\"\"\n Now context have instance language, all languages and path with out current language slug.\n context['language']\n context['languages']\n context['path'](form request path '/ru/...' replace language slug)\n\n context['example'] have methods:\n property locales\n Return all locales\n property locale_default\n Use in admin panel, for display locale instance\n get_locale\n Need argument language\n Return Locale instance by language\n context['example_locale'] = context['example'].get_locale(context['language'])\n \"\"\"\n return context\n\n```\n\n##### template.html\nFor getting current locale from instance load base_locale_extras\n```text\n{% load base_locale_extras %}\n{% bl_locale example as example_locale %}\n Now we use the locale object.\n {{ example_locale.language.code }}\n Two ways for use example instance:\n 1. {{ example.pk }}\n 2. {{ example_locale.base.pk }}\n{% end_bl_locale %}\n``` \n\n##### How to create page translation links:\n```text\n{% for lang in languages %}\n lang.code\n{% endfor %}\n{# or #}\n{% for lang in languages %}\n lang.code\n{% endfor %}\n```\npath is not require. path is request.path with out language code.\n\n##### How to create page locale links:\n```text\n{% load base_locale_extras %}\n\n{# or #}\n\n```\n\n### Register tags in settings.py\n```text\nTEMPLATES = [\n {\n ...\n 'OPTIONS': {\n ...\n 'builtins': [\n 'base_locale.templatetags.base_locale_extras',\n ] \n },\n },\n]\n```\n\n### Models reference\nbase_locale app has modifier django metaclass, and use new metaclass for BaseModelLocale.\nNew metaclass was auto generation foreign key for BaseModel. See [How to use](#how-to-use).\nFor access from BaseModelLocale to BaseModel use attribute 'base'.\n\nBaseModel have attributes:\n- property locales: return all locales.\n- property locale_default: return locale by language__is_default is True.\n- get_locale(language): return locale by language.\n\nBaseModelLocale have attributes:\n- property base: return instance ForeignKey for BaseModel.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Maksych/django_base_locale", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-base-locale", "package_url": "https://pypi.org/project/django-base-locale/", "platform": "", "project_url": "https://pypi.org/project/django-base-locale/", "project_urls": { "Homepage": "https://github.com/Maksych/django_base_locale" }, "release_url": "https://pypi.org/project/django-base-locale/4.2.0/", "requires_dist": null, "requires_python": "", "summary": "Simple way to create multi language Django app.", "version": "4.2.0" }, "last_serial": 4928957, "releases": { "4.2.0": [ { "comment_text": "", "digests": { "md5": "73f89182f9097ffa9c257d79e5bc07a8", "sha256": "70b6d3da13f6ddeff3c2a0b5a1eddcb8a76aeb4ef21e27670f36b257e0fed8c9" }, "downloads": -1, "filename": "django_base_locale-4.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "73f89182f9097ffa9c257d79e5bc07a8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11710, "upload_time": "2019-03-11T14:43:36", "url": "https://files.pythonhosted.org/packages/76/32/44320a4ee9845d57f43e7acf1a5ad589959b2ad341e8874f84d3be9a958e/django_base_locale-4.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a37ba4e1e388093e8c7133c80acb0260", "sha256": "c595e1caaa3b3efba8d5916c09465ff1783445b5133b6ca68e0742aa69c94bbd" }, "downloads": -1, "filename": "django_base_locale-4.2.0.tar.gz", "has_sig": false, "md5_digest": "a37ba4e1e388093e8c7133c80acb0260", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8752, "upload_time": "2019-03-11T14:43:38", "url": "https://files.pythonhosted.org/packages/79/cf/3f462c7da35d953caf84b7f231a976244b4011df367f19ed810131119f33/django_base_locale-4.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "73f89182f9097ffa9c257d79e5bc07a8", "sha256": "70b6d3da13f6ddeff3c2a0b5a1eddcb8a76aeb4ef21e27670f36b257e0fed8c9" }, "downloads": -1, "filename": "django_base_locale-4.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "73f89182f9097ffa9c257d79e5bc07a8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11710, "upload_time": "2019-03-11T14:43:36", "url": "https://files.pythonhosted.org/packages/76/32/44320a4ee9845d57f43e7acf1a5ad589959b2ad341e8874f84d3be9a958e/django_base_locale-4.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a37ba4e1e388093e8c7133c80acb0260", "sha256": "c595e1caaa3b3efba8d5916c09465ff1783445b5133b6ca68e0742aa69c94bbd" }, "downloads": -1, "filename": "django_base_locale-4.2.0.tar.gz", "has_sig": false, "md5_digest": "a37ba4e1e388093e8c7133c80acb0260", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8752, "upload_time": "2019-03-11T14:43:38", "url": "https://files.pythonhosted.org/packages/79/cf/3f462c7da35d953caf84b7f231a976244b4011df367f19ed810131119f33/django_base_locale-4.2.0.tar.gz" } ] }