mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-03-16 21:30:24 +00:00
allow setting to override case sensitive detection
This commit is contained in:
parent
f9fb95a158
commit
b70d283ee8
3 changed files with 45 additions and 13 deletions
|
|
@ -27,6 +27,7 @@ Rosetta can be configured via the following parameters, to be defined in your pr
|
|||
* ``ROSETTA_LOGIN_URL``: Use this if you want to override the login URL for rosetta. Defaults to ``settings.LOGIN_URL``.
|
||||
* ``ROSETTA_LANGUAGES``: List of languages that Rosetta will offer to translate. This is useful when you wish to translate a language that is not yet defined in ``settings.LANGUAGES``. Defaults to ``settings.LANGUAGES``.
|
||||
* ``ROSETTA_SHOW_OCCURRENCES``: Determines whether occurrences (where the original text appears) should be shown next to the translations for context. Defaults to ``True``.
|
||||
* ``ROSETTA_CASE_SENSITIVE_FILESYSTEM``: Overrides auto-detection of case sensitive OS. Defaults to ``None`` which enables auto-detection. Useful when running case sensitive OS (e.g. Ubuntu) in docker on case insensitive OS (e.g. MacOS).
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
|
||||
import django
|
||||
|
|
@ -70,10 +71,19 @@ def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False)
|
|||
)
|
||||
)
|
||||
|
||||
# is OS case sensitive? settings preferred over auto detection
|
||||
case_sensitive_file_system = getattr(
|
||||
settings, "ROSETTA_CASE_SENSITIVE_FILESYSTEM", False
|
||||
settings, "ROSETTA_CASE_SENSITIVE_FILESYSTEM", None
|
||||
)
|
||||
|
||||
# in case of no settings, attempt auto detection
|
||||
if case_sensitive_file_system is None:
|
||||
case_sensitive_file_system = True
|
||||
tmphandle, tmppath = tempfile.mkstemp()
|
||||
if os.path.exists(tmppath.upper()):
|
||||
# Case insensitive file system.
|
||||
case_sensitive_file_system = False
|
||||
|
||||
# django/locale
|
||||
if django_apps:
|
||||
django_paths = cache.get("rosetta_django_paths")
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@ import filecmp
|
|||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
from unittest import mock
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import vcr
|
||||
|
||||
from django import VERSION
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
|
@ -16,7 +15,9 @@ from django.test.client import Client
|
|||
from django.urls import resolve, reverse
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
import vcr
|
||||
from rosetta import views
|
||||
from rosetta.poutil import find_pos
|
||||
from rosetta.signals import entry_changed, post_save
|
||||
from rosetta.storage import get_storage
|
||||
|
||||
|
|
@ -382,14 +383,16 @@ class RosettaTestCase(TestCase):
|
|||
|
||||
# Post a translation, it should have properly wrapped lines
|
||||
data = {
|
||||
"m_bb9d8fe6159187b9ea494c1b313d23d4": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean "
|
||||
"commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
|
||||
"penatibus et magnis dis parturient montes, nascetur ridiculus "
|
||||
"mus. Donec quam felis, ultricies nec, pellentesque eu, pretium "
|
||||
"quis, sem. Nulla consequat massa quis enim. Donec pede justo, "
|
||||
"fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, "
|
||||
"rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum "
|
||||
"felis eu pede mollis pretium."
|
||||
"m_bb9d8fe6159187b9ea494c1b313d23d4": (
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean "
|
||||
"commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
|
||||
"penatibus et magnis dis parturient montes, nascetur ridiculus "
|
||||
"mus. Donec quam felis, ultricies nec, pellentesque eu, pretium "
|
||||
"quis, sem. Nulla consequat massa quis enim. Donec pede justo, "
|
||||
"fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, "
|
||||
"rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum "
|
||||
"felis eu pede mollis pretium."
|
||||
)
|
||||
}
|
||||
r = self.client.post(self.xx_form_url, data)
|
||||
with open(self.dest_file, "r") as po_file:
|
||||
|
|
@ -762,8 +765,9 @@ class RosettaTestCase(TestCase):
|
|||
msg_hashes = message_hashes()
|
||||
data = {msg_hashes["String 1"]: "Translation 1"}
|
||||
self.client.post(self.xx_form_url, data)
|
||||
po_file_hash_before, mo_file_hash_before = file_hash(po_file), file_hash(
|
||||
mo_file
|
||||
po_file_hash_before, mo_file_hash_before = (
|
||||
file_hash(po_file),
|
||||
file_hash(mo_file),
|
||||
)
|
||||
|
||||
# Make a change to the translations
|
||||
|
|
@ -1053,6 +1057,23 @@ class RosettaTestCase(TestCase):
|
|||
resp = self.client.get(reverse("admin:index"))
|
||||
self.assertNotContains(resp, "rosetta-content-main")
|
||||
|
||||
@mock.patch("rosetta.poutil.os.path.exists")
|
||||
def test_273_override_case_sensitivity(self, path_mock):
|
||||
path_mock.exists.return_value = False
|
||||
# no setting
|
||||
find_pos("en")
|
||||
path_mock.assert_called_with(mock.ANY)
|
||||
|
||||
path_mock.reset_mock()
|
||||
with override_settings(ROSETTA_CASE_SENSITIVE_FILESYSTEM=False):
|
||||
find_pos("en")
|
||||
path_mock.isfile.assert_not_called()
|
||||
|
||||
path_mock.reset_mock()
|
||||
with override_settings(ROSETTA_CASE_SENSITIVE_FILESYSTEM=True):
|
||||
find_pos("en")
|
||||
path_mock.isfile.assert_not_called()
|
||||
|
||||
|
||||
# Stubbed access control function
|
||||
def no_access(user):
|
||||
|
|
|
|||
Loading…
Reference in a new issue