Ticket #541 (closed defect: fixed)

Opened 6 months ago

Last modified 4 months ago

error in guess_language in pot.py

Reported by: dahool Owned by:
Priority: major Milestone: 0.8.1
Component: Core Version: devel
Keywords: Cc:
Easy Task: yes Blocked By:
Blocking: Ready for Review: no
Patch Review: Needs Patch: yes

Description (last modified by dahool) (diff)

I assume this function will extract the language code in a file named like 'thisisapofile.en.po', in that case, line 74 in POTManager:

return os.path.basename(filename[:-3:])

Should be:

return os.path.basename(filename[:-3:][-2:])

File: translations/lib/types/pot.py

Version: 0.8.0

Attachments

pot.patch Download (0.7 KB) - added by dahool 6 months ago.

Change History

  Changed 6 months ago by dahool

  • description modified (diff)

follow-up: ↓ 3   Changed 6 months ago by glezos

  • needs_patch set

Maybe it would be even better if we used a regular expression?

in reply to: ↑ 2   Changed 6 months ago by dahool

Replying to glezos:

Maybe it would be even better if we used a regular expression?

Yes. As the proposed solution won't work with languages like pt_br :)

  Changed 6 months ago by glezos

Gabriel, can you maybe attach a patch or point to a bitbucket fork of yours with a commit? I can push it right away.

Changed 6 months ago by dahool

  Changed 6 months ago by dahool

according to my tests, the attached patch should do the trick.

  Changed 6 months ago by glezos

Seeing the quite restrictive (but OK-looking) first part [-_@\w]+, I was wondering whether this restricts the query too much. Wanting to see it being run on a large Tx instance and check whether any file path of any large project will have some files blocked from this, I run something similar on Txn.

REGEX = "[-_@\w]+\.(['po']+)"
filelist = [(p.object.project, p.filename) for p in POFile.objects.all() if not re.match(REGEX, os.path.basename(p.filename)) and not os.path.basename(p.filename).endswith('.pot')]
print filelist

[(<Project: django-l10n-portuguese>, u'pt_BR/ref/index.txt.po'),
 (<Project: translation of man-pages>, u'ru/LC_MESSAGES/getc_unlocked.3.po'),
 (<Project: greenmachine>, u'base/locale/kr/LC_MESSAGES/Copy of django.po')]

The last two are handled by the first part of the if clause, and the first one is quite a rare occasion.

  Changed 6 months ago by dahool

Right. It could be replaced with something like (.+)\.(?P<lang>[-_@\w]+)\.(po?+)

Of course, the first example, 'pt_BR/ref/index.txt.po' is a totally different scenario. I wonder, how it was managed?

  Changed 6 months ago by dahool

[.+]\.(?P<lang>[-_@\w]+)\.['po']+

Sorry about that. wiki formatting issues :P

  Changed 4 months ago by diegobz

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to 0.8.1

Fixed in r1481.

Note: See TracTickets for help on using tickets.