Opened 18 years ago

Closed 16 years ago

Last modified 13 years ago

#4389 closed (fixed)

BIDI language detection not smart enough

Reported by: Ahmad Alhashemi Owned by: Jannis Leidel
Component: Internationalization Version: dev
Severity: Keywords: bidi rtl sprintdec01
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

one of my projects, I'm using a LANGUAGE_CODE of 'ar-kw' (Arabic-Kuwait). We already have an Arabic translation (ar) and it is being appropriately used. The problem is that my language code is not being detected as a right to left language. It has to be exactly 'ar' or it will not be detected.

Maybe we can bring some of the smartness of gettext into detecting the direction of text too?

There is a function in gettext called _expand_lang. It takes the locale as a single argument and returns a list of possible names for this locale, so that ar_KW will return a list containing ar_KW, ar and other locales.

Attachments (2)

bidi.diff (902 bytes ) - added by Jannis Leidel 17 years ago.
Added proposed support for _expand_lang
get_language_bidi.diff (523 bytes ) - added by arien 16 years ago.
Use only first part of language name (i.e., xx for a language xx-yy) for BiDi detection.

Download all attachments as: .zip

Change History (13)

comment:1 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Jannis Leidel, 17 years ago

Owner: changed from nobody to Jannis Leidel

by Jannis Leidel, 17 years ago

Attachment: bidi.diff added

Added proposed support for _expand_lang

comment:3 by Jannis Leidel, 17 years ago

Has patch: set

comment:4 by Jannis Leidel, 17 years ago

Keywords: sprintdec01 added

comment:5 by Jannis Leidel, 16 years ago

milestone: 1.0
Status: newassigned
Version: 0.96SVN

comment:6 by arien, 16 years ago

Changing django.utils.translation.get_language_bidi so that it looks to see if xx is in settings.LANGUAGES_BIDI for a language xx-yy (or xx) seems like a nicer way to do this.

by arien, 16 years ago

Attachment: get_language_bidi.diff added

Use only first part of language name (i.e., xx for a language xx-yy) for BiDi detection.

comment:7 by Jannis Leidel, 16 years ago

I don't see why this is nicer to not use a upstream function that does exactly that.

comment:8 by arien, 16 years ago

Resolution: fixed
Status: assignedclosed

gettext._expand_lang expands a locale to a list of locales. That's not doing what is needed here. Besides, you're checking to see if any of those locales is listed in settings.LANGUAGES_BIDI, which contains languages. The reason this works is more or less accident.

All that's needed is to check if xx is in settings.LANGUAGES_BIDI for some language xx-yy. So that's what the patch does.

(You could extract the base_lang function from translation and get_language_bidi to be more DRY, but I'll leave that to a committer.)

comment:9 by arien, 16 years ago

Resolution: fixed
Status: closedreopened

Didn't mean to close this.

comment:10 by Jacob, 16 years ago

Resolution: fixed
Status: reopenedclosed

(In [8596]) Fixed #4389: be more robust in get_language_bidi(). Thanks, arien.

comment:11 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top