Coder Social home page Coder Social logo

django-collectmessages's Introduction

django-collectmessages

Collect translated messages from other applications.

USAGE

  1. Add application collectmessages to INSTALLED_APPS in settings.py:

    INSTALLED_APPS = (
        ...
    
        'collectmessages',
    
        ...
    )
    
  2. Add the following options to settings.py:

    COLLECTMESSAGES_PATH

    The path of the locale directory where the generated translation files will be placed. This option is required.

    COLLECTMESSAGES_LANGUAGES

    A list of language codes. Translation files will be generated for each code. This option is required.

    COLLECTMESSAGES_FINDERS

    A list of message finders. Each message finder returns a sequence of translated messages for the translation files. This option is required.

    COLLECTMESSAGES_METADATA

    A dictionary with the metadata for the PO-files. This setting is optional.

    Example:

    COLLECTMESSAGES_PATH = "collected/locale"
    COLLECTMESSAGES_LANGUAGES = ("en", "nl")
    COLLECTMESSAGES_FINDERS = (
        "firstexampleapp.messages.MessageFinder",
        "secondexampleapp.messages.MessageFinder",
    )
    COLLECTMESSAGES_METADATA = {
        "Project-Id-Version": "1.0",
        "Report-Msgid-Bugs-To": "[email protected]",
        "POT-Creation-Date": "2007-10-18 14:00+0100",
        "PO-Revision-Date": "2007-10-18 14:00+0100",
        "Last-Translator": "John Doe <[email protected]>",
        "Language-Team": "Translations <[email protected]>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=utf-8",
        "Content-Transfer-Encoding": "8bit",
    }
    
  3. Add COLLECTMESSAGES_PATH to LOCALE_PATHS in settings.py:

    LOCALE_PATHS = (
        ...
    
        "collected/locale",
    
        ...
    )
    
  4. Use the custom command collect_messages to generate the translation files:

    $ python django-manage.py collect_messages
    

    This command has the following options:

    -c, --compile

    Compile the PO-files.

    -t, --pot-file

    Create a POT-file.

    -s, --verbose

    Show more information.

  5. Create custom message finders by subclassing BaseMessageFinder and customizing method find():

    from collectmessages.finders import BaseMessageFinder
    from polib import POEntry
    
    
    class MessageFinder(BaseMessageFinder):
    
        def find(self, language=None):
            ...
    

    Method find() returns a sequence of POEntry objects with the translated messages. It takes one (optional) parameter language. If given, this parameter has the language code for the translated messages. If not given, find() should return POEntry objects for a POT-file, with an empty translated string.

CONTRIBUTORS

django-collectmessages's People

Contributors

bastiaanraa avatar batlock666 avatar mmaccari avatar

Watchers

Kevin Van Wilder avatar  avatar Marc VANDERSTRAETEN avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.