mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-05-04 19:54:42 +00:00
Merge branch 'develop' into pr/60
This commit is contained in:
commit
d1cb2455c4
59 changed files with 1512 additions and 517 deletions
3
.github/ISSUE_TEMPLATE.md
vendored
Normal file
3
.github/ISSUE_TEMPLATE.md
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
- Which version of Django are you using?:
|
||||
- Which version of django-rosetta are you using?:
|
||||
- Have you looked trough [recent issues](https://github.com/mbi/django-rosetta/issues?utf8=%E2%9C%93&q=is%3Aissue) and checked this isn't a duplicate?
|
||||
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
### All Submissions:
|
||||
|
||||
- [ ] Are tests passing? (From the root-level of the repository please run `pip install tox && tox`)
|
||||
- [ ] I have added or updated a test to cover the changes proposed in this Pull Request
|
||||
- [ ] I have updated the documentation to cover the changes proposed in this Pull Request
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -8,9 +8,12 @@ build
|
|||
rosetta/locale/xx/LC_MESSAGES/*.mo
|
||||
/.settings
|
||||
/.project
|
||||
docs/_build
|
||||
testproject/coverage.xml
|
||||
testproject/htmlcov/
|
||||
testproject/rosetta.db
|
||||
testproject/src/
|
||||
testproject/.coverage
|
||||
.venv_*
|
||||
.tox
|
||||
.eggs
|
||||
|
||||
|
|
|
|||
21
.travis.yml
Normal file
21
.travis.yml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
language: python
|
||||
services: memcached
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- python: "3.5"
|
||||
env: TOX_ENV=py35-django18
|
||||
- python: "3.5"
|
||||
env: TOX_ENV=py35-django19
|
||||
- python: "2.7"
|
||||
env: TOX_ENV=py27-django17
|
||||
- python: "2.7"
|
||||
env: TOX_ENV=py27-django18
|
||||
- python: "2.7"
|
||||
env: TOX_ENV=py27-django19
|
||||
|
||||
install:
|
||||
- pip install tox
|
||||
|
||||
script:
|
||||
- tox -e $TOX_ENV
|
||||
55
CHANGES
55
CHANGES
|
|
@ -1,3 +1,52 @@
|
|||
Version History
|
||||
===============
|
||||
|
||||
Version 0.7.11 (unreleased)
|
||||
---------------------------
|
||||
* Make MO file compilation optional (PR #166, Issue #155, thanks @nealtodd)
|
||||
* Fix an invalid page get parameter by falling back to page 1 (PR #165, thanks @nealtodd)
|
||||
|
||||
Version 0.7.10
|
||||
--------------
|
||||
* Re-released 0.7.9 to include a missing image (Issue #162, thanks @legios89)
|
||||
|
||||
Version 0.7.9
|
||||
-------------
|
||||
* Use language code without country specification for Yandex dest lang (PR #152, thanks @nealtodd)
|
||||
* Support discovering locale directories like zh_Hans(xx_Xxxx) (Fixes #133 via PR #153 and #133, thanks @glasslion and @dohsimpson)
|
||||
* Ship Django's original search icon as a static asset (Fixes #157, thanks @facconi)
|
||||
* Added a warning about translation via the Google Translate service being deprecated in the next version
|
||||
|
||||
|
||||
Version 0.7.8
|
||||
-------------
|
||||
* Adds missing includes in MANIFEST.in
|
||||
* Support for running tests via setuptools
|
||||
* Updated microsofttranslator dependency version
|
||||
|
||||
Version 0.7.7
|
||||
-------------
|
||||
* Supported Django versions are now 1.7, 1.8 and 1.9
|
||||
* Added proper documentation
|
||||
* Fixed typo in documentation (PR #130, thanks @dfrdmn)
|
||||
* Fixes the Fuzzy toggle link by adding an actual toggle checkbox (Issue #132, thanks @EmilStenstrom)
|
||||
* Better handling of Custom User Models while checking wether the current User is authorized to translate (Issue #131, thanks @EmilStenstrom)
|
||||
* Include the testproject in the sdist tarball to allow Debian to run tests during installation (Issue #137, thanks @fladi)
|
||||
* Display an explicit error message to the enduser when saving the POfile fails for some reason (Issue #135, thanks @pgcd)
|
||||
* Added support for PEP 3101 string formatting (PR #140, thanks @adamjforster)
|
||||
* Added support for composite locales, e.g. 'bs-Cyrl-BA' (Issue #142, thanks @felarov)
|
||||
* Fixed a misplaced CSRF token (PR #145, thanks @pajod)
|
||||
|
||||
|
||||
Version 0.7.6
|
||||
-------------
|
||||
* Added support for the Free Google Translate API (PR #117, thanks @cuchac)
|
||||
* Probable fix for apps defined by their AppConfig causing havoc in Django 1.7 and later (Issues #113 and #125)
|
||||
* Test configuration improved to test against Django 1.8 beta 1 and Django 1.7.5
|
||||
* Require polib >= 1.0.6 (PR #127, thanks @NotSqrt)
|
||||
* Test against Django 1.8 final
|
||||
|
||||
|
||||
Version 0.7.5
|
||||
-------------
|
||||
* Fixed external JavaScript import to be url scheme independent (PR #101, thanks @tsouvarev)
|
||||
|
|
@ -6,6 +55,12 @@ Version 0.7.5
|
|||
* Added support for translator groups (PR #103, thanks @barklund)
|
||||
* Removed Microsoft Translator as a shipped lib, relying on an external version instead
|
||||
* Improved the app loading mechanism to cope with Django 1.7's new AppConfig (thanks @artscoop)
|
||||
* Fixed a couple inconsistencies in the German translation. (thanks @benebun)
|
||||
* Use content_type instead of mimetype in HttpResponse. (Issue #115, thanks @vesteinn)
|
||||
* Don't assume that request.user has settable properties, this was a silly idea anyway (Issue #114, thanks @stevejalim)
|
||||
* Preserve HTML code when receiving translations from the Yandex translation service (Issue #116, thanks @marcbelmont)
|
||||
* Use TOX for testing
|
||||
* Test against Django 1.8a
|
||||
|
||||
|
||||
Version 0.7.4
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@ include MANIFEST.in
|
|||
include LICENSE
|
||||
exclude *.pyc
|
||||
exclude *.sh
|
||||
include tox.ini
|
||||
recursive-include rosetta/locale *
|
||||
recursive-include rosetta/tests *
|
||||
recursive-include rosetta/utils *
|
||||
recursive-include rosetta/templates *
|
||||
prune testproject
|
||||
recursive-include rosetta/static *
|
||||
recursive-include testproject *
|
||||
recursive-include docs *
|
||||
prune rosetta/tests/__pycache__
|
||||
prune rosetta/utils/__pycache__
|
||||
prune rosetta/utils/microsofttranslator/__pycache__
|
||||
|
|
|
|||
143
README.rst
143
README.rst
|
|
@ -2,10 +2,16 @@
|
|||
Rosetta
|
||||
=======
|
||||
|
||||
.. image:: https://travis-ci.org/mbi/django-rosetta.png?branch=develop
|
||||
:target: http://travis-ci.org/mbi/django-rosetta
|
||||
|
||||
|
||||
Rosetta is a `Django <http://www.djangoproject.com/>`_ application that eases the translation process of your Django projects.
|
||||
|
||||
Because it doesn't export any models, Rosetta doesn't create any tables in your project's database. Rosetta can be installed and uninstalled by simply adding and removing a single entry in your project's `INSTALLED_APPS` and a single line in your main ``urls.py`` file.
|
||||
|
||||
Note: as of version 0.7.7 django-rosetta requires Django 1.7 or later. If you need support for earlier versions of Django (1.4+) you should stick to 0.7.6.
|
||||
|
||||
********
|
||||
Features
|
||||
********
|
||||
|
|
@ -16,141 +22,8 @@ Features
|
|||
* Uses Django's admin interface CSS
|
||||
|
||||
|
||||
************
|
||||
Requirements
|
||||
************
|
||||
|
||||
Rosetta requires Django 1.4 or newer. When running with Django 1.5, Python 3.x is supported.
|
||||
|
||||
************
|
||||
Installation
|
||||
************
|
||||
|
||||
|
||||
To install Rosetta:
|
||||
|
||||
1. ``pip install django-rosetta``
|
||||
2. Add ``'rosetta'`` to the `INSTALLED_APPS` in your project's ``settings.py``
|
||||
3. Add an URL entry to your project's ``urls.py``, for example::
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if 'rosetta' in settings.INSTALLED_APPS:
|
||||
urlpatterns += patterns('',
|
||||
url(r'^rosetta/', include('rosetta.urls')),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Note: you can use whatever you wish as the URL prefix.
|
||||
|
||||
To uninstall Rosetta, simply comment out or remove the ``'rosetta'`` line in your ``INSTALLED_APPS``
|
||||
|
||||
*************
|
||||
Configuration
|
||||
Documentation
|
||||
*************
|
||||
|
||||
Rosetta can be configured via the following parameters, to be defined in your project settings file:
|
||||
|
||||
* ``ROSETTA_MESSAGES_PER_PAGE``: Number of messages to display per page. Defaults to ``10``.
|
||||
* ``ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS``: Enable AJAX translation suggestions. Defaults to ``False``.
|
||||
* ``YANDEX_TRANSLATE_KEY``: Translation suggestions from Yandex `Yandex.Translate API <http://api.yandex.com/translate/>`_. To use this service you must first `obtain an AppID key <http://api.yandex.com/key/form.xml?service=trnsl>`_, then specify the key here. Defaults to ``None``.
|
||||
* ``AZURE_CLIENT_ID`` and ``AZURE_CLIENT_SECRET``: Translation suggestions using the Microsoft Azure API. To use this service, you must first `register for the service <https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44>`_, then specify the 'Customer ID' and 'Primary Account Key' respectively, which you can find on your `account information page on Azure Marketplace <https://datamarket.azure.com/account?lang=en>`_.
|
||||
* ``ROSETTA_MESSAGES_SOURCE_LANGUAGE_CODE`` and ``ROSETTA_MESSAGES_SOURCE_LANGUAGE_NAME``: Change these if the source language in your PO files isn't English. Default to ``'en'`` and ``'English'`` respectively.
|
||||
* ``ROSETTA_WSGI_AUTO_RELOAD`` and ``ROSETTA_UWSGI_AUTO_RELOAD``: When running WSGI daemon mode, using ``mod_wsgi`` 2.0c5 or later, this setting controls whether the contents of the gettext catalog files should be automatically reloaded by the WSGI processes each time they are modified. For performance reasons, this setting should be disabled in production environments. Default to ``False``.
|
||||
* ``ROSETTA_EXCLUDED_APPLICATIONS``: Exclude applications defined in this list from being translated. Defaults to ``()``.
|
||||
* ``ROSETTA_REQUIRES_AUTH``: Require authentication for all Rosetta views. Defaults to ``True``.
|
||||
* ``ROSETTA_POFILE_WRAP_WIDTH``: Sets the line-length of the edited PO file. Set this to ``0`` to mimic ``makemessage``'s ``--no-wrap`` option. Defaults to ``78``.
|
||||
* ``ROSETTA_STORAGE_CLASS``: See the note below on Storages. Defaults to ``rosetta.storage.CacheRosettaStorage``
|
||||
* ``ROSETTA_ENABLE_REFLANG``: See the note below on Reference Language. Defaults to ``False``.
|
||||
* ``ROSETTA_ACCESS_CONTROL_FUNCTION``: An alternative function that determines if a given user can access the translation views. This function receives a ``user`` as its argument, and returns a boolean specifying whether the passed user is allowed to use Rosetta or not.
|
||||
* ``ROSETTA_LANGUAGE_GROUPS``: Set to ``True`` to enable language-specific groups, which can be used to give different translators access to different languages. Instead of creating a global ``translators`` group, create individual per-language groups, e.g. ``translators-de``, ``translators-fr``, and assign users to these.
|
||||
* ``ROSETTA_CACHE_NAME``: When using ``rosetta.storage.CacheRosettaStorage``, you can store the rosetta data in a specific cache. This is particularly useful when your ``default`` cache is a ``django.core.cache.backends.dummy.DummyCache`` (which happens on pre-production environments). If unset, it will default to ``rosetta`` if a cache with this name exists, or ``default`` if not.
|
||||
* ``ROSETTA_POFILENAMES``: Defines which po filenames are exposed in the web interface. Defaults to ``('django.po', 'djangojs.po')``
|
||||
* ``ROSETTA_EXCLUDE_PATHS``: Exclude paths defined in this list from being searched (usually ends with "locale"). Defaults to ``()``
|
||||
|
||||
********
|
||||
Storages
|
||||
********
|
||||
|
||||
To prevent re-reading and parsing the PO file catalogs over and over again, Rosetta stores them in a volatile location. This can be either the HTTP session or the Django cache.
|
||||
|
||||
Django 1.4 has introduced a signed cookie session backend, which stores the whole content of the session in an encrypted cookie. Unfortunately this doesn't work with large PO files, as the limit of 4096 chars that can be stored in a cookie are easily exceeded.
|
||||
|
||||
In this case the Cache-based backend should be used (by setting ``ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage'``). Please make sure that a proper ``CACHES`` backend is configured in your Django settings if your Django app is being served in a multi-process environment, or the different server processes, serving subsequent requests, won't find the storage data left by previous requests.
|
||||
|
||||
Alternatively you can switch back to using the Session based storage by setting ``ROSETTA_STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage`` in your settings. This is perfectly safe on Django 1.3. On Django 1.4 or higher make sure you have DON'T use the `signed_cookies <https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions>`_ ``SESSION_BACKEND`` with this Rosetta storage backend or funky things might happen.
|
||||
|
||||
**TL;DR**: if you run Django with gunincorn, mod-wsgi or other multi-process environment, the Django-default ``CACHES`` ``LocMemCache`` backend won't suffice: use memcache instead, or you will run into issues.
|
||||
|
||||
********
|
||||
Security
|
||||
********
|
||||
|
||||
Because Rosetta requires write access to some of the files in your Django project, access to the application is restricted to the administrator user only (as defined in your project's Admin interface)
|
||||
|
||||
If you wish to grant editing access to other users:
|
||||
|
||||
1. Create a 'translators' group in your admin interface
|
||||
2. Add the user you wish to grant translating rights to this group
|
||||
|
||||
******************
|
||||
Reference Language
|
||||
******************
|
||||
|
||||
If this option is enabled, a selector will appear on the translation page allowing you to choose
|
||||
a reference language. A reference language will allow you to display your ``msgid`` in a laguage
|
||||
that has already been translated. For example, if you already have a translation in French, a
|
||||
translator that only knows French and Spanish (but not English) could select French as a reference
|
||||
language to perform a "second hand" translation.
|
||||
|
||||
The last row of the reference language selector, "MSGID", is to directly display ``msgid``.
|
||||
|
||||
*****
|
||||
Usage
|
||||
*****
|
||||
|
||||
Generate a batch of files to translate
|
||||
--------------------------------------
|
||||
|
||||
See `Django's documentation on Internationalization <https://docs.djangoproject.com/en/1.5/topics/i18n/translation/>`_ to setup your project to use i18n and create the ``gettext`` catalog files.
|
||||
|
||||
Translate away!
|
||||
---------------
|
||||
|
||||
Start your Django development server and point your browser to the URL prefix you have chosen during the installation process. You will get to the file selection window.
|
||||
|
||||
.. image:: http://django-rosetta.googlecode.com/files/rosetta-1.png
|
||||
|
||||
Select a file and translate each untranslated message. Whenever a new batch of messages is processed, Rosetta updates the corresponding `django.po` file and regenerates the corresponding ``mo`` file.
|
||||
|
||||
This means your project's labels will be translated right away, unfortunately you'll still have to restart the webserver for the changes to take effect. (NEW: if your webserver supports it, you can force auto-reloading of the translated catalog whenever a change was saved. See the note regarding the ``ROSETTA_WSGI_AUTO_RELOAD`` variable in ``conf/settings.py``.
|
||||
|
||||
If the webserver doesn't have write access on the catalog files (as shown in the screen shot below) an archive of the catalog files can be downloaded.
|
||||
|
||||
.. image:: http://django-rosetta.googlecode.com/files/rosetta-2.1.png
|
||||
|
||||
|
||||
Translating Rosetta itself
|
||||
--------------------------
|
||||
|
||||
By default Rosetta hides its own catalog files in the file selection interface (shown above.) If you would like to translate Rosetta to your own language:
|
||||
|
||||
1. Create a subdirectory for your locale inside Rosetta's ``locale`` directory, e.g. ``rosetta/locale/XX/LC_MESSAGES``
|
||||
2. Instruct Django to create the initial catalog, by running ``django-admin.py makemessages -l XX`` inside Rosetta's directory (refer to `Django's documentation on i18n <http://www.djangoproject.com/documentation/i18n/>`_ for details)
|
||||
3. Instruct Rosetta to look for its own catalogs, by appending `?rosetta` to the language selection page's URL, e.g. ``http://127.0.0.1:8000/rosetta/pick/?rosetta``
|
||||
4. Translate as usual
|
||||
5. Send a pull request if you feel like sharing
|
||||
|
||||
|
||||
|
||||
|
||||
***************
|
||||
Acknowledgments
|
||||
***************
|
||||
|
||||
* Rosetta uses the excellent `polib <https://bitbucket.org/izi/polib>`_ library to parse and handle gettext files.
|
||||
|
||||
.. image:: https://d2weczhvl823v0.cloudfront.net/mbi/django-rosetta/trend.png
|
||||
:alt: Bitdeli badge
|
||||
:target: https://bitdeli.com/free
|
||||
Please refer to the `online documentation <http://django-rosetta.readthedocs.org/>`_ to install Rosetta and get started.
|
||||
|
|
|
|||
192
docs/Makefile
Normal file
192
docs/Makefile
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
|
||||
endif
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " applehelp to make an Apple Help Book"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
@echo " coverage to run coverage check of the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/DjangoRosetta.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/DjangoRosetta.qhc"
|
||||
|
||||
applehelp:
|
||||
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
|
||||
@echo
|
||||
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
|
||||
@echo "N.B. You won't be able to view it unless you put it in" \
|
||||
"~/Library/Documentation/Help or install it in your application" \
|
||||
"bundle."
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/DjangoRosetta"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/DjangoRosetta"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
coverage:
|
||||
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
|
||||
@echo "Testing of coverage in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/coverage/python.txt."
|
||||
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
||||
BIN
docs/_static/rosetta-1.png
vendored
Normal file
BIN
docs/_static/rosetta-1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
docs/_static/rosetta-2.1.png
vendored
Normal file
BIN
docs/_static/rosetta-2.1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
1
docs/changes.rst
Symbolic link
1
docs/changes.rst
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../CHANGES
|
||||
284
docs/conf.py
Normal file
284
docs/conf.py
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Django Rosetta documentation build configuration file, created by
|
||||
# sphinx-quickstart on Thu Apr 2 15:19:37 2015.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import shlex
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Django Rosetta'
|
||||
copyright = u'2016, Marco Bonetti'
|
||||
author = u'Marco Bonetti'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.7.10'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.7.10'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
#keep_warnings = False
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
#html_extra_path = []
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Language to be used for generating the HTML full-text search index.
|
||||
# Sphinx supports the following languages:
|
||||
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
|
||||
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
|
||||
#html_search_language = 'en'
|
||||
|
||||
# A dictionary with options for the search language support, empty by default.
|
||||
# Now only 'ja' uses this config value
|
||||
#html_search_options = {'type': 'default'}
|
||||
|
||||
# The name of a javascript file (relative to the configuration directory) that
|
||||
# implements a search results scorer. If empty, the default will be used.
|
||||
#html_search_scorer = 'scorer.js'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'DjangoRosettadoc'
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'DjangoRosetta.tex', u'Django Rosetta Documentation',
|
||||
u'Marco Bonetti', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'djangorosetta', u'Django Rosetta Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'DjangoRosetta', u'Django Rosetta Documentation',
|
||||
author, 'DjangoRosetta', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#texinfo_no_detailmenu = False
|
||||
27
docs/index.rst
Normal file
27
docs/index.rst
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Rosetta
|
||||
=======
|
||||
|
||||
Rosetta is a `Django <http://www.djangoproject.com/>`_ application that eases the translation process of your Django projects.
|
||||
|
||||
Because it doesn't export any models, Rosetta doesn't create any tables in your project's database. Rosetta can be installed and uninstalled by simply adding and removing a single entry in your project's `INSTALLED_APPS` and a single line in your main ``urls.py`` file.
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Database independent
|
||||
* Reads and writes your project's `gettext` catalogs (po and mo files)
|
||||
* Installed and uninstalled in under a minute
|
||||
* Uses Django's admin interface CSS
|
||||
|
||||
|
||||
|
||||
Contents:
|
||||
=========
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation.rst
|
||||
settings.rst
|
||||
usage.rst
|
||||
changes.rst
|
||||
42
docs/installation.rst
Normal file
42
docs/installation.rst
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
Installation
|
||||
============
|
||||
|
||||
Requirements
|
||||
------------
|
||||
* As of version 0.7.7, Rosetta supports Django 1.7 through 1.9. If you need support for earlier versions of Django (1.4+) you should stick to Rosetta 0.7.6.
|
||||
|
||||
|
||||
Install Rosetta
|
||||
---------------
|
||||
|
||||
1. ``pip install django-rosetta``
|
||||
2. Add ``'rosetta'`` to the `INSTALLED_APPS` in your project's ``settings.py``
|
||||
3. Add an URL entry to your project's ``urls.py``, for example::
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if 'rosetta' in settings.INSTALLED_APPS:
|
||||
urlpatterns += patterns('',
|
||||
url(r'^rosetta/', include('rosetta.urls')),
|
||||
)
|
||||
|
||||
Note: you can use whatever you wish as the URL prefix.
|
||||
|
||||
To uninstall Rosetta, simply comment out or remove the ``'rosetta'`` line in your ``INSTALLED_APPS``
|
||||
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
||||
``pip install tox && tox``
|
||||
|
||||
|
||||
Security
|
||||
--------
|
||||
|
||||
Because Rosetta requires write access to some of the files in your Django project, access to the application is restricted to the administrator user only (as defined in your project's Admin interface)
|
||||
|
||||
If you wish to grant editing access to other users:
|
||||
|
||||
1. Create a `'translators'` group in your admin interface
|
||||
2. Add the user you wish to grant translating rights to this group
|
||||
34
docs/settings.rst
Normal file
34
docs/settings.rst
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
Settings
|
||||
========
|
||||
|
||||
Rosetta can be configured via the following parameters, to be defined in your project settings file:
|
||||
|
||||
* ``ROSETTA_MESSAGES_PER_PAGE``: Number of messages to display per page. Defaults to ``10``.
|
||||
* ``ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS``: Enable AJAX translation suggestions. Defaults to ``False``.
|
||||
* ``YANDEX_TRANSLATE_KEY``: Translation suggestions from Yandex `Yandex.Translate API <http://api.yandex.com/translate/>`_. To use this service you must first `obtain an AppID key <http://api.yandex.com/key/form.xml?service=trnsl>`_, then specify the key here. Defaults to ``None``.
|
||||
* ``AZURE_CLIENT_ID`` and ``AZURE_CLIENT_SECRET``: Translation suggestions using the Microsoft Azure API. To use this service, you must first `register for the service <https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44>`_, then specify the 'Customer ID' and 'Primary Account Key' respectively, which you can find on your `account information page on Azure Marketplace <https://datamarket.azure.com/account?lang=en>`_.
|
||||
* ``ROSETTA_MESSAGES_SOURCE_LANGUAGE_CODE`` and ``ROSETTA_MESSAGES_SOURCE_LANGUAGE_NAME``: Change these if the source language in your PO files isn't English. Default to ``'en'`` and ``'English'`` respectively.
|
||||
* ``ROSETTA_WSGI_AUTO_RELOAD`` and ``ROSETTA_UWSGI_AUTO_RELOAD``: When running WSGI daemon mode, using ``mod_wsgi`` 2.0c5 or later, this setting controls whether the contents of the gettext catalog files should be automatically reloaded by the WSGI processes each time they are modified. For performance reasons, this setting should be disabled in production environments. Default to ``False``.
|
||||
* ``ROSETTA_EXCLUDED_APPLICATIONS``: Exclude applications defined in this list from being translated. Defaults to ``()``.
|
||||
* ``ROSETTA_REQUIRES_AUTH``: Require authentication for all Rosetta views. Defaults to ``True``.
|
||||
* ``ROSETTA_POFILE_WRAP_WIDTH``: Sets the line-length of the edited PO file. Set this to ``0`` to mimic ``makemessage``'s ``--no-wrap`` option. Defaults to ``78``.
|
||||
* ``ROSETTA_STORAGE_CLASS``: See the note below on Storages. Defaults to ``rosetta.storage.CacheRosettaStorage``
|
||||
* ``ROSETTA_ACCESS_CONTROL_FUNCTION``: An alternative function that determines if a given user can access the translation views. This function receives a ``user`` as its argument, and returns a boolean specifying whether the passed user is allowed to use Rosetta or not.
|
||||
* ``ROSETTA_LANGUAGE_GROUPS``: Set to ``True`` to enable language-specific groups, which can be used to give different translators access to different languages. Instead of creating a global ``translators`` group, create individual per-language groups, e.g. ``translators-de``, ``translators-fr``, and assign users to these.
|
||||
* ``ROSETTA_CACHE_NAME``: When using ``rosetta.storage.CacheRosettaStorage``, you can store the Rosetta data in a specific cache. This is particularly useful when your ``default`` cache is a ``django.core.cache.backends.dummy.DummyCache`` (which happens on pre-production environments). If unset, it will default to ``rosetta`` if a cache with this name exists, or ``default`` if not.
|
||||
* ``ROSETTA_POFILENAMES``: Defines which po file names are exposed in the web interface. Defaults to ``('django.po', 'djangojs.po')``
|
||||
* ``ROSETTA_EXCLUDED_PATHS``: Exclude paths defined in this list from being searched (usually ends with "locale"). Defaults to ``()``
|
||||
* ``ROSETTA_AUTO_COMPILE``: Determines whether the MO file is automatically compiled when the PO file is saved. Defaults to ``True``.
|
||||
|
||||
Storages
|
||||
--------
|
||||
|
||||
To prevent re-reading and parsing the PO file catalogs over and over again, Rosetta stores them in a volatile location. This can be either the HTTP session or the Django cache.
|
||||
|
||||
Django 1.4 has introduced a signed cookie session backend, which stores the whole content of the session in an encrypted cookie. Unfortunately this doesn't work with large PO files, as the limit of 4096 chars that can be stored in a cookie is easily exceeded.
|
||||
|
||||
In this case the Cache-based backend should be used (by setting ``ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage'``). Please make sure that a proper ``CACHES`` backend is configured in your Django settings if your Django app is being served in a multi-process environment, or the different server processes, serving subsequent requests, won't find the storage data left by previous requests.
|
||||
|
||||
Alternatively you can switch back to using the Session based storage by setting ``ROSETTA_STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage'`` in your settings. This is perfectly safe on Django 1.3. On Django 1.4 or higher make sure you have DON'T use the `signed_cookies <https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions>`_ ``SESSION_BACKEND`` with this Rosetta storage backend or funky things might happen.
|
||||
|
||||
**TL;DR**: if you run Django with gunincorn, mod-wsgi or other multi-process environment, the Django-default ``CACHES`` ``LocMemCache`` backend won't suffice: use memcache instead, or you will run into issues.
|
||||
41
docs/usage.rst
Normal file
41
docs/usage.rst
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
Usage
|
||||
=====
|
||||
|
||||
Generate a batch of files to translate
|
||||
--------------------------------------
|
||||
|
||||
See `Django's documentation on Internationalization <https://docs.djangoproject.com/en/1.8/topics/i18n/translation/>`_ to set up your project to use i18n and create the ``gettext`` catalog files.
|
||||
|
||||
Translate away!
|
||||
---------------
|
||||
|
||||
Start your Django development server and point your browser to the URL prefix you have chosen during the installation process. You will get to the file selection window.
|
||||
|
||||
.. image:: _static/rosetta-1.png
|
||||
|
||||
Select a file and translate each untranslated message. Whenever a new batch of messages is processed, Rosetta updates the corresponding `django.po` file and regenerates the corresponding ``mo`` file.
|
||||
|
||||
This means your project's labels will be translated right away, unfortunately you'll still have to restart the web server for the changes to take effect. (NEW: if your web server supports it, you can force auto-reloading of the translated catalog whenever a change was saved. See the note regarding the ``ROSETTA_WSGI_AUTO_RELOAD`` variable in ``conf/settings.py``.
|
||||
|
||||
If the webserver doesn't have write access on the catalog files (as shown in the screen shot below) an archive of the catalog files can be downloaded.
|
||||
|
||||
.. image:: _static/rosetta-2.1.png
|
||||
|
||||
|
||||
Translating Rosetta itself
|
||||
--------------------------
|
||||
|
||||
By default Rosetta hides its own catalog files in the file selection interface (shown above.) If you would like to translate Rosetta to your own language:
|
||||
|
||||
1. Create a subdirectory for your locale inside Rosetta's ``locale`` directory, e.g. ``rosetta/locale/XX/LC_MESSAGES``
|
||||
2. Instruct Django to create the initial catalog, by running ``django-admin.py makemessages -l XX`` inside Rosetta's directory (refer to `Django's documentation on i18n <http://www.djangoproject.com/documentation/i18n/>`_ for details)
|
||||
3. Instruct Rosetta to look for its own catalogs, by appending `?rosetta` to the language selection page's URL, e.g. ``http://127.0.0.1:8000/rosetta/pick/?rosetta``
|
||||
4. Translate as usual
|
||||
5. Send a pull request if you feel like sharing
|
||||
|
||||
|
||||
|
||||
Acknowledgments
|
||||
***************
|
||||
|
||||
* Rosetta uses the excellent `polib <https://bitbucket.org/izi/polib>`_ library to parse and handle gettext files.
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
VERSION = (0, 7, 5)
|
||||
VERSION = (0, 7, 10)
|
||||
|
||||
|
||||
def get_version(svn=False, limit=3):
|
||||
"Returns the version as a human-format string."
|
||||
"""Return the version as a human-format string."""
|
||||
return '.'.join([str(i) for i in VERSION[:limit]])
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
from django.conf import settings
|
||||
from rosetta.conf import settings as rosetta_settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from django.utils import importlib
|
||||
try:
|
||||
import importlib
|
||||
except ImportError:
|
||||
from django.utils import importlib
|
||||
|
||||
|
||||
def can_translate(user):
|
||||
|
|
@ -25,20 +29,31 @@ def get_access_control_function():
|
|||
def is_superuser_staff_or_in_translators_group(user):
|
||||
if not getattr(settings, 'ROSETTA_REQUIRES_AUTH', True):
|
||||
return True
|
||||
if not user.is_authenticated():
|
||||
return False
|
||||
elif user.is_superuser and user.is_staff:
|
||||
return True
|
||||
else:
|
||||
return user.groups.filter(name='translators').exists()
|
||||
try:
|
||||
if not user.is_authenticated():
|
||||
return False
|
||||
elif user.is_superuser and user.is_staff:
|
||||
return True
|
||||
else:
|
||||
return user.groups.filter(name='translators').exists()
|
||||
except AttributeError:
|
||||
if not hasattr(user, 'is_authenticated') or not hasattr(user, 'is_superuser') or not hasattr(user, 'groups'):
|
||||
raise ImproperlyConfigured('If you are using custom User Models you must implement a custom authentication method for Rosetta. See ROSETTA_ACCESS_CONTROL_FUNCTION here: https://django-rosetta.readthedocs.org/en/latest/settings.html')
|
||||
raise
|
||||
|
||||
|
||||
def can_translate_language(user, langid):
|
||||
if not rosetta_settings.ROSETTA_LANGUAGE_GROUPS:
|
||||
return can_translate(user)
|
||||
elif not user.is_authenticated():
|
||||
return False
|
||||
elif user.is_superuser and user.is_staff:
|
||||
return True
|
||||
else:
|
||||
return user.groups.filter(name='translators-%s' % langid).exists()
|
||||
try:
|
||||
if not rosetta_settings.ROSETTA_LANGUAGE_GROUPS:
|
||||
return can_translate(user)
|
||||
elif not user.is_authenticated():
|
||||
return False
|
||||
elif user.is_superuser and user.is_staff:
|
||||
return True
|
||||
else:
|
||||
return user.groups.filter(name='translators-%s' % langid).exists()
|
||||
|
||||
except AttributeError:
|
||||
if not hasattr(user, 'is_authenticated') or not hasattr(user, 'is_superuser') or not hasattr(user, 'groups'):
|
||||
raise ImproperlyConfigured('If you are using custom User Models you must implement a custom authentication method for Rosetta. See ROSETTA_ACCESS_CONTROL_FUNCTION here: https://django-rosetta.readthedocs.org/en/latest/settings.html')
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
# Number of messages to display per page.
|
||||
MESSAGES_PER_PAGE = getattr(settings, 'ROSETTA_MESSAGES_PER_PAGE', 10)
|
||||
|
|
@ -15,6 +16,19 @@ YANDEX_TRANSLATE_KEY = getattr(settings, 'YANDEX_TRANSLATE_KEY', None)
|
|||
AZURE_CLIENT_ID = getattr(settings, 'AZURE_CLIENT_ID', None)
|
||||
AZURE_CLIENT_SECRET = getattr(settings, 'AZURE_CLIENT_SECRET', None)
|
||||
|
||||
# Use Google translator
|
||||
GOOGLE_TRANSLATE = getattr(settings, 'ROSETTA_GOOGLE_TRANSLATE', None)
|
||||
if GOOGLE_TRANSLATE:
|
||||
try:
|
||||
import goslate # NOQA
|
||||
|
||||
import warnings
|
||||
warnings.warn('Translation via Google Translate (goslate) is no longer supported by Google and will be removed in the next version of Rosetta')
|
||||
|
||||
except ImportError:
|
||||
raise ImproperlyConfigured('If you set ROSETTA_GOOGLE_TRANSLATE to True, you must install the `goslate` module.')
|
||||
|
||||
|
||||
# Displays this language beside the original MSGID in the admin
|
||||
MAIN_LANGUAGE = getattr(settings, 'ROSETTA_MAIN_LANGUAGE', None)
|
||||
|
||||
|
|
@ -82,3 +96,6 @@ ROSETTA_EXCLUDED_PATHS = getattr(settings, 'ROSETTA_EXCLUDED_PATHS', ())
|
|||
# 'translators` group, create individual per-language groups, e.g.
|
||||
# 'translators-de', 'translators-fr', ...
|
||||
ROSETTA_LANGUAGE_GROUPS = getattr(settings, 'ROSETTA_LANGUAGE_GROUPS', False)
|
||||
|
||||
# Determines whether the MO file is automatically compiled when the PO file is saved.
|
||||
AUTO_COMPILE = getattr(settings, 'ROSETTA_AUTO_COMPILE', True)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -99,16 +99,16 @@ msgid ""
|
|||
"a> for a guide on how to set up internationalization for your project."
|
||||
msgstr ""
|
||||
"Unter <a href=\"%(i18n_doc_link)s\">Django's I18N documentation</a> finden "
|
||||
"Sie eine Anleitung, wie sie Internationalisierung in Ihrem Projekt "
|
||||
"Sie eine Anleitung, wie Sie Internationalisierung in Ihrem Projekt "
|
||||
"einrichten."
|
||||
|
||||
#: templates/rosetta/pofile.html:9
|
||||
msgid "Pick another file"
|
||||
msgstr "Wähle eine andere Datei"
|
||||
msgstr "Wählen Sie eine andere Datei"
|
||||
|
||||
#: templates/rosetta/pofile.html:10
|
||||
msgid "Download this catalog"
|
||||
msgstr "Laden sie diesen Katalog herunter"
|
||||
msgstr "Laden Sie diesen Katalog herunter"
|
||||
|
||||
#: templates/rosetta/pofile.html:25
|
||||
#, fuzzy, python-format
|
||||
|
|
@ -118,7 +118,7 @@ msgstr "Fortschritt: %(percent_translated)s%"
|
|||
#: templates/rosetta/pofile.html:27
|
||||
msgid "File is read-only: download the file when done editing!"
|
||||
msgstr ""
|
||||
"Datei ist schreibgeschützt: Laden Sie die Datei herunter wenn sie mit dem "
|
||||
"Datei ist schreibgeschützt: Laden Sie die Datei herunter wenn Sie mit dem "
|
||||
"Editieren fertig sind!"
|
||||
|
||||
#: templates/rosetta/pofile.html:28
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2,22 +2,21 @@
|
|||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Rosetta\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-02-28 13:36+0100\n"
|
||||
"PO-Revision-Date: 2008-09-12 12:16\n"
|
||||
"Last-Translator: <tomasz@napierala.org>\n"
|
||||
"PO-Revision-Date: 2014-12-10 17:26+0124\n"
|
||||
"Last-Translator: Anonymous User <arrviasto@gmail.com>\n"
|
||||
"Language-Team: pl <LL@li.org>\n"
|
||||
"Language: pl\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Translated-Using: django-rosetta 0.4.RC2\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
|
||||
"|| n%100>=20) ? 1 : 2);\n"
|
||||
"Language: pl\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
||||
"X-Translated-Using: django-rosetta 0.7.4\n"
|
||||
|
||||
#: templates/rosetta/languages.html:5 templates/rosetta/languages.html.py:8
|
||||
msgid "Language selection"
|
||||
|
|
@ -30,30 +29,35 @@ msgstr "Początek"
|
|||
#: templates/rosetta/languages.html:9
|
||||
msgid ""
|
||||
"Couldn't load the specified language file. This usually happens when using "
|
||||
"the Encrypted Cookies Session Storage backend on Django 1.4 or higher.<br/"
|
||||
">Setting ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage' in "
|
||||
"your settings file should fix this."
|
||||
"the Encrypted Cookies Session Storage backend on Django 1.4 or "
|
||||
"higher.<br/>Setting ROSETTA_STORAGE_CLASS = "
|
||||
"'rosetta.storage.CacheRosettaStorage' in your settings file should fix this."
|
||||
msgstr ""
|
||||
"Nie można załadować żądanego pliku. Zwykle spowodowane jest to użyciem "
|
||||
"szyfrowanego magazynu ciastek sesji (Encrypted Cookies Session Storage) na "
|
||||
"Django 1.4 lub nowszym.<br/>Ustawienie ROSETTA_STORAGE_CLASS = "
|
||||
"'rosetta.storage.CacheRosettaStorage' w pliku ustawień (settings.py) powinno"
|
||||
" rozwiązać problem."
|
||||
|
||||
#: templates/rosetta/languages.html:15
|
||||
msgid "Filter"
|
||||
msgstr ""
|
||||
msgstr "Filtr"
|
||||
|
||||
#: templates/rosetta/languages.html:16
|
||||
msgid "Project"
|
||||
msgstr ""
|
||||
msgstr "Projekt"
|
||||
|
||||
#: templates/rosetta/languages.html:17
|
||||
msgid "Third party"
|
||||
msgstr ""
|
||||
msgstr "Aplikacje zewnętrzne"
|
||||
|
||||
#: templates/rosetta/languages.html:19 templates/rosetta/pofile.html:39
|
||||
msgid "All"
|
||||
msgstr ""
|
||||
msgstr "Wszystko"
|
||||
|
||||
#: templates/rosetta/languages.html:32
|
||||
msgid "Application"
|
||||
msgstr ""
|
||||
msgstr "Aplikacja"
|
||||
|
||||
#: templates/rosetta/languages.html:33
|
||||
msgid "Progress"
|
||||
|
|
@ -69,7 +73,7 @@ msgstr "Przetłumaczone"
|
|||
|
||||
#: templates/rosetta/languages.html:36 templates/rosetta/pofile.html:61
|
||||
msgid "Fuzzy"
|
||||
msgstr ""
|
||||
msgstr "Niejednoznaczne (fuzzy)"
|
||||
|
||||
#: templates/rosetta/languages.html:37
|
||||
msgid "Obsolete"
|
||||
|
|
@ -88,15 +92,16 @@ msgid ""
|
|||
"You haven't specified any languages in your settings file, or haven't yet "
|
||||
"generated a batch of translation catalogs."
|
||||
msgstr ""
|
||||
"Nie podałeś żadnych języków w plikach ustawień, lub nie wygenerowałeś "
|
||||
"jeszcze katalogów do tłumaczeń."
|
||||
"Nie podałeś żadnych języków w plikach ustawień lub nie wygenerowałeś jeszcze"
|
||||
" katalogów do tłumaczeń."
|
||||
|
||||
# python-format
|
||||
#: templates/rosetta/languages.html:63
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Please refer to <a href=\"%(i18n_doc_link)s\">Django's I18N documentation</"
|
||||
"a> for a guide on how to set up internationalization for your project."
|
||||
"Please refer to <a href=\"%(i18n_doc_link)s\">Django's I18N "
|
||||
"documentation</a> for a guide on how to set up internationalization for your"
|
||||
" project."
|
||||
msgstr ""
|
||||
"Sprawdź pomoc dotyczącą <a href=\"%(i18n_doc_link)s\">internacjonalizacji "
|
||||
"Django I18N </a>, aby znaleźć dokumentację na temat internacjonalizacji "
|
||||
|
|
@ -111,19 +116,21 @@ msgid "Download this catalog"
|
|||
msgstr "Pobierz ten katalog"
|
||||
|
||||
#: templates/rosetta/pofile.html:25
|
||||
#, fuzzy, python-format
|
||||
#, python-format
|
||||
msgid "Progress: %(percent_translated)s%%"
|
||||
msgstr "Postęp: %(percent_translated)s %"
|
||||
msgstr "Postęp: %(percent_translated)s%%"
|
||||
|
||||
#: templates/rosetta/pofile.html:27
|
||||
msgid "File is read-only: download the file when done editing!"
|
||||
msgstr "Plik jest tylko do odczytu: pobierz go kiedy skończysz edytować"
|
||||
msgstr "Plik jest tylko do odczytu: pobierz go, kiedy skończysz edytować"
|
||||
|
||||
#: templates/rosetta/pofile.html:28
|
||||
msgid ""
|
||||
"Some items in your last translation block couldn't be saved: this usually "
|
||||
"happens when the catalog file changes on disk after you last loaded it."
|
||||
msgstr ""
|
||||
"Niektóre elementy z twojego tłumaczenia nie zostały zapisane. Zwykle oznacza"
|
||||
" to, że plik katalogowy zmienił się od ostatniego załadowania."
|
||||
|
||||
#: templates/rosetta/pofile.html:32
|
||||
#, python-format
|
||||
|
|
@ -144,7 +151,7 @@ msgstr "Tylko przetłumaczone"
|
|||
|
||||
#: templates/rosetta/pofile.html:38
|
||||
msgid "Fuzzy only"
|
||||
msgstr ""
|
||||
msgstr "Tylko niejednoznaczne (fuzzy)"
|
||||
|
||||
#: templates/rosetta/pofile.html:46
|
||||
msgid "Search"
|
||||
|
|
@ -156,7 +163,7 @@ msgstr "Idź"
|
|||
|
||||
#: templates/rosetta/pofile.html:58
|
||||
msgid "Original"
|
||||
msgstr ""
|
||||
msgstr "Oryginał"
|
||||
|
||||
#: templates/rosetta/pofile.html:62
|
||||
msgid "Occurrences(s)"
|
||||
|
|
@ -165,7 +172,7 @@ msgstr "Wystąpienie(a)"
|
|||
#: templates/rosetta/pofile.html:76 templates/rosetta/pofile.html.py:79
|
||||
#: templates/rosetta/pofile.html:94 templates/rosetta/pofile.html.py:97
|
||||
msgid "Context hint"
|
||||
msgstr ""
|
||||
msgstr "Kontekst"
|
||||
|
||||
#: templates/rosetta/pofile.html:104
|
||||
msgid "suggest"
|
||||
|
|
@ -196,7 +203,7 @@ msgstr "Wyświetlanie:"
|
|||
msgid "%(hits)s/%(message_number)s message"
|
||||
msgid_plural "%(hits)s/%(message_number)s messages"
|
||||
msgstr[0] "%(hits)s/%(message_number)s komunikat"
|
||||
msgstr[1] "%(hits)s/%(message_number)s komunikatów"
|
||||
msgstr[1] "%(hits)s/%(message_number)s komunikaty"
|
||||
msgstr[2] "%(hits)s/%(message_number)s komunikatów"
|
||||
|
||||
#~ msgid "English"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -10,7 +10,7 @@ msgstr ""
|
|||
"POT-Creation-Date: 2014-02-28 13:36+0100\n"
|
||||
"PO-Revision-Date: 2010-07-04 13:42+0200\n"
|
||||
"Last-Translator: Nazar Leush <nazar@pleso.net>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language-Team: ru <nazar@pleso.net>\n"
|
||||
"Language: ru\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -10,7 +10,7 @@ msgstr ""
|
|||
"POT-Creation-Date: 2014-02-28 13:36+0100\n"
|
||||
"PO-Revision-Date: 2010-07-04 13:42+0200\n"
|
||||
"Last-Translator: Nazar Leush <nazar@pleso.net>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language-Team: uk <nazar@pleso.net>\n"
|
||||
"Language: uk\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
|
@ -33,26 +33,30 @@ msgid ""
|
|||
">Setting ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage' in "
|
||||
"your settings file should fix this."
|
||||
msgstr ""
|
||||
"Не вдалося завантажити вказаний мовний файл. Це часом стається при використанні "
|
||||
"бекенду Encrypted Cookies Session Storage на Django 1.4 чи вище.<br/"
|
||||
">Вказання ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage' у "
|
||||
"налаштуваннях має виправити це."
|
||||
|
||||
#: templates/rosetta/languages.html:15
|
||||
msgid "Filter"
|
||||
msgstr ""
|
||||
msgstr "Фільтр"
|
||||
|
||||
#: templates/rosetta/languages.html:16
|
||||
msgid "Project"
|
||||
msgstr ""
|
||||
msgstr "Проект"
|
||||
|
||||
#: templates/rosetta/languages.html:17
|
||||
msgid "Third party"
|
||||
msgstr ""
|
||||
msgstr "Третя сторона"
|
||||
|
||||
#: templates/rosetta/languages.html:19 templates/rosetta/pofile.html:39
|
||||
msgid "All"
|
||||
msgstr ""
|
||||
msgstr "Усі"
|
||||
|
||||
#: templates/rosetta/languages.html:32
|
||||
msgid "Application"
|
||||
msgstr ""
|
||||
msgstr "Програма"
|
||||
|
||||
#: templates/rosetta/languages.html:33
|
||||
msgid "Progress"
|
||||
|
|
@ -68,7 +72,7 @@ msgstr "Перекладено"
|
|||
|
||||
#: templates/rosetta/languages.html:36 templates/rosetta/pofile.html:61
|
||||
msgid "Fuzzy"
|
||||
msgstr ""
|
||||
msgstr "Змінені"
|
||||
|
||||
#: templates/rosetta/languages.html:37
|
||||
msgid "Obsolete"
|
||||
|
|
@ -80,13 +84,15 @@ msgstr "Файл"
|
|||
|
||||
#: templates/rosetta/languages.html:61
|
||||
msgid "Nothing to translate!"
|
||||
msgstr ""
|
||||
msgstr "Немає чого перекладати"
|
||||
|
||||
#: templates/rosetta/languages.html:62
|
||||
msgid ""
|
||||
"You haven't specified any languages in your settings file, or haven't yet "
|
||||
"generated a batch of translation catalogs."
|
||||
msgstr ""
|
||||
"Ви не вказали мов у своєму файлі налаштувань або ще не "
|
||||
"згенерували набір каталогів перекладу."
|
||||
|
||||
#: templates/rosetta/languages.html:63
|
||||
#, python-format
|
||||
|
|
@ -94,6 +100,8 @@ msgid ""
|
|||
"Please refer to <a href=\"%(i18n_doc_link)s\">Django's I18N documentation</"
|
||||
"a> for a guide on how to set up internationalization for your project."
|
||||
msgstr ""
|
||||
"Будь ласка, дивіться у <a href=\"%(i18n_doc_link)s\">I18N-документації Django</"
|
||||
"a> посібник з налаштування інтернаціоналізації Вашого проекту."
|
||||
|
||||
#: templates/rosetta/pofile.html:9
|
||||
msgid "Pick another file"
|
||||
|
|
@ -117,6 +125,8 @@ msgid ""
|
|||
"Some items in your last translation block couldn't be saved: this usually "
|
||||
"happens when the catalog file changes on disk after you last loaded it."
|
||||
msgstr ""
|
||||
"Деякі елементи у Вашому останньому блоці не перекладу не вдалося зберегти: це часом "
|
||||
"трапляється, якщо файл каталогу змінився на диску з тих пір, як Ви востаннє його завантажували."
|
||||
|
||||
#: templates/rosetta/pofile.html:32
|
||||
#, python-format
|
||||
|
|
@ -137,7 +147,7 @@ msgstr "Тільки перекладені"
|
|||
|
||||
#: templates/rosetta/pofile.html:38
|
||||
msgid "Fuzzy only"
|
||||
msgstr ""
|
||||
msgstr "Тільки змінені"
|
||||
|
||||
#: templates/rosetta/pofile.html:46
|
||||
msgid "Search"
|
||||
|
|
@ -149,32 +159,32 @@ msgstr "Вперед"
|
|||
|
||||
#: templates/rosetta/pofile.html:58
|
||||
msgid "Original"
|
||||
msgstr ""
|
||||
msgstr "Оригінал"
|
||||
|
||||
#: templates/rosetta/pofile.html:62
|
||||
msgid "Occurrences(s)"
|
||||
msgstr "Зустрічається в"
|
||||
msgstr "Трапляється у"
|
||||
|
||||
#: templates/rosetta/pofile.html:76 templates/rosetta/pofile.html.py:79
|
||||
#: templates/rosetta/pofile.html:94 templates/rosetta/pofile.html.py:97
|
||||
msgid "Context hint"
|
||||
msgstr ""
|
||||
msgstr "Підказка контексту"
|
||||
|
||||
#: templates/rosetta/pofile.html:104
|
||||
msgid "suggest"
|
||||
msgstr ""
|
||||
msgstr "підказка"
|
||||
|
||||
#: templates/rosetta/pofile.html:115
|
||||
#, python-format
|
||||
msgid "%(more_count)s more"
|
||||
msgid_plural "%(more_count)s more"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
msgstr[2] ""
|
||||
msgstr[0] "ще %(more_count)s"
|
||||
msgstr[1] "ще %(more_count)s"
|
||||
msgstr[2] "ще %(more_count)s"
|
||||
|
||||
#: templates/rosetta/pofile.html:127
|
||||
msgid "Save and translate next block"
|
||||
msgstr "Записати і перекласти наступний блок"
|
||||
msgstr "Зберегти і перекласти наступний блок"
|
||||
|
||||
#: templates/rosetta/pofile.html:131
|
||||
msgid "Skip to page:"
|
||||
|
|
@ -196,4 +206,4 @@ msgstr[2] "%(hits)s/%(message_number)s повідомлень"
|
|||
#~ msgstr "Англійська"
|
||||
|
||||
#~ msgid "Both"
|
||||
#~ msgstr "Всі"
|
||||
#~ msgstr "Усі"
|
||||
|
|
|
|||
|
|
@ -1,26 +1,20 @@
|
|||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
from django.core.cache import get_cache
|
||||
from rosetta.conf import settings as rosetta_settings
|
||||
import django
|
||||
import os
|
||||
import inspect
|
||||
from django.apps import AppConfig
|
||||
from django.apps import apps
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
try:
|
||||
from django.utils import timezone
|
||||
except:
|
||||
timezone = None
|
||||
|
||||
try:
|
||||
set
|
||||
except NameError:
|
||||
from sets import Set as set # Python 2.3 fallback
|
||||
|
||||
if django.VERSION[0:2] >= (1,7):
|
||||
from django.apps import AppConfig
|
||||
from django.apps import apps
|
||||
|
||||
cache = get_cache(rosetta_settings.ROSETTA_CACHE_NAME)
|
||||
from django.core.cache import caches
|
||||
cache = caches[rosetta_settings.ROSETTA_CACHE_NAME]
|
||||
except ImportError:
|
||||
from django.core.cache import get_cache
|
||||
cache = get_cache(rosetta_settings.ROSETTA_CACHE_NAME)
|
||||
|
||||
|
||||
def timestamp_with_timezone(dt=None):
|
||||
|
|
@ -74,7 +68,9 @@ def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False)
|
|||
if os.path.isdir(localepath):
|
||||
paths.append(localepath)
|
||||
|
||||
|
||||
# project/app/locale
|
||||
has_appconfig = False
|
||||
for appname in settings.INSTALLED_APPS:
|
||||
if rosetta_settings.EXCLUDED_APPLICATIONS and appname in rosetta_settings.EXCLUDED_APPLICATIONS:
|
||||
continue
|
||||
|
|
@ -86,50 +82,68 @@ def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False)
|
|||
# For django 1.7, an imported INSTALLED_APP can be an AppConfig instead
|
||||
# of an app module. This code converts the AppConfig to its application
|
||||
# module.
|
||||
if django.VERSION[0:2] >= (1,7):
|
||||
if django.VERSION[0:2] >= (1, 7):
|
||||
if inspect.isclass(app) and issubclass(app, AppConfig):
|
||||
app = apps.get_app_config(app.name).module
|
||||
has_appconfig = True
|
||||
continue
|
||||
|
||||
try:
|
||||
if issubclass(app, AppConfig):
|
||||
app = apps.get_app_config(app.name).module
|
||||
else:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
apppath = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(app.__file__), 'locale')))
|
||||
app_path = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(app.__file__), 'locale')))
|
||||
|
||||
# django apps
|
||||
if 'contrib' in apppath and 'django' in apppath and not django_apps:
|
||||
if 'contrib' in app_path and 'django' in app_path and not django_apps:
|
||||
continue
|
||||
|
||||
# third party external
|
||||
if not third_party_apps and abs_project_path not in apppath:
|
||||
if not third_party_apps and abs_project_path not in app_path:
|
||||
continue
|
||||
|
||||
# local apps
|
||||
if not project_apps and abs_project_path in apppath:
|
||||
if not project_apps and abs_project_path in app_path:
|
||||
continue
|
||||
|
||||
|
||||
if os.path.isdir(apppath):
|
||||
paths.append(apppath)
|
||||
if os.path.isdir(app_path):
|
||||
paths.append(app_path)
|
||||
|
||||
# Handling with AppConfigs is a wee messy, but we can simply get all the
|
||||
# app paths directly from apps object
|
||||
if has_appconfig:
|
||||
for app_ in apps.get_app_configs():
|
||||
if rosetta_settings.EXCLUDED_APPLICATIONS and app_.name in rosetta_settings.EXCLUDED_APPLICATIONS:
|
||||
continue
|
||||
|
||||
app_path = app_.path
|
||||
# django apps
|
||||
if 'contrib' in app_path and 'django' in app_path and not django_apps:
|
||||
continue
|
||||
|
||||
# third party external
|
||||
if not third_party_apps and abs_project_path not in app_path:
|
||||
continue
|
||||
|
||||
# local apps
|
||||
if not project_apps and abs_project_path in app_path:
|
||||
continue
|
||||
|
||||
if os.path.exists(os.path.abspath(os.path.join(app_path, 'locale'))):
|
||||
paths.append(os.path.abspath(os.path.join(app_path, 'locale')))
|
||||
if os.path.exists(os.path.abspath(os.path.join(app_path, '..', 'locale'))):
|
||||
paths.append(os.path.abspath(os.path.join(app_path, '..', 'locale')))
|
||||
|
||||
ret = set()
|
||||
langs = [lang, ]
|
||||
if u'-' in lang:
|
||||
_l, _c = map(lambda x: x.lower(), lang.split(u'-'))
|
||||
langs += [u'%s_%s' % (_l, _c), u'%s_%s' % (_l, _c.upper()), ]
|
||||
_l, _c = map(lambda x: x.lower(), lang.split(u'-', 1))
|
||||
langs += [u'%s_%s' % (_l, _c), u'%s_%s' % (_l, _c.upper()), u'%s_%s' % (_l, _c.capitalize()),]
|
||||
elif u'_' in lang:
|
||||
_l, _c = map(lambda x: x.lower(), lang.split(u'_'))
|
||||
langs += [u'%s-%s' % (_l, _c), u'%s-%s' % (_l, _c.upper()), ]
|
||||
_l, _c = map(lambda x: x.lower(), lang.split(u'_', 1))
|
||||
langs += [u'%s-%s' % (_l, _c), u'%s-%s' % (_l, _c.upper()), u'%s_%s' % (_l, _c.capitalize()),]
|
||||
|
||||
paths = map(os.path.normpath, paths)
|
||||
paths = list(set(paths))
|
||||
for path in paths:
|
||||
# Exclude paths
|
||||
if not path in rosetta_settings.ROSETTA_EXCLUDED_PATHS:
|
||||
if path not in rosetta_settings.ROSETTA_EXCLUDED_PATHS:
|
||||
for lang_ in langs:
|
||||
dirname = os.path.join(path, lang_, 'LC_MESSAGES')
|
||||
for fn in rosetta_settings.POFILENAMES:
|
||||
|
|
|
|||
BIN
rosetta/static/admin/img/icon_searchbox_rosetta.png
Normal file
BIN
rosetta/static/admin/img/icon_searchbox_rosetta.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 667 B |
|
|
@ -1,6 +1,4 @@
|
|||
from django.core.cache import get_cache
|
||||
from django.conf import settings
|
||||
from django.utils import importlib
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from rosetta.conf import settings as rosetta_settings
|
||||
import hashlib
|
||||
|
|
@ -9,7 +7,17 @@ import six
|
|||
import django
|
||||
|
||||
|
||||
cache = get_cache(rosetta_settings.ROSETTA_CACHE_NAME)
|
||||
try:
|
||||
from django.core.cache import caches
|
||||
cache = caches[rosetta_settings.ROSETTA_CACHE_NAME]
|
||||
except ImportError:
|
||||
from django.core.cache import get_cache
|
||||
cache = get_cache(rosetta_settings.ROSETTA_CACHE_NAME)
|
||||
|
||||
try:
|
||||
import importlib
|
||||
except ImportError:
|
||||
from django.utils import importlib
|
||||
|
||||
|
||||
class BaseRosettaStorage(object):
|
||||
|
|
@ -82,7 +90,7 @@ class CacheRosettaStorage(BaseRosettaStorage):
|
|||
|
||||
# Make sure we're not using DummyCache
|
||||
if 'dummycache' in settings.CACHES[rosetta_settings.ROSETTA_CACHE_NAME]['BACKEND'].lower():
|
||||
raise ImproperlyConfigured("You can't use the CacheRosettaStorage if your cache isn't correctly set up (you are use the DummyCache cache backend).")
|
||||
raise ImproperlyConfigured("You can't use the CacheRosettaStorage if your cache isn't correctly set up (you are using the DummyCache cache backend).")
|
||||
|
||||
# Make sure the actually actually works
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html>{% load url from future %}{% load admin_static %}
|
||||
<!DOCTYPE html>{% load admin_static %}
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>{% block pagetitle %}Rosetta{% endblock %}</title>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ google.setOnLoadCallback(function() {
|
|||
$('.hide', $(this).parent()).hide();
|
||||
});
|
||||
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS and rosetta_settings.AZURE_CLIENT_ID and rosetta_settings.AZURE_CLIENT_SECRET %}
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}
|
||||
{% if rosetta_settings.AZURE_CLIENT_ID and rosetta_settings.AZURE_CLIENT_SECRET or rosetta_settings.GOOGLE_TRANSLATE %}
|
||||
$('a.suggest').click(function(e){
|
||||
e.preventDefault();
|
||||
var a = $(this);
|
||||
|
|
@ -20,11 +21,11 @@ google.setOnLoadCallback(function() {
|
|||
orig = unescape(orig).replace(/<br\s?\/?>/g,'\n').replace(/<code>/,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<');
|
||||
a.attr('class','suggesting').html('...');
|
||||
|
||||
$.getJSON("/rosetta/translate/", {
|
||||
$.getJSON("./translate/", {
|
||||
from: sourceLang,
|
||||
to: destLang,
|
||||
text: orig
|
||||
},
|
||||
},
|
||||
function(data) {
|
||||
if (data.success){
|
||||
trans.val(unescape(data.translation).replace(/'/g,'\'').replace(/"/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s '));
|
||||
|
|
@ -35,9 +36,9 @@ google.setOnLoadCallback(function() {
|
|||
}
|
||||
);
|
||||
});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS and rosetta_settings.YANDEX_TRANSLATE_KEY %}
|
||||
{% if rosetta_settings.YANDEX_TRANSLATE_KEY %}
|
||||
$('a.suggest').click(function(e){
|
||||
e.preventDefault();
|
||||
var a = $(this);
|
||||
|
|
@ -45,13 +46,15 @@ google.setOnLoadCallback(function() {
|
|||
var orig = $('.original .message', a.parents('tr')).html();
|
||||
var trans=$('textarea',a.parent());
|
||||
var apiUrl = "https://translate.yandex.net/api/v1.5/tr.json/translate";
|
||||
var destLangRoot = '{{ rosetta_i18n_lang_code }}'.split('-')[0];
|
||||
var lang = '{{ rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE }}-' + destLangRoot;
|
||||
|
||||
a.attr('class','suggesting').html('...');
|
||||
|
||||
var apiData = {
|
||||
error: 'onTranslationError',
|
||||
success: 'onTranslationComplete',
|
||||
lang: '{{ rosetta_settings.MESSAGES_SOURCE_LANGUAGE_CODE }}-{{ rosetta_i18n_lang_code }}',
|
||||
lang: lang,
|
||||
key: '{{ rosetta_settings.YANDEX_TRANSLATE_KEY }}',
|
||||
format: 'html',
|
||||
text: orig
|
||||
|
|
@ -63,7 +66,7 @@ google.setOnLoadCallback(function() {
|
|||
dataType: 'jsonp',
|
||||
success: function(response) {
|
||||
if (response.code == 200) {
|
||||
trans.val(response.text[0]);
|
||||
trans.val(response.text[0].replace(/<br>/g, '\n').replace(/</g, '<').replace(/>/g, '>'));
|
||||
a.hide();
|
||||
} else {
|
||||
a.text(response);
|
||||
|
|
@ -74,6 +77,7 @@ google.setOnLoadCallback(function() {
|
|||
}
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
$('td.plural').each(function(i) {
|
||||
|
|
@ -83,11 +87,11 @@ google.setOnLoadCallback(function() {
|
|||
$($('.part',td).get(j)).css('top',textareaY + 'px');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('.translation textarea').blur(function() {
|
||||
if($(this).val()) {
|
||||
$('.alert', $(this).parents('tr')).remove();
|
||||
var RX = /%(?:\([^\s\)]*\))?[sdf]/g,
|
||||
var RX = /%(?:\([^\s\)]*\))?[sdf]|\{[\w\d_]+?\}/g,
|
||||
origs=$('.original', $(this).parents('tr')).html().match(RX),
|
||||
trads=$(this).val().match(RX),
|
||||
error = $('<span class="alert">Unmatched variables</span>');
|
||||
|
|
@ -111,5 +115,15 @@ google.setOnLoadCallback(function() {
|
|||
});
|
||||
|
||||
$('.translation textarea').eq(0).focus();
|
||||
|
||||
|
||||
$('#action-toggle').change(function(){
|
||||
jQuery('tbody td.c input[type="checkbox"]').each(function(i, e) {
|
||||
if($('#action-toggle').is(':checked')) {
|
||||
$(e).attr('checked', 'checked');
|
||||
} else {
|
||||
$(e).removeAttr('checked');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
{% extends "rosetta/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block pagetitle %}{{block.super}} - {% trans "Language selection" %}{% endblock %}
|
||||
|
||||
|
|
@ -40,7 +39,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for app,path,po in pos %}
|
||||
<tr class="{% cycle row1,row2 %}">
|
||||
<tr class="{% cycle 'row1' 'row2' %}">
|
||||
<td><a href="{% url 'rosetta-language-selection' lid forloop.counter0 %}{% if do_django %}?django{% endif %}{% if do_rosetta %}?rosetta{% endif %}">{{ app|title }}</a></td>
|
||||
<td class="ch-progress r">{{po.percent_translated|floatformat:2}}%</td>
|
||||
{% with po.untranslated_entries|length as len_untranslated_entries %}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
{% extends "rosetta/base.html" %}{% load admin_static %}
|
||||
{% load rosetta i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block header %}
|
||||
{{block.super}}
|
||||
|
|
@ -26,6 +25,13 @@
|
|||
</div>
|
||||
{% if not rosetta_i18n_write %}<p class="errornote read-only">{% trans "File is read-only: download the file when done editing!" %}</p>{% endif %}
|
||||
{% if rosetta_last_save_error %}<p class="errornote save-conflict">{% trans "Some items in your last translation block couldn't be saved: this usually happens when the catalog file changes on disk after you last loaded it." %}</p>{% endif %}
|
||||
{% if messages %}
|
||||
<div class="messages errornote save-conflict">
|
||||
{% for message in messages %}
|
||||
<p class="{{message.tags}}">{{ message|linebreaks }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
|
@ -52,7 +58,7 @@
|
|||
<form id="changelist-search" action="" method="post">
|
||||
<div>
|
||||
{% rosetta_csrf_token %}
|
||||
<label for="searchbar"><img src="{% static "admin/img/icon_searchbox.png" %}" alt="{% trans "Search" %}" /></label>
|
||||
<label for="searchbar"><img src="{% static "admin/img/icon_searchbox_rosetta.png" %}" alt="{% trans "Search" %}" /></label>
|
||||
<input type="text" size="40" name="query" value="{% if query %}{{query}}{% endif %}" id="searchbar" tabindex="0" />
|
||||
<input type="submit" name="search" value="{% trans "Go" %}" />
|
||||
</div>
|
||||
|
|
@ -60,20 +66,20 @@
|
|||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
{% rosetta_csrf_token %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
{% rosetta_csrf_token %}
|
||||
<th><div class="text">{% trans "Original" %}</div></th>
|
||||
{% if main_language %}<th>{{ main_language }}</th>{% endif %}
|
||||
<th>{{ rosetta_i18n_lang_name }}</th>
|
||||
<th class="c"><span class="checkall">[-]</span> {% trans "Fuzzy" %}</th>
|
||||
<th class="c"><input style="display: inline;" id="action-toggle" type="checkbox"> {% trans "Fuzzy" %}</th>
|
||||
<th>{% trans "Occurrences(s)" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for message in rosetta_messages %}
|
||||
<tr class="{% cycle row1,row2 %}">
|
||||
<tr class="{% cycle 'row1' 'row2' %}">
|
||||
{% if message.msgid_plural %}
|
||||
<td class="original plural">
|
||||
<div class="plural-container">
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import six
|
|||
|
||||
|
||||
register = template.Library()
|
||||
rx = re.compile(r'(%(\([^\s\)]*\))?[sd])')
|
||||
rx = re.compile(r'(%(\([^\s\)]*\))?[sd]|\{[\w\d_]+?\})')
|
||||
|
||||
|
||||
def format_message(message):
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
from .tests import *
|
||||
from microsofttranslator.test import *
|
||||
|
|
|
|||
6
rosetta/tests/test_app/apps.py
Normal file
6
rosetta/tests/test_app/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TestAppConfig(AppConfig):
|
||||
name = 'rosetta.tests.test_app'
|
||||
verbose_name = 'Rosetta test app'
|
||||
BIN
rosetta/tests/test_app/locale/xx/LC_MESSAGES/django.mo
Normal file
BIN
rosetta/tests/test_app/locale/xx/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
35
rosetta/tests/test_app/locale/xx/LC_MESSAGES/django.po
Normal file
35
rosetta/tests/test_app/locale/xx/LC_MESSAGES/django.po
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Rosetta\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2013-04-30 14:37+0200\n"
|
||||
"PO-Revision-Date: 2015-02-25 08:16-0600\n"
|
||||
"Last-Translator: <admin@admin.com>\n"
|
||||
"Language-Team: French <LL@li.org>\n"
|
||||
"Language: fr\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
|
||||
"X-Translated-Using: django-rosetta 0.7.5\n"
|
||||
|
||||
#: templates/test.html:3
|
||||
msgid "Some text to translate"
|
||||
msgstr "Some text to translate"
|
||||
|
||||
#: templates/test.html:5
|
||||
#, python-format
|
||||
msgid ""
|
||||
"\n"
|
||||
"one bottle of beer on the wall\n"
|
||||
msgid_plural ""
|
||||
"\n"
|
||||
"%(num_bottles)s bottles of beer on the wall\n"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
msgstr[2] ""
|
||||
|
|
@ -1,29 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.core.urlresolvers import reverse, resolve
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.cache import cache
|
||||
from django.template.defaultfilters import floatformat
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase # , override_settings
|
||||
from django.test.client import Client
|
||||
from django.dispatch import receiver
|
||||
from rosetta.conf import settings as rosetta_settings
|
||||
from rosetta.signals import entry_changed, post_save
|
||||
import os
|
||||
import shutil
|
||||
import six
|
||||
import django
|
||||
|
||||
|
||||
try:
|
||||
from django.dispatch import receiver
|
||||
except ImportError:
|
||||
# We might be in django < 1.3, so backport this function
|
||||
def receiver(signal, **kwargs):
|
||||
def _decorator(func):
|
||||
signal.connect(func, **kwargs)
|
||||
return func
|
||||
return _decorator
|
||||
import vcr
|
||||
import hashlib
|
||||
|
||||
|
||||
class RosettaTestCase(TestCase):
|
||||
|
|
@ -33,9 +24,11 @@ class RosettaTestCase(TestCase):
|
|||
super(RosettaTestCase, self).__init__(*args, **kwargs)
|
||||
self.curdir = os.path.dirname(__file__)
|
||||
self.dest_file = os.path.normpath(os.path.join(self.curdir, '../locale/xx/LC_MESSAGES/django.po'))
|
||||
self.django_version_major, self.django_version_minor = django.VERSION[0], django.VERSION[1]
|
||||
|
||||
|
||||
def setUp(self):
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
user = User.objects.create_user('test_admin', 'test@test.com', 'test_password')
|
||||
user2 = User.objects.create_user('test_admin2', 'test@test2.com', 'test_password')
|
||||
user3 = User.objects.create_user('test_admin3', 'test@test2.com', 'test_password')
|
||||
|
|
@ -53,11 +46,20 @@ class RosettaTestCase(TestCase):
|
|||
self.client2.login(username='test_admin2', password='test_password')
|
||||
|
||||
self.__old_settings_languages = settings.LANGUAGES
|
||||
settings.LANGUAGES = (('xx', 'dummy language'), ('fr_FR.utf8', 'French (France), UTF8'))
|
||||
settings.LANGUAGES = (
|
||||
('xx', 'dummy language'),
|
||||
('fr_FR.utf8', 'French (France), UTF8'),
|
||||
('bs-Cyrl-BA', u'Bosnian (Cyrillic) (Bosnia and Herzegovina)'),
|
||||
('yy-Anot', u'Yet Another dummy language'),
|
||||
('zh_Hans', u'Chinese (simplified)'),
|
||||
)
|
||||
|
||||
self.__session_engine = settings.SESSION_ENGINE
|
||||
self.__storage_class = rosetta_settings.STORAGE_CLASS
|
||||
self.__require_auth = rosetta_settings.ROSETTA_REQUIRES_AUTH
|
||||
self.__google_translate = rosetta_settings.GOOGLE_TRANSLATE
|
||||
self.__enable_translation = rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS
|
||||
self.__auto_compile = rosetta_settings.AUTO_COMPILE
|
||||
|
||||
shutil.copy(self.dest_file, self.dest_file + '.orig')
|
||||
|
||||
|
|
@ -66,6 +68,9 @@ class RosettaTestCase(TestCase):
|
|||
settings.SESSION_ENGINE = self.__session_engine
|
||||
rosetta_settings.STORAGE_CLASS = self.__storage_class
|
||||
rosetta_settings.ROSETTA_REQUIRES_AUTH = self.__require_auth
|
||||
rosetta_settings.GOOGLE_TRANSLATE = self.__google_translate
|
||||
rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS = self.__enable_translation
|
||||
rosetta_settings.AUTO_COMPILE = self.__auto_compile
|
||||
shutil.move(self.dest_file + '.orig', self.dest_file)
|
||||
|
||||
def test_1_ListLoading(self):
|
||||
|
|
@ -112,7 +117,7 @@ class RosettaTestCase(TestCase):
|
|||
r = self.client.get(reverse('rosetta-home'))
|
||||
|
||||
# the translated string no longer is up for translation
|
||||
self.assertTrue('String 1' in str(r.content))
|
||||
self.assertTrue('String 1' in str(r.content))
|
||||
self.assertTrue('String 2' not in str(r.content))
|
||||
|
||||
# display only translated strings
|
||||
|
|
@ -120,7 +125,7 @@ class RosettaTestCase(TestCase):
|
|||
r = self.client.get(reverse('rosetta-home'))
|
||||
|
||||
# The tranlsation was persisted
|
||||
self.assertTrue('String 1' not in str(r.content))
|
||||
self.assertTrue('String 1' not in str(r.content))
|
||||
self.assertTrue('String 2' in str(r.content))
|
||||
self.assertTrue('Hello, world' in str(r.content))
|
||||
|
||||
|
|
@ -306,20 +311,20 @@ class RosettaTestCase(TestCase):
|
|||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('rosetta/locale/xx/LC_MESSAGES/django.po') not in str(r.content))
|
||||
|
||||
if self.django_version_major >= 1 and self.django_version_minor >= 3:
|
||||
if django.VERSION[0:2] >= (1, 3):
|
||||
self.assertTrue(('contrib') in str(r.content))
|
||||
|
||||
self.client.get(reverse('rosetta-pick-file') + '?filter=all')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('rosetta/locale/xx/LC_MESSAGES/django.po') in str(r.content))
|
||||
|
||||
if self.django_version_major >= 1 and self.django_version_minor >= 3:
|
||||
if django.VERSION[0:2] >= (1, 3):
|
||||
self.assertTrue(('contrib') in str(r.content))
|
||||
|
||||
self.client.get(reverse('rosetta-pick-file') + '?filter=project')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('rosetta/locale/xx/LC_MESSAGES/django.po') not in str(r.content))
|
||||
if self.django_version_major >= 1 and self.django_version_minor >= 3:
|
||||
if django.VERSION[0:2] >= (1, 3):
|
||||
self.assertTrue(('contrib') not in str(r.content))
|
||||
|
||||
def test_14_issue_99_context_and_comments(self):
|
||||
|
|
@ -437,7 +442,7 @@ class RosettaTestCase(TestCase):
|
|||
self.assertTrue('msgstr[1] ""\n"\\n"\n"Bar %s\\n"' in pofile_content)
|
||||
|
||||
def test_20_Test_Issue_gh38(self):
|
||||
if self.django_version_minor >= 4 and self.django_version_major >= 1:
|
||||
if django.VERSION[0:2] >= (1, 4):
|
||||
self.assertTrue('django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES)
|
||||
|
||||
settings.SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
|
||||
|
|
@ -465,7 +470,7 @@ class RosettaTestCase(TestCase):
|
|||
self.assertTrue('m_9f6c442c6d579707440ba9dada0fb373' in str(r.content))
|
||||
|
||||
# Two, the cookie backend
|
||||
if self.django_version_minor < 6:
|
||||
if django.VERSION[0:2] < (1, 6):
|
||||
rosetta_settings.STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage'
|
||||
|
||||
shutil.copy(os.path.normpath(os.path.join(self.curdir, './django.po.issue38gh.template')), self.dest_file)
|
||||
|
|
@ -499,11 +504,13 @@ class RosettaTestCase(TestCase):
|
|||
r = self.client.get(reverse('rosetta-language-selection', args=('xx', 0), kwargs=dict()))
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
# We have distinct hashes, even though the msgid and msgstr are identical
|
||||
#print (r.content)
|
||||
# print (r.content)
|
||||
self.assertTrue('m_4765f7de94996d3de5975fa797c3451f' in str(r.content))
|
||||
self.assertTrue('m_08e4e11e2243d764fc45a5a4fba5d0f2' in str(r.content))
|
||||
|
||||
def test_23_save_header_data(self):
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
shutil.copy(os.path.normpath(os.path.join(self.curdir, './django.po.template')), self.dest_file)
|
||||
|
||||
unicode_user = User.objects.create_user('test_unicode', 'save_header_data@test.com', 'test_unicode')
|
||||
|
|
@ -531,7 +538,7 @@ class RosettaTestCase(TestCase):
|
|||
f_ = open(self.dest_file, 'rb')
|
||||
content = six.text_type(f_.read())
|
||||
f_.close()
|
||||
#print (content)
|
||||
# print (content)
|
||||
# make sure unicode data was properly converted to ascii
|
||||
self.assertTrue('Hello, world' in content)
|
||||
self.assertTrue('save_header_data@test.com' in content)
|
||||
|
|
@ -584,7 +591,7 @@ class RosettaTestCase(TestCase):
|
|||
self.assertTrue('<li class="active"><a href="?filter=third-party">' in str(r.content))
|
||||
|
||||
def test_29_unsupported_p3_django_16_storage(self):
|
||||
if self.django_version_minor >= 6 and self.django_version_major >= 1:
|
||||
if django.VERSION[0:2] >= (1, 6):
|
||||
self.assertTrue('django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES)
|
||||
|
||||
settings.SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
|
||||
|
|
@ -634,6 +641,8 @@ class RosettaTestCase(TestCase):
|
|||
rosetta_settings.ROSETTA_EXCLUDED_PATHS = ROSETTA_EXCLUDED_PATHS
|
||||
|
||||
def test_32_pr_103__language_groups(self):
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
||||
ROSETTA_LANGUAGE_GROUPS = rosetta_settings.ROSETTA_LANGUAGE_GROUPS
|
||||
rosetta_settings.ROSETTA_LANGUAGE_GROUPS = False
|
||||
|
||||
|
|
@ -686,6 +695,146 @@ class RosettaTestCase(TestCase):
|
|||
self.assertTrue('<span class="message">translated-string1</span>' in str(r.content))
|
||||
rosetta_settings.ENABLE_REFLANG = ENABLE_REFLANG
|
||||
|
||||
@vcr.use_cassette('fixtures/vcr_cassettes/test_33_pr_116_google_translate.yaml', match_on=['method', 'scheme', 'host', 'port', 'path', 'query', 'raw_body'], record_mode='new_episodes')
|
||||
def test_33_pr_116_google_translate(self):
|
||||
rosetta_settings.GOOGLE_TRANSLATE = True
|
||||
rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS = True
|
||||
|
||||
r = self.client.get(reverse('translate_text') + '?from=en&to=fr&text=Hello,+world!')
|
||||
self.assertTrue(six.text_type("Bonjour le monde!") in six.text_type(r.content))
|
||||
|
||||
def test_34_issue_113_app_configs(self):
|
||||
if django.VERSION[0:2] >= (1, 7):
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=all')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue('rosetta/select/xx/1/">Test_App' in str(r.content))
|
||||
|
||||
def test_35_issue_135_display_exception_messages(self):
|
||||
shutil.copy(os.path.normpath(os.path.join(self.curdir, './django.po.template')), self.dest_file)
|
||||
|
||||
# Load the template file
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=third-party')
|
||||
r = self.client.get(reverse('rosetta-language-selection', args=('xx', 0), kwargs=dict()))
|
||||
r = self.client.get(reverse('rosetta-home') + '?filter=untranslated')
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
# make sure both strings are untranslated
|
||||
self.assertTrue('m_e48f149a8b2e8baa81b816c0edf93890' in str(r.content))
|
||||
|
||||
# make the pofile read-only
|
||||
os.chmod(self.dest_file, 292) # 0400
|
||||
|
||||
# post a translation
|
||||
r = self.client.post(reverse('rosetta-home'), dict(m_e48f149a8b2e8baa81b816c0edf93890='Hello, world', _next='_next'))
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
self.assertTrue(six.text_type('Permission denied') in six.text_type(r.content))
|
||||
|
||||
# cleanup
|
||||
os.chmod(self.dest_file, 420) # 0644
|
||||
|
||||
def test_36_issue_142_complex_locales(self):
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=all')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('locale/bs-Cyrl-BA/LC_MESSAGES/django.po') in str(r.content))
|
||||
|
||||
def test_37_issue_133_complex_locales(self):
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=all')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('locale/yy_Anot/LC_MESSAGES/django.po') in str(r.content))
|
||||
|
||||
def test_38_issue_161_more_weird_locales(self):
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=all')
|
||||
r = self.client.get(reverse('rosetta-pick-file'))
|
||||
self.assertTrue(os.path.normpath('locale/zh_Hans/LC_MESSAGES/django.po') in str(r.content))
|
||||
|
||||
def test_39_invalid_get_page(self):
|
||||
r = self.client.get(reverse('rosetta-pick-file') + '?filter=third-party')
|
||||
r = self.client.get(reverse('rosetta-language-selection', args=('xx', 0), kwargs=dict()))
|
||||
r = self.client.get(reverse('rosetta-home') + '?filter=untranslated')
|
||||
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
self.assertEqual(r.context['page'], 1)
|
||||
r = self.client.get(reverse('rosetta-home') + '?page=')
|
||||
self.assertEqual(r.context['page'], 1)
|
||||
r = self.client.get(reverse('rosetta-home') + '?page=%s' % 'x')
|
||||
self.assertEqual(r.context['page'], 1)
|
||||
|
||||
def test_40_issue_155_auto_compile(self):
|
||||
|
||||
def file_hash(file_string):
|
||||
if six.PY3:
|
||||
with open(file_string, encoding="latin-1") as file:
|
||||
file_content = file.read().encode('utf-8')
|
||||
else:
|
||||
with open(file_string) as file:
|
||||
file_content = file.read()
|
||||
return hashlib.md5(file_content).hexdigest()
|
||||
|
||||
def message_hashes():
|
||||
r = self.client.get(reverse('rosetta-home'))
|
||||
return dict([(m.msgid, 'm_' + m.md5hash) for m in r.context['rosetta_messages']])
|
||||
|
||||
po_file = self.dest_file
|
||||
mo_file = self.dest_file[:-3] + '.mo'
|
||||
|
||||
# Load the template file
|
||||
self.client.get(reverse('rosetta-pick-file') + '?filter=third-party')
|
||||
self.client.get(reverse('rosetta-language-selection', args=('xx', 0), kwargs=dict()))
|
||||
|
||||
# MO file will be compiled by default.
|
||||
# Get PO and MO files into an initial reference state (MO will be created or updated)
|
||||
msg_hashes = message_hashes()
|
||||
self.client.post(reverse('rosetta-home'), {
|
||||
msg_hashes['String 1']: "Translation 1", '_next': '_next'})
|
||||
po_file_hash_before, mo_file_hash_before = file_hash(po_file), file_hash(mo_file)
|
||||
|
||||
# Make a change to the translations
|
||||
msg_hashes = message_hashes()
|
||||
self.client.post(reverse('rosetta-home'), {
|
||||
msg_hashes['String 1']: "Translation 2", '_next': '_next'})
|
||||
|
||||
# Get the new hashes of the PO and MO file contents
|
||||
po_file_hash_after, mo_file_hash_after = file_hash(po_file), file_hash(mo_file)
|
||||
|
||||
# Both the PO and MO should have changed
|
||||
self.assertNotEqual(po_file_hash_before, po_file_hash_after)
|
||||
self.assertNotEqual(mo_file_hash_before, mo_file_hash_after)
|
||||
|
||||
# Disable auto-compilation of the MO when the PO is saved
|
||||
rosetta_settings.AUTO_COMPILE = False
|
||||
|
||||
# Make a change to the translations
|
||||
po_file_hash_before, mo_file_hash_before = po_file_hash_after, mo_file_hash_after
|
||||
msg_hashes = message_hashes()
|
||||
self.client.post(reverse('rosetta-home'), {
|
||||
msg_hashes['String 1']: "Translation 3", '_next': '_next'})
|
||||
po_file_hash_after, mo_file_hash_after = file_hash(po_file), file_hash(mo_file)
|
||||
|
||||
# Only the PO should have changed, the MO should be unchanged
|
||||
self.assertNotEqual(po_file_hash_before, po_file_hash_after)
|
||||
self.assertEqual(mo_file_hash_before, mo_file_hash_after)
|
||||
|
||||
# Verify that translating another string also leaves the MO unchanged
|
||||
po_file_hash_before, mo_file_hash_before = po_file_hash_after, mo_file_hash_after
|
||||
msg_hashes = message_hashes()
|
||||
self.client.post(reverse('rosetta-home'), {
|
||||
msg_hashes['String 2']: "Translation 4", '_next': '_next'})
|
||||
po_file_hash_after, mo_file_hash_after = file_hash(po_file), file_hash(mo_file)
|
||||
|
||||
self.assertNotEqual(po_file_hash_before, po_file_hash_after)
|
||||
self.assertEqual(mo_file_hash_before, mo_file_hash_after)
|
||||
|
||||
# Double check that switching back to auto compilation updates the MO
|
||||
rosetta_settings.AUTO_COMPILE = True
|
||||
|
||||
po_file_hash_before, mo_file_hash_before = po_file_hash_after, mo_file_hash_after
|
||||
msg_hashes = message_hashes()
|
||||
self.client.post(reverse('rosetta-home'), {
|
||||
msg_hashes['String 2']: "Translation 5", '_next': '_next'})
|
||||
po_file_hash_after, mo_file_hash_after = file_hash(po_file), file_hash(mo_file)
|
||||
|
||||
self.assertNotEqual(po_file_hash_before, po_file_hash_after)
|
||||
self.assertNotEqual(mo_file_hash_before, mo_file_hash_after)
|
||||
|
||||
|
||||
# Stubbed access control function
|
||||
def no_access(user):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
try:
|
||||
from django.conf.urls import patterns, include, url
|
||||
except ImportError:
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
from .views import dummy
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^rosetta/',include('rosetta.urls')),
|
||||
url(r'^admin/$','rosetta.tests.views.dummy', name='dummy-login')
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^rosetta/', include('rosetta.urls')),
|
||||
url(r'^admin/$', dummy, name='dummy-login')
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
def dummy(request):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
try:
|
||||
from django.conf.urls import patterns, url
|
||||
except ImportError:
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
from django.conf.urls import url
|
||||
from .views import (home, list_languages, download_file, lang_sel, translate_text, ref_sel)
|
||||
|
||||
|
||||
urlpatterns = patterns('rosetta.views',
|
||||
url(r'^$', 'home', name='rosetta-home'),
|
||||
url(r'^pick/$', 'list_languages', name='rosetta-pick-file'),
|
||||
url(r'^download/$', 'download_file', name='rosetta-download-file'),
|
||||
url(r'^select/(?P<langid>[\w\-_\.]+)/(?P<idx>\d+)/$', 'lang_sel', name='rosetta-language-selection'),
|
||||
url(r'^select-ref/(?P<langid>[\w\-_\.]+)/$', 'ref_sel', name='rosetta-reference-selection'),
|
||||
url(r'^translate/$', 'translate_text', name='translate_text'),
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^$', home, name='rosetta-home'),
|
||||
url(r'^pick/$', list_languages, name='rosetta-pick-file'),
|
||||
url(r'^download/$', download_file, name='rosetta-download-file'),
|
||||
url(r'^select/(?P<langid>[\w\-_\.]+)/(?P<idx>\d+)/$', lang_sel, name='rosetta-language-selection'),
|
||||
url(r'^select-ref/(?P<langid>[\w\-_\.]+)/$', ref_sel, name='rosetta-reference-selection'),
|
||||
url(r'^translate/$', translate_text, name='translate_text'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from django.template import RequestContext
|
|||
from django.utils.encoding import iri_to_uri
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.contrib import messages
|
||||
|
||||
from microsofttranslator import Translator, TranslateApiException
|
||||
|
||||
|
|
@ -54,6 +55,13 @@ def home(request):
|
|||
out_ = out_.rstrip()
|
||||
return out_
|
||||
|
||||
def _request_request(key, default=None):
|
||||
if key in request.GET:
|
||||
return request.GET.get(key)
|
||||
elif key in request.POST:
|
||||
return request.POST.get(key)
|
||||
return default
|
||||
|
||||
storage = get_storage(request)
|
||||
query = ''
|
||||
if storage.has('rosetta_i18n_fn'):
|
||||
|
|
@ -68,8 +76,8 @@ def home(request):
|
|||
for entry in rosetta_i18n_pofile:
|
||||
entry.md5hash = hashlib.md5(
|
||||
(six.text_type(entry.msgid) +
|
||||
six.text_type(entry.msgstr) +
|
||||
six.text_type(entry.msgctxt or "")).encode('utf8')
|
||||
six.text_type(entry.msgstr) +
|
||||
six.text_type(entry.msgctxt or "")).encode('utf8')
|
||||
).hexdigest()
|
||||
|
||||
else:
|
||||
|
|
@ -112,7 +120,6 @@ def home(request):
|
|||
if entry:
|
||||
old_msgstr = entry.msgstr
|
||||
if plural_id is not None:
|
||||
#plural_string = fix_nls(entry.msgstr_plural[plural_id], value)
|
||||
plural_string = fix_nls(entry.msgid_plural, value)
|
||||
entry.msgstr_plural[plural_id] = plural_string
|
||||
else:
|
||||
|
|
@ -142,12 +149,11 @@ def home(request):
|
|||
|
||||
if file_change and rosetta_i18n_write:
|
||||
try:
|
||||
# Provide defaults in case authorization is not required.
|
||||
request.user.first_name = getattr(request.user, 'first_name', 'Anonymous')
|
||||
request.user.last_name = getattr(request.user, 'last_name', 'User')
|
||||
request.user.email = getattr(request.user, 'email', 'anonymous@user.tld')
|
||||
|
||||
rosetta_i18n_pofile.metadata['Last-Translator'] = unicodedata.normalize('NFKD', u"%s %s <%s>" % (request.user.first_name, request.user.last_name, request.user.email)).encode('ascii', 'ignore')
|
||||
rosetta_i18n_pofile.metadata['Last-Translator'] = unicodedata.normalize('NFKD', u"%s %s <%s>" % (
|
||||
getattr(request.user, 'first_name', 'Anonymous'),
|
||||
getattr(request.user, 'last_name', 'User'),
|
||||
getattr(request.user, 'email', 'anonymous@user.tld')
|
||||
)).encode('ascii', 'ignore')
|
||||
rosetta_i18n_pofile.metadata['X-Translated-Using'] = u"django-rosetta %s" % rosetta.get_version(False)
|
||||
rosetta_i18n_pofile.metadata['PO-Revision-Date'] = timestamp_with_timezone()
|
||||
except UnicodeDecodeError:
|
||||
|
|
@ -156,8 +162,10 @@ def home(request):
|
|||
try:
|
||||
rosetta_i18n_pofile.save()
|
||||
po_filepath, ext = os.path.splitext(rosetta_i18n_fn)
|
||||
save_as_mo_filepath = po_filepath + '.mo'
|
||||
rosetta_i18n_pofile.save_as_mofile(save_as_mo_filepath)
|
||||
|
||||
if rosetta_settings.AUTO_COMPILE:
|
||||
save_as_mo_filepath = po_filepath + '.mo'
|
||||
rosetta_i18n_pofile.save_as_mofile(save_as_mo_filepath)
|
||||
|
||||
post_save.send(sender=None, language_code=rosetta_i18n_lang_code, request=request)
|
||||
# Try auto-reloading via the WSGI daemon mode reload mechanism
|
||||
|
|
@ -165,7 +173,7 @@ def home(request):
|
|||
'mod_wsgi.process_group' in request.environ and \
|
||||
request.environ.get('mod_wsgi.process_group', None) and \
|
||||
'SCRIPT_FILENAME' in request.environ and \
|
||||
int(request.environ.get('mod_wsgi.script_reloading', '0')):
|
||||
int(request.environ.get('mod_wsgi.script_reloading', '0')):
|
||||
try:
|
||||
os.utime(request.environ.get('SCRIPT_FILENAME'), None)
|
||||
except OSError:
|
||||
|
|
@ -180,38 +188,39 @@ def home(request):
|
|||
# we may not be running under uwsgi :P
|
||||
pass
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
messages.error(request, e)
|
||||
storage.set('rosetta_i18n_write', False)
|
||||
storage.set('rosetta_i18n_pofile', rosetta_i18n_pofile)
|
||||
|
||||
# Retain query arguments
|
||||
query_arg = '?_next=1'
|
||||
if 'query' in request.GET or 'query' in request.POST:
|
||||
query_arg += '&query=%s' % request.REQUEST.get('query')
|
||||
if _request_request('query', False):
|
||||
query_arg += '&query=%s' % _request_request('query')
|
||||
if 'page' in request.GET:
|
||||
query_arg += '&page=%d&_next=1' % int(request.GET.get('page'))
|
||||
return HttpResponseRedirect(reverse('rosetta-home') + iri_to_uri(query_arg))
|
||||
rosetta_i18n_lang_code = storage.get('rosetta_i18n_lang_code')
|
||||
|
||||
if 'query' in request.REQUEST and request.REQUEST.get('query', '').strip():
|
||||
query = request.REQUEST.get('query').strip()
|
||||
if _request_request('query', False) and _request_request('query', '').strip():
|
||||
query = _request_request('query', '').strip()
|
||||
rx = re.compile(re.escape(query), re.IGNORECASE)
|
||||
paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete and rx.search(six.text_type(e.msgstr) + six.text_type(e.msgid) + u''.join([o[0] for o in e.occurrences]))], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
paginator = Paginator([e_ for e_ in rosetta_i18n_pofile if not e_.obsolete and rx.search(six.text_type(e_.msgstr) + six.text_type(e_.msgid) + u''.join([o[0] for o in e_.occurrences]))], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
else:
|
||||
if rosetta_i18n_filter == 'untranslated':
|
||||
paginator = Paginator(rosetta_i18n_pofile.untranslated_entries(), rosetta_settings.MESSAGES_PER_PAGE)
|
||||
elif rosetta_i18n_filter == 'translated':
|
||||
paginator = Paginator(rosetta_i18n_pofile.translated_entries(), rosetta_settings.MESSAGES_PER_PAGE)
|
||||
elif rosetta_i18n_filter == 'fuzzy':
|
||||
paginator = Paginator([e for e in rosetta_i18n_pofile.fuzzy_entries() if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
paginator = Paginator([e_ for e_ in rosetta_i18n_pofile.fuzzy_entries() if not e_.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
else:
|
||||
paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
paginator = Paginator([e_ for e_ in rosetta_i18n_pofile if not e_.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
|
||||
|
||||
if rosetta_settings.ENABLE_REFLANG:
|
||||
ref_lang = storage.get('rosetta_i18n_ref_lang_code', 'msgid')
|
||||
ref_pofile = None
|
||||
if ref_lang != 'msgid':
|
||||
ref_fn = re.sub('/locale/[a-z]{2}/','/locale/%s/' % ref_lang, rosetta_i18n_fn)
|
||||
ref_fn = re.sub('/locale/[a-z]{2}/', '/locale/%s/' % ref_lang, rosetta_i18n_fn)
|
||||
try:
|
||||
ref_pofile = pofile(ref_fn)
|
||||
except IOError:
|
||||
|
|
@ -231,10 +240,15 @@ def home(request):
|
|||
ref_lang = None
|
||||
LANGUAGES = settings.LANGUAGES
|
||||
|
||||
if 'page' in request.GET and int(request.GET.get('page')) <= paginator.num_pages and int(request.GET.get('page')) > 0:
|
||||
page = int(request.GET.get('page'))
|
||||
else:
|
||||
page = 1
|
||||
page = 1
|
||||
if 'page' in request.GET:
|
||||
try:
|
||||
get_page = int(request.GET.get('page'))
|
||||
except ValueError:
|
||||
page = 1 # fall back to page 1
|
||||
else:
|
||||
if 0 < get_page <= paginator.num_pages:
|
||||
page = get_page
|
||||
|
||||
if '_next' in request.GET or '_next' in request.POST:
|
||||
page += 1
|
||||
|
|
@ -371,9 +385,10 @@ def list_languages(request, do_session_warn=False):
|
|||
pos = find_pos(language[0], project_apps=project_apps, django_apps=django_apps, third_party_apps=third_party_apps)
|
||||
has_pos = has_pos or len(pos)
|
||||
languages.append(
|
||||
(language[0],
|
||||
_(language[1]),
|
||||
sorted([(get_app_name(l), os.path.realpath(l), pofile(l)) for l in pos], key=lambda app: app[0]),
|
||||
(
|
||||
language[0],
|
||||
_(language[1]),
|
||||
sorted([(get_app_name(l), os.path.realpath(l), pofile(l)) for l in pos], key=lambda app: app[0]),
|
||||
)
|
||||
)
|
||||
try:
|
||||
|
|
@ -420,10 +435,11 @@ def lang_sel(request, langid, idx):
|
|||
storage.set('rosetta_i18n_fn', file_)
|
||||
po = pofile(file_)
|
||||
for entry in po:
|
||||
entry.md5hash = hashlib.new('md5',
|
||||
entry.md5hash = hashlib.new(
|
||||
'md5',
|
||||
(six.text_type(entry.msgid) +
|
||||
six.text_type(entry.msgstr) +
|
||||
six.text_type(entry.msgctxt or "")).encode('utf8')
|
||||
six.text_type(entry.msgstr) +
|
||||
six.text_type(entry.msgctxt or "")).encode('utf8')
|
||||
).hexdigest()
|
||||
|
||||
storage.set('rosetta_i18n_pofile', po)
|
||||
|
|
@ -435,6 +451,7 @@ def lang_sel(request, langid, idx):
|
|||
|
||||
return HttpResponseRedirect(reverse('rosetta-home'))
|
||||
|
||||
|
||||
def ref_sel(request, langid):
|
||||
storage = get_storage(request)
|
||||
ALLOWED_LANGUAGES = [l[0] for l in settings.LANGUAGES] + ['msgid']
|
||||
|
|
@ -448,6 +465,7 @@ def ref_sel(request, langid):
|
|||
ref_sel = never_cache(ref_sel)
|
||||
ref_sel = user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL)(ref_sel)
|
||||
|
||||
|
||||
@user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL)
|
||||
def translate_text(request):
|
||||
language_from = request.GET.get('from', None)
|
||||
|
|
@ -458,15 +476,20 @@ def translate_text(request):
|
|||
data = {'success': True, 'translation': text}
|
||||
else:
|
||||
# run the translation:
|
||||
AZURE_CLIENT_ID = getattr(settings, 'AZURE_CLIENT_ID', None)
|
||||
AZURE_CLIENT_SECRET = getattr(settings, 'AZURE_CLIENT_SECRET', None)
|
||||
|
||||
translator = Translator(AZURE_CLIENT_ID, AZURE_CLIENT_SECRET)
|
||||
if getattr(rosetta_settings, 'GOOGLE_TRANSLATE', False):
|
||||
import goslate
|
||||
translator = goslate.Goslate()
|
||||
else:
|
||||
AZURE_CLIENT_ID = getattr(settings, 'AZURE_CLIENT_ID', None)
|
||||
AZURE_CLIENT_SECRET = getattr(settings, 'AZURE_CLIENT_SECRET', None)
|
||||
|
||||
translator = Translator(AZURE_CLIENT_ID, AZURE_CLIENT_SECRET)
|
||||
|
||||
try:
|
||||
translated_text = translator.translate(text, language_to)
|
||||
translated_text = translator.translate(text, language_to, language_from)
|
||||
data = {'success': True, 'translation': translated_text}
|
||||
except TranslateApiException as e:
|
||||
data = {'success': False, 'error': "Translation API Exception: {0}".format(e.message)}
|
||||
|
||||
return HttpResponse(json.dumps(data), mimetype='application/json')
|
||||
return HttpResponse(json.dumps(data), content_type='application/json')
|
||||
|
|
|
|||
|
|
@ -1,113 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ ! -d .venv_14 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python2.7 .venv_14
|
||||
. .venv_14/bin/activate
|
||||
pip install --use-mirrors Django==1.4 coverage python-memcached six requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_15 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python2.7 .venv_15
|
||||
. .venv_15/bin/activate
|
||||
pip install --use-mirrors Django==1.5 coverage python-memcached six requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_15_p3 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python3 .venv_15_p3
|
||||
. .venv_15_p3/bin/activate
|
||||
pip install --use-mirrors Django==1.5 coverage python3-memcached six requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_16 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python2.7 .venv_16
|
||||
. .venv_16/bin/activate
|
||||
pip install --use-mirrors coverage python-memcached six Django==1.6.1 requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_16_p3 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python3 .venv_16_p3
|
||||
. .venv_16_p3/bin/activate
|
||||
pip install --use-mirrors coverage python3-memcached six Django==1.6.1 requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_17b ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python2.7 .venv_17b
|
||||
. .venv_17b/bin/activate
|
||||
pip install https://www.djangoproject.com/download/1.7.b4/tarball/
|
||||
pip install --use-mirrors coverage python-memcached six requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
if [ ! -d .venv_17b_p3 ]
|
||||
then
|
||||
virtualenv --no-site-packages --distribute --python=python3 .venv_17b_p3
|
||||
. .venv_17b_p3/bin/activate
|
||||
pip install https://www.djangoproject.com/download/1.7.b4/tarball/
|
||||
pip install --use-mirrors coverage python3-memcached six requests==2.1.0 polib==1.0.4 microsofttranslator==0.5
|
||||
deactivate
|
||||
fi
|
||||
|
||||
|
||||
. .venv_14/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_15/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_15_p3/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_16/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_16_p3/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_17b/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
. .venv_17b_p3/bin/activate
|
||||
cd testproject
|
||||
python manage.py --version
|
||||
python --version
|
||||
python manage.py test rosetta
|
||||
cd ..
|
||||
deactivate
|
||||
|
||||
# Check translations
|
||||
for d in `find rosetta -name LC_MESSAGES -type d`; do msgfmt -c -o $d/django.mo $d/django.po; done
|
||||
40
setup.py
40
setup.py
|
|
@ -1,4 +1,30 @@
|
|||
from setuptools import setup, find_packages
|
||||
from setuptools.command.test import test as test_command
|
||||
import sys
|
||||
|
||||
|
||||
class Tox(test_command):
|
||||
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
|
||||
|
||||
def initialize_options(self):
|
||||
test_command.initialize_options(self)
|
||||
self.tox_args = None
|
||||
|
||||
def finalize_options(self):
|
||||
test_command.finalize_options(self)
|
||||
self.test_args = []
|
||||
self.test_suite = True
|
||||
|
||||
def run_tests(self):
|
||||
# import here, cause outside the eggs aren't loaded
|
||||
import tox
|
||||
import shlex
|
||||
args = self.tox_args
|
||||
if args:
|
||||
args = shlex.split(self.tox_args)
|
||||
errno = tox.cmdline(args=args)
|
||||
sys.exit(errno)
|
||||
|
||||
setup(
|
||||
name='django-rosetta',
|
||||
version=__import__('rosetta').get_version(limit=3),
|
||||
|
|
@ -7,7 +33,7 @@ setup(
|
|||
author_email='mbonetti@gmail.com',
|
||||
url='https://github.com/mbi/django-rosetta',
|
||||
license='MIT',
|
||||
packages=find_packages(),
|
||||
packages=find_packages(exclude=['testproject', 'testproject.*']),
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Environment :: Web Environment',
|
||||
|
|
@ -18,17 +44,19 @@ setup(
|
|||
'Topic :: Software Development :: Localization',
|
||||
'Topic :: Software Development :: Internationalization',
|
||||
'Framework :: Django',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
],
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
install_requires=[
|
||||
'six >=1.2.0',
|
||||
'Django >= 1.3',
|
||||
'Django >= 1.7',
|
||||
'requests >= 2.1.0',
|
||||
'polib == 1.0.4',
|
||||
'microsofttranslator == 0.5'
|
||||
]
|
||||
'polib >= 1.0.6',
|
||||
'microsofttranslator >= 0.7'
|
||||
],
|
||||
tests_require=['tox'],
|
||||
cmdclass={'test': Tox},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
Connection: [close]
|
||||
Host: [!!python/unicode translate.google.com]
|
||||
!!python/unicode User-Agent: [!!python/unicode Mozilla/4.0]
|
||||
method: GET
|
||||
uri: http://translate.google.com/translate_a/single?tl=fr&client=a&q=Hello%2C+world%21&dt=t&sl=en&oe=UTF-8&ie=UTF-8
|
||||
response:
|
||||
body: {string: !!python/unicode '[[["Bonjour le monde!","Hello, world!",,,1]],,"en"]'}
|
||||
headers:
|
||||
accept-ranges: [none]
|
||||
cache-control: ['no-cache, no-store, must-revalidate']
|
||||
connection: [close]
|
||||
content-disposition: [attachment; filename="f.txt"]
|
||||
content-type: [application/json; charset=UTF-8]
|
||||
date: ['Mon, 30 Nov 2015 11:56:42 GMT']
|
||||
expires: ['Fri, 01 Jan 1990 00:00:00 GMT']
|
||||
pragma: [no-cache]
|
||||
server: [HTTP server (unknown)]
|
||||
vary: [Accept-Encoding]
|
||||
x-content-type-options: [nosniff]
|
||||
x-frame-options: [SAMEORIGIN]
|
||||
x-xss-protection: [1; mode=block]
|
||||
status: {code: 200, message: OK}
|
||||
version: 1
|
||||
34
testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po
Normal file
34
testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
||||
|
||||
#: templates/test.html:3
|
||||
msgid "Some text to translate"
|
||||
msgstr ""
|
||||
|
||||
#: templates/test.html:5
|
||||
#, python-format
|
||||
msgid ""
|
||||
"\n"
|
||||
"one bottle of beer on the wall\n"
|
||||
msgid_plural ""
|
||||
"\n"
|
||||
"%(num_bottles)s bottles of beer on the wall\n"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2013-04-30 14:37+0200\n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2013-04-30 14:37+0200\n"
|
||||
"PO-Revision-Date: 2014-08-08 09:24-0500\n"
|
||||
"Last-Translator: <admin@admin.com>\n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: Rosetta\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2013-04-30 14:37+0200\n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: 2012-05-27 14:59\n"
|
||||
"Last-Translator: <admin@admin.com>\n"
|
||||
"Language-Team: French <LL@li.org>\n"
|
||||
|
|
|
|||
34
testproject/locale/yy_Anot/LC_MESSAGES/django.po
Normal file
34
testproject/locale/yy_Anot/LC_MESSAGES/django.po
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
||||
|
||||
#: templates/test.html:3
|
||||
msgid "Some text to translate"
|
||||
msgstr ""
|
||||
|
||||
#: templates/test.html:5
|
||||
#, python-format
|
||||
msgid ""
|
||||
"\n"
|
||||
"one bottle of beer on the wall\n"
|
||||
msgid_plural ""
|
||||
"\n"
|
||||
"%(num_bottles)s bottles of beer on the wall\n"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
34
testproject/locale/zh_Hans/LC_MESSAGES/django.po
Normal file
34
testproject/locale/zh_Hans/LC_MESSAGES/django.po
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2015-09-14 02:28-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
||||
|
||||
#: templates/test.html:3
|
||||
msgid "Some text to translate"
|
||||
msgstr ""
|
||||
|
||||
#: templates/test.html:5
|
||||
#, python-format
|
||||
msgid ""
|
||||
"\n"
|
||||
"one bottle of beer on the wall\n"
|
||||
msgid_plural ""
|
||||
"\n"
|
||||
"%(num_bottles)s bottles of beer on the wall\n"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
|
@ -1,26 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
try:
|
||||
from django.core.management import execute_manager
|
||||
OLD_DJANGO = True
|
||||
except ImportError:
|
||||
from django.core.management import execute_from_command_line
|
||||
OLD_DJANGO = False
|
||||
|
||||
if OLD_DJANGO:
|
||||
try:
|
||||
import settings # Assumed to be in the same directory.
|
||||
except ImportError:
|
||||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
|
||||
sys.exit(1)
|
||||
|
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
sys.path.insert(0, BASEDIR)
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ["DJANGO_SETTINGS_MODULE"] = "testproject.settings"
|
||||
if OLD_DJANGO:
|
||||
execute_manager(settings)
|
||||
else:
|
||||
execute_from_command_line(sys.argv)
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
|
||||
|
||||
import django
|
||||
django.setup()
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
execute_from_command_line(sys.argv)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#from __future__ import unicode_literals
|
||||
# from __future__ import unicode_literals
|
||||
import django
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -28,30 +28,48 @@ CACHES = {
|
|||
}
|
||||
|
||||
|
||||
#CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
|
||||
# CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
|
||||
|
||||
TEST_DATABASE_CHARSET = "utf8"
|
||||
TEST_DATABASE_COLLATION = "utf8_general_ci"
|
||||
|
||||
DATABASE_SUPPORTS_TRANSACTIONS = True
|
||||
SETTINGS_MODULE = 'testproject.settings'
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.auth',
|
||||
'django.contrib.admin',
|
||||
# 'django.contrib.admin.apps.SimpleAdminConfig',
|
||||
# 'django.contrib.redirects.apps.RedirectsConfig',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
|
||||
'rosetta',
|
||||
]
|
||||
|
||||
if django.VERSION[0:2] >= (1, 7):
|
||||
INSTALLED_APPS.append('rosetta.tests.test_app.apps.TestAppConfig')
|
||||
|
||||
LANGUAGE_CODE = "en"
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware'
|
||||
)
|
||||
|
||||
# Note: languages are overridden in the test runner
|
||||
LANGUAGES = (
|
||||
('bs-Cyrl-BA', u'Bosnian (Cyrillic) (Bosnia and Herzegovina)'),
|
||||
('ja', u'日本語'),
|
||||
('xx', u'XXXXX'),
|
||||
('fr', u'French'),
|
||||
('zh_Hans', u'Chinese (Simplified)'),
|
||||
('fr_FR.utf8', u'French (France), UTF8'),
|
||||
)
|
||||
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(PROJECT_PATH, 'locale'),
|
||||
]
|
||||
|
|
@ -65,11 +83,35 @@ STATIC_URL = '/static/'
|
|||
ROOT_URLCONF = 'testproject.urls'
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = True
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'debug': False,
|
||||
'context_processors': (
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.i18n",
|
||||
"django.template.context_processors.media",
|
||||
"django.template.context_processors.static",
|
||||
"django.template.context_processors.tz",
|
||||
"django.contrib.messages.context_processors.messages"
|
||||
)
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
#SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
|
||||
#ROSETTA_STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage'
|
||||
|
||||
# SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
|
||||
# ROSETTA_STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage'
|
||||
|
||||
ROSETTA_STORAGE_CLASS = 'rosetta.storage.CacheRosettaStorage'
|
||||
SECRET_KEY = 'empty'
|
||||
|
||||
ROSETTA_ENABLE_REFLANG = True
|
||||
|
||||
ROSETTA_GOOGLE_TRANSLATE = True
|
||||
ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
|
||||
|
|
|
|||
|
|
@ -1,23 +1,10 @@
|
|||
try:
|
||||
from django.conf.urls import patterns, include, url
|
||||
except ImportError:
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Examples:
|
||||
# url(r'^$', 'testproject.views.home', name='home'),
|
||||
# url(r'^testproject/', include('testproject.foo.urls')),
|
||||
|
||||
# Uncomment the admin/doc line below to enable admin documentation:
|
||||
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^rosetta/', include('rosetta.urls'))
|
||||
)
|
||||
|
|
|
|||
56
tox.ini
Normal file
56
tox.ini
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
[tox]
|
||||
envlist =
|
||||
py27-django17,
|
||||
{py27,py35}-django{18,19},
|
||||
gettext,docs
|
||||
|
||||
skipsdist = True
|
||||
|
||||
|
||||
[testenv]
|
||||
changedir = testproject
|
||||
commands =
|
||||
python manage.py test rosetta
|
||||
|
||||
setenv =
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
deps =
|
||||
|
||||
django17: Django==1.7.11
|
||||
django18: Django==1.8.11
|
||||
django19: Django==1.9.4
|
||||
py27-django{17,18,19}: python-memcached
|
||||
py35-django{17,18,19}: python3-memcached
|
||||
# py27-django18: pudb
|
||||
requests
|
||||
polib>=1.0.6
|
||||
microsofttranslator>=0.7
|
||||
six
|
||||
goslate
|
||||
vcrpy
|
||||
|
||||
[testenv:gettext]
|
||||
changedir = rosetta/locale/
|
||||
whitelist_externals =
|
||||
msgfmt
|
||||
|
||||
commands =
|
||||
msgfmt -c -o cs/LC_MESSAGES/django.mo cs/LC_MESSAGES/django.po
|
||||
msgfmt -c -o de/LC_MESSAGES/django.mo de/LC_MESSAGES/django.po
|
||||
msgfmt -c -o es/LC_MESSAGES/django.mo es/LC_MESSAGES/django.po
|
||||
msgfmt -c -o fa/LC_MESSAGES/django.mo fa/LC_MESSAGES/django.po
|
||||
msgfmt -c -o fr/LC_MESSAGES/django.mo fr/LC_MESSAGES/django.po
|
||||
msgfmt -c -o hu/LC_MESSAGES/django.mo hu/LC_MESSAGES/django.po
|
||||
msgfmt -c -o it/LC_MESSAGES/django.mo it/LC_MESSAGES/django.po
|
||||
msgfmt -c -o nl/LC_MESSAGES/django.mo nl/LC_MESSAGES/django.po
|
||||
msgfmt -c -o pl/LC_MESSAGES/django.mo pl/LC_MESSAGES/django.po
|
||||
msgfmt -c -o ru/LC_MESSAGES/django.mo ru/LC_MESSAGES/django.po
|
||||
msgfmt -c -o tr/LC_MESSAGES/django.mo tr/LC_MESSAGES/django.po
|
||||
msgfmt -c -o uk/LC_MESSAGES/django.mo uk/LC_MESSAGES/django.po
|
||||
|
||||
[testenv:docs]
|
||||
deps = sphinx
|
||||
changedir = docs
|
||||
commands=
|
||||
sphinx-build -W -b html . _build/html
|
||||
Loading…
Reference in a new issue