mbi / django-rosetta

Rosetta is a Django application that eases the translation process of your Django projects
MIT License
1.05k stars 194 forks source link

REFLANG not working anymore? #280

Open Skrattoune opened 1 year ago

Skrattoune commented 1 year ago

Which version of Django are you using?: 3.2 Which version of django-rosetta are you using?: 0.9.9 Have you looked trough recent issues and checked this isn't a duplicate? Yes

Hi, I was tempting to enable reflangin my project to facilitate the work of translators, but when testing the feature, the page throws me an error

error at /translations/files/project/de/0/
bad escape \l at position 0

The same occurs whatever the translation language I choose, whatever the django.po file I choose, and whatever the reference language I choose between 'fr' which is almost completely translated, and 'en' which is the original language to be translated

Am I missing something or is the functionality currently broken?

Detail of traceback:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])

During handling of the above exception ('\\l'), another exception occurred:
...
  File "MyProject\venv\lib\site-packages\rosetta\views.py", line 57, in dispatch
    return super(RosettaBaseMixin, self).dispatch(*args, **kwargs)
  File "MyProject\venv\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "MyProject\venv\lib\site-packages\django\views\generic\base.py", line 159, in get
    context = self.get_context_data(**kwargs)
  File "MyProject\venv\lib\site-packages\rosetta\views.py", line 448, in get_context_data
    if self.ref_lang_po_file:
  File "MyProject\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "MyProject\venv\lib\site-packages\rosetta\views.py", line 578, in ref_lang_po_file
    ref_fn = re.sub(pattern, replacement, self.po_file_path)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))

Exception Type: error at /translations/files/project/de/0/
Exception Value: bad escape \l at position 0

with :

<html>
<body>
<!--StartFragment-->

addgroup | <function parse_template.<locals>.addgroup at 0x0DAF6030>
-- | --
c | 'l'
groupindex | {}
groups | []
lappend | <built-in method append of list object at 0x0DAD31E8>
literal | []
literals | []
pattern | re.compile('\\\\locale\\\\[a-z]{2}')
s | <sre_parse.Tokenizer object at 0x0DAE0A50>
sget | <bound method Tokenizer.get of <sre_parse.Tokenizer object at 0x0DAE0A50>>
source | '\\locale\\fr'
this | '\\l'

<!--EndFragment-->
</body>
</html>
Skrattoune commented 1 year ago

OK, because the cause of the error seemed to be linked to a wrong number of slashes, I decided to test in prod ...

And reflangwork very well in prod indeed!

I'm on a windows PC on dev ... so it seems that there is a need to fix this doubled slashes issue. I kind of remember that there was a template filter for that specific purpose, but I haven't been able to find it back