Edgewall Software
Modify

Opened 3 years ago

Closed 2 years ago

#12418 closed defect (fixed)

trac-admin should respect LC_ALL environment variable

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.0.13
Component: i18n Version: 1.0.10
Severity: normal Keywords:
Cc:
Release Notes:

Use locale environment variables to negotiate locale on console.

API Changes:

Description

trac-admin command prints localized text by LANG environment.

$ LANG=fr_FR.UTF8 ~/venv/trac/1.0.10/bin/trac-admin help
trac-admin - La console d'administration de Trac 1.0.10

Utilisation : trac-admin </chemin/vers/env_du_projet> [commande [sous-command] [option ...]]

Le lancement de trac-admin sans commandes déclenche le mode interactif.

help     Show documentation
initenv  Create and initialize a new environment

However, it ignores when LC_ALL is used.

$ LC_ALL=fr_FR.UTF8 ~/venv/trac/1.0.10/bin/trac-admin help
trac-admin - The Trac Administration Console 1.0.10

Usage: trac-admin </path/to/projenv> [command [subcommand] [option ...]]

Invoking trac-admin without command starts interactive mode.

help     Show documentation
initenv  Create and initialize a new environment

It prints by LANG=de_DE.UTF8 even though LC_ALL=fr_FR.UTF8.

$ LC_ALL=fr_FR.UTF8 LANG=de_DE.UTF8 ~/venv/trac/1.0.10/bin/trac-admin help
trac-admin - Die Administrations-Konsole von Trac 1.0.10

Aufruf: trac-admin </pfad/zur/projektumgebung> [Kommando [Subkommando] [Option ...]]

Der Aufruf von trac-admin ohne Kommando startet den interaktiven Modus.

help     Show documentation
initenv  Create and initialize a new environment

Attachments (0)

Change History (7)

comment:1 Changed 3 years ago by Jun Omae

Milestone: 1.0.11
Owner: set to Jun Omae
Status: newassigned

According to GNU gettext utilities: Locale Environment Variables, the priority order is:

  1. LANGUAGE
  2. LC_ALL
  3. LC_xxx, according to selected locale category: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, …
  4. LANG

See also babel:source:/tags/0.9.6/babel/core.py@:633#L610.

  • trac/admin/api.py

    diff --git a/trac/admin/api.py b/trac/admin/api.py
    index bae8ee7d1..b271b7d7c 100644
    a b def get_dir_list(path, dirs_only=False):  
    197197    return result
    198198
    199199
    200 def get_console_locale(env=None, lang=LANG):
    201     """Return negotiated locale for console by LANG environment and
     200def get_console_locale(env=None, categories=('LANGUAGE', 'LC_ALL', 'LC_CTYPE',
     201                                             'LANG')):
     202    """Return negotiated locale for console by locale environments and
    202203    [trac] default_language."""
    203204    if has_babel:
    204205        from babel.core import Locale, UnknownLocaleError, parse_locale
     206        preferred = []
     207        for category in categories:
     208            value = os.environ.get(category)
     209            if not value:
     210                continue
     211            try:
     212                locale = '_'.join(filter(None, parse_locale(value)))
     213            except:
     214                continue
     215            preferred.append(locale)
     216        if env:
     217            preferred.append(env.config.get('trac', 'default_language', ''))
    205218        try:
    206             lang = '_'.join(filter(None, parse_locale(lang)))
    207         except:
    208             lang = None
    209         default = env.config.get('trac', 'default_language', '') \
    210                   if env else None
    211         try:
    212             return get_negotiated_locale([lang, default]) or Locale.default()
     219            return get_negotiated_locale(preferred)
    213220        except UnknownLocaleError:
    214221            pass
    215222    return None

I'll push it with unit tests.

comment:2 Changed 3 years ago by Jun Omae

Proposed changes in jomae.git@t12418.

comment:3 Changed 3 years ago by Ryan J Ollos

Milestone: 1.0.111.0.12

comment:4 Changed 2 years ago by Ryan J Ollos

Milestone: 1.0.121.0.13

comment:5 Changed 2 years ago by Ryan J Ollos

Did you want to commit the change for 1.0.13, or should I move to 1.0.14?

comment:6 Changed 2 years ago by Jun Omae

Yeah, I'll push tonight. Also, I noticed default width of east asian ambiguous should respect locale environments. Updated jomae.git@t12418.

comment:7 Changed 2 years ago by Jun Omae

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [15119-15120] and merged to 1.2-stable and trunk in [15121-15122].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.