localflavor.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ==========================
  2. The "local flavor" add-ons
  3. ==========================
  4. Historically, Django has shipped with ``django.contrib.localflavor`` --
  5. assorted pieces of code that are useful for particular countries or cultures.
  6. This code is now distributed separately from Django, for easier maintenance
  7. and to trim the size of Django's codebase.
  8. The new localflavor package is named ``django-localflavor``, with a main
  9. module called ``localflavor`` and many subpackages using an
  10. `ISO 3166 country code`_. For example: ``localflavor.us`` is the
  11. localflavor package for the U.S.A.
  12. Most of these ``localflavor`` add-ons are country-specific fields for the
  13. :doc:`forms </topics/forms/index>` framework -- for example, a
  14. ``USStateField`` that knows how to validate U.S. state abbreviations and a
  15. ``FISocialSecurityNumber`` that knows how to validate Finnish social security
  16. numbers.
  17. To use one of these localized components, just import the relevant subpackage.
  18. For example, here's how you can create a form with a field representing a
  19. French telephone number::
  20. from django import forms
  21. from localflavor.fr.forms import FRPhoneNumberField
  22. class MyForm(forms.Form):
  23. my_french_phone_no = FRPhoneNumberField()
  24. For documentation on a given country's localflavor helpers, see its README
  25. file.
  26. .. _ISO 3166 country code: http://www.iso.org/iso/country_codes.htm
  27. .. _localflavor-packages:
  28. Supported countries
  29. ===================
  30. See the official documentation for more information:
  31. https://django-localflavor.readthedocs.org/
  32. Internationalization of localflavors
  33. ====================================
  34. To activate translations for the ``localflavor`` application, you must include
  35. the application's name in the :setting:`INSTALLED_APPS` setting, so the
  36. internationalization system can find the catalog, as explained in
  37. :ref:`how-django-discovers-translations`.
  38. .. _localflavor-how-to-migrate:
  39. How to migrate
  40. ==============
  41. If you've used the old ``django.contrib.localflavor`` package or one of the
  42. temporary ``django-localflavor-*`` releases, follow these two easy steps to
  43. update your code:
  44. 1. Install the third-party ``django-localflavor`` package from PyPI.
  45. 2. Change your app's import statements to reference the new package.
  46. For example, change this::
  47. from django.contrib.localflavor.fr.forms import FRPhoneNumberField
  48. ...to this::
  49. from localflavor.fr.forms import FRPhoneNumberField
  50. The code in the new package is the same (it was copied directly from Django),
  51. so you don't have to worry about backwards compatibility in terms of
  52. functionality. Only the imports have changed.
  53. .. _localflavor-deprecation-policy:
  54. Deprecation policy
  55. ==================
  56. In Django 1.5, importing from ``django.contrib.localflavor`` will result in a
  57. ``DeprecationWarning``. This means your code will still work, but you should
  58. change it as soon as possible.
  59. In Django 1.6, importing from ``django.contrib.localflavor`` will no longer
  60. work.