Django

Code

Ticket #4389 (closed: fixed)

Opened 2 years ago

Last modified 3 months ago

BIDI language detection not smart enough

Reported by: Ahmad Alhashemi Assigned to: jezdez
Milestone: 1.0 Component: Internationalization
Version: SVN Keywords: bidi rtl sprintdec01
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

bidi.diff (0.9 kB) - added by jezdez on 12/01/07 05:23:06.
Added proposed support for _expand_lang
get_language_bidi.diff (0.5 kB) - added by arien on 08/19/08 03:10:10.
Use only first part of language name (i.e., xx for a language xx-yy) for BiDi? detection.

Change History

05/26/07 08:10:24 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

12/01/07 05:20:57 changed by jezdez

  • owner changed from nobody to jezdez.

12/01/07 05:23:06 changed by jezdez

  • attachment bidi.diff added.

Added proposed support for _expand_lang

12/01/07 05:28:34 changed by jezdez

  • has_patch set to 1.

12/01/07 10:53:07 changed by jezdez

  • keywords changed from bidi rtl to bidi rtl sprintdec01.

06/26/08 12:46:47 changed by jezdez

  • status changed from new to assigned.
  • version changed from 0.96 to SVN.
  • milestone set to 1.0.

08/19/08 03:08:32 changed 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.

08/19/08 03:10:10 changed by arien

  • attachment get_language_bidi.diff added.

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

08/19/08 05:28:25 changed by jezdez

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

08/19/08 23:02:43 changed by arien

  • status changed from assigned to closed.
  • resolution set to fixed.

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.)

08/19/08 23:03:03 changed by arien

  • status changed from closed to reopened.
  • resolution deleted.

Didn't mean to close this.

08/26/08 15:08:04 changed by jacob

  • status changed from reopened to closed.
  • resolution set to fixed.

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


Add/Change #4389 (BIDI language detection not smart enough)




Change Properties
Action