Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#4389 closed (fixed)

BIDI language detection not smart enough

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

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 jezdez 7 years ago.
Added proposed support for _expand_lang
get_language_bidi.diff (523 bytes) - added by arien 7 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 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by jezdez

  • Owner changed from nobody to jezdez

Changed 7 years ago by jezdez

Added proposed support for _expand_lang

comment:3 Changed 7 years ago by jezdez

  • Has patch set

comment:4 Changed 7 years ago by jezdez

  • Keywords sprintdec01 added

comment:5 Changed 7 years ago by jezdez

  • milestone set to 1.0
  • Status changed from new to assigned
  • Version changed from 0.96 to SVN

comment:6 Changed 7 years ago by arien

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.

Changed 7 years ago by arien

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

comment:7 Changed 7 years ago by jezdez

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

comment:8 Changed 7 years ago by arien

  • Resolution set to fixed
  • Status changed from assigned to closed

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 Changed 7 years ago by arien

  • Resolution fixed deleted
  • Status changed from closed to reopened

Didn't mean to close this.

comment:10 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:11 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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