<commit_before>==================
Kay i18n mechanism
==================

Overview
--------

Kay has a almost full stack i18n feature including extracting messages
from the source, adding new language to your app, updating and
compiling the message catalogs and a handlers for javascript gettext
implementation.

Marking your messages
---------------------

You can mark your messages for translation in python code like: 

.. code-block:: python

  from kay.i18n import gettext as _
  _('Hello')

You can mark your messages for translation in templates like: 

.. code-block:: html

  <p>{{ _('Hello') }}</p>
  <p>{% trans %}Hello{% endtrans %}

Extracting messages
-------------------

You can extract the messages from 'myapp' application and create the
template file like:

.. code-block:: console

   $ python manage.py extract_messages myapp

The 'extract_messages' subcommand accepts optional '--domain'
parameter. The value for this parameter must be 'messages' or
'jsmessages'.


Adding translations
-------------------

You can add new Japanese translations from the template like:

.. code-block:: console

  $ python manage.py add_translation myapp -l ja

Updating messages
-----------------

You can update your translations with updated translation template
like:

.. code-block:: console

   $ python manage.py update_translations myapp -l ja


Compiling messages
------------------

You can compile all of your translations under 'myapp' application
like:

.. code-block:: console

  $ python manage.py compile_translations myapp


Javascript handler
------------------

You can define a handler for pseudo javascript gettext like:

.. code-block:: python

  from kay.views.i18n import javascript_catalog

  return Map([
    Rule('/_i18n.js', endpoint='i18n_js',
         defaults={'packages':('myapp','kay')}),
  ])

  all_views = {
    'i18n_js': javascript_catalog,
  }

<commit_msg>Updated docs.<commit_after>==================
Kay i18n mechanism
==================

Overview
--------

Kay has a almost full stack i18n feature including extracting messages
from the source, adding new language to your app, updating and
compiling the message catalogs and a handlers for javascript gettext
implementation. This feature is basicaly based on the jinja2's i18n
feature, so it is a good idea to refer to jinja2's documentation
hosted at:

  http://jinja.pocoo.org/2/documentation/

Marking your messages
---------------------

You can mark your messages for translation in python code as
following:

.. code-block:: python

  from kay.i18n import gettext as _
  _('Hello')

You can mark your messages for translation in templates as following:

.. code-block:: html

  <p>{{ _('Hello') }}</p>
  <p>{% trans %}Hello{% endtrans %}

Extracting messages
-------------------

You can extract the messages from 'myapp' application and create the
template file as following:

.. code-block:: console

   $ python manage.py extract_messages myapp

The 'extract_messages' subcommand accepts optional '--domain'
parameter. The value for this parameter must be 'messages' or
'jsmessages'.


Adding translations
-------------------

You can add new Japanese translations from the template like:

.. code-block:: console

  $ python manage.py add_translation myapp -l ja

Updating messages
-----------------

You can update your translations with updated translation template as
following:

.. code-block:: console

   $ python manage.py update_translations myapp -l ja


Compiling messages
------------------

You can compile all of your translations under 'myapp' application as
following:

.. code-block:: console

  $ python manage.py compile_translations myapp


Javascript handler
------------------

You can define a handler for pseudo javascript gettext as following:

.. code-block:: python

  from kay.views.i18n import javascript_catalog

  return Map([
    Rule('/_i18n.js', endpoint='i18n_js',
         defaults={'packages':('myapp','kay')}),
  ])

  all_views = {
    'i18n_js': javascript_catalog,
  }


{'fraction_non_alphanumeric': 0.1505349589450112, 'fraction_numerical': 0.008210997760636975, 'mean_word_length': 3.1062308478038814, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5672850', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1044, 'n_words': 437}